diff --git a/examples/conan_test_package/CMakeLists.txt b/examples/conan_test_package/CMakeLists.txt index 48f109e6c..699536419 100644 --- a/examples/conan_test_package/CMakeLists.txt +++ b/examples/conan_test_package/CMakeLists.txt @@ -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) diff --git a/examples/conan_test_package/conanfile.py b/examples/conan_test_package/conanfile.py index 734def051..e79dbb4e9 100644 --- a/examples/conan_test_package/conanfile.py +++ b/examples/conan_test_package/conanfile.py @@ -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 diff --git a/examples/conan_test_package_v2/conanfile.py b/examples/conan_test_package_v2/conanfile.py index 8bba84bba..c5a3382ea 100644 --- a/examples/conan_test_package_v2/conanfile.py +++ b/examples/conan_test_package_v2/conanfile.py @@ -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