From 4499e3e67eed7292804315125768fd38e285704f Mon Sep 17 00:00:00 2001 From: Paul T Date: Fri, 29 Sep 2023 14:29:59 -0400 Subject: [PATCH] fix: build issues with fsanitize=thread in linux --- .github/workflows/ubuntu.yml | 4 ++-- CMakeLists.txt | 9 +++++---- CMakePresets.json | 18 ++++++++++++------ test/CMakeLists.txt | 2 +- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index ba21392..b3aab2e 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -43,10 +43,10 @@ jobs: platform: x64 - name: configure gcc - run: cmake -S . -B build -DTP_BUILD_EXAMPLES=OFF -DTP_BUILD_BENCHMARKS=OFF -DCMAKE_BUILD_TYPE=Debug + run: cmake -S . -B build -DTP_BUILD_EXAMPLES=OFF -DTP_BUILD_BENCHMARKS=OFF -DTP_THREAD_SANITIZER=OFF -DCMAKE_BUILD_TYPE=Debug - name: configure clang - run: cmake -S . -B build-clang -DTP_BUILD_EXAMPLES=OFF -DTP_BUILD_BENCHMARKS=OFF -DCMAKE_BUILD_TYPE=Debug + run: cmake -S . -B build-clang -DTP_BUILD_EXAMPLES=OFF -DTP_BUILD_BENCHMARKS=OFF -DTP_THREAD_SANITIZER=OFF -DCMAKE_BUILD_TYPE=Debug env: CC: clang CXX: clang++ diff --git a/CMakeLists.txt b/CMakeLists.txt index 489fcb1..63a5cf9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -137,19 +137,20 @@ install(FILES ${PROJECT_BINARY_DIR}/include/thread_pool/version.h option(TP_BUILD_TESTS "Turn on to build unit tests." ON) option(TP_BUILD_EXAMPLES "Turn on to build examples." ON) option(TP_BUILD_BENCHMARKS "Turn on to build benchmarks." ON) +option(TP_THREAD_SANITIZER "Turn on to build with thread sanitizer." OFF) -if(${TP_BUILD_TESTS} OR ${TP_BUILD_EXAMPLES} OR ${TP_BUILD_BENCHMARKS}) +if(TP_BUILD_TESTS OR TP_BUILD_EXAMPLES OR TP_BUILD_BENCHMARKS) # see https://github.com/TheLartians/CPM.cmake for more info include(cmake/CPM.cmake) endif() -if(${TP_BUILD_TESTS}) +if(TP_BUILD_TESTS) enable_testing() add_subdirectory(test) endif() -if(${TP_BUILD_EXAMPLES}) +if(TP_BUILD_EXAMPLES) add_subdirectory(examples) endif() -if(${TP_BUILD_BENCHMARKS}) +if(TP_BUILD_BENCHMARKS) add_subdirectory(benchmark) endif() diff --git a/CMakePresets.json b/CMakePresets.json index 95ca434..c2c297e 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -26,7 +26,6 @@ "binaryDir": "${sourceDir}/out/build/${presetName}", "installDir": "${sourceDir}/out/install/${presetName}", "cacheVariables": { - "CMAKE_C_COMPILER": "cl", "CMAKE_CXX_COMPILER": "cl" }, "condition": { @@ -40,7 +39,6 @@ "hidden": true, "inherits": "linux-base", "cacheVariables": { - "CMAKE_C_COMPILER": "gcc", "CMAKE_CXX_COMPILER": "g++" } }, @@ -48,7 +46,10 @@ "name": "gcc-debug", "inherits": "gcc-base", "displayName": "GCC Debug", - "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug" } + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug", + "TP_THREAD_SANITIZER": "ON" + } }, { "name": "gcc-release", @@ -61,7 +62,6 @@ "hidden": true, "inherits": "linux-base", "cacheVariables": { - "CMAKE_C_COMPILER": "clang", "CMAKE_CXX_COMPILER": "clang++" } }, @@ -69,7 +69,10 @@ "name": "clang-debug", "inherits": "clang-base", "displayName": "Clang Debug", - "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug" } + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug", + "TP_THREAD_SANITIZER": "ON" + } }, { "name": "clang-release", @@ -81,7 +84,10 @@ "name": "clang-release-with-debug-info", "inherits": "clang-base", "displayName": "Clang RelWithDebInfo", - "cacheVariables": { "CMAKE_BUILD_TYPE": "RelWithDebInfo" } + "cacheVariables": { + "CMAKE_BUILD_TYPE": "RelWithDebInfo", + "TP_THREAD_SANITIZER": "ON" + } }, { "name": "x64-debug", diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 9f29ba8..9a7c6b0 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -45,7 +45,7 @@ target_link_options( ${PROJECT_NAME} PRIVATE $<$:--coverage> ) -if(NOT WIN32) +if(NOT WIN32 AND TP_THREAD_SANITIZER) target_compile_options( ${PROJECT_NAME} PRIVATE $<$:-fsanitize=thread -g> )