Skip to content

Commit

Permalink
Enable address sanitizer in test_package.
Browse files Browse the repository at this point in the history
  • Loading branch information
PengZheng committed Jun 24, 2024
1 parent 50e1193 commit d3b1e15
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
13 changes: 13 additions & 0 deletions examples/conan_test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ set(CMAKE_CXX_STANDARD 17)

find_package(Celix REQUIRED)

option(ENABLE_ADDRESS_SANITIZER "Enabled building with address sanitizer. Note for gcc libasan must be installed," OFF)
if (ENABLE_ADDRESS_SANITIZER)
if("${CMAKE_C_COMPILER_ID}" MATCHES "Clang")
set(CMAKE_C_FLAGS "-fsanitize=address -fno-omit-frame-pointer ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "-fsanitize=address -fno-omit-frame-pointer ${CMAKE_CXX_FLAGS}")
elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_C_FLAGS "-lasan -fsanitize=address -fno-omit-frame-pointer ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "-lasan -fsanitize=address -fno-omit-frame-pointer ${CMAKE_CXX_FLAGS}")
else ()
message(WARNING "Address sanitizer is not supported for ${CMAKE_C_COMPILER_ID}")
endif ()
endif()

option(TEST_FRAMEWORK "Test Celix framework" OFF)
if (TEST_FRAMEWORK)
add_celix_bundle(hello VERSION 1.0.0 SOURCES hello_bundle.c)
Expand Down
1 change: 1 addition & 0 deletions examples/conan_test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class TestPackageConan(ConanFile):

def build(self):
cmake = CMake(self)
cmake.definitions["ENABLE_ADDRESS_SANITIZER"] = self.options["celix"].enable_address_sanitizer
cmake.definitions["TEST_FRAMEWORK"] = self.options["celix"].build_framework
cmake.definitions["TEST_HTTP_ADMIN"] = self.options["celix"].build_http_admin
cmake.definitions["TEST_LOG_SERVICE"] = self.options["celix"].build_log_service
Expand Down
1 change: 1 addition & 0 deletions examples/conan_test_package_v2/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def requirements(self):
def generate(self):
tc = CMakeToolchain(self)
celix_options = self.dependencies["celix"].options
tc.cache_variables["ENABLE_ADDRESS_SANITIZER"] = celix_options.enable_address_sanitizer
tc.cache_variables["TEST_FRAMEWORK"] = celix_options.build_framework
tc.cache_variables["TEST_HTTP_ADMIN"] = celix_options.build_http_admin
tc.cache_variables["TEST_LOG_SERVICE"] = celix_options.build_log_service
Expand Down

0 comments on commit d3b1e15

Please sign in to comment.