Skip to content

Commit

Permalink
fix: build issues with fsanitize=thread in linux
Browse files Browse the repository at this point in the history
  • Loading branch information
DeveloperPaul123 committed Sep 29, 2023
1 parent b04b165 commit 4499e3e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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++
Expand Down
9 changes: 5 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
18 changes: 12 additions & 6 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"binaryDir": "${sourceDir}/out/build/${presetName}",
"installDir": "${sourceDir}/out/install/${presetName}",
"cacheVariables": {
"CMAKE_C_COMPILER": "cl",
"CMAKE_CXX_COMPILER": "cl"
},
"condition": {
Expand All @@ -40,15 +39,17 @@
"hidden": true,
"inherits": "linux-base",
"cacheVariables": {
"CMAKE_C_COMPILER": "gcc",
"CMAKE_CXX_COMPILER": "g++"
}
},
{
"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",
Expand All @@ -61,15 +62,17 @@
"hidden": true,
"inherits": "linux-base",
"cacheVariables": {
"CMAKE_C_COMPILER": "clang",
"CMAKE_CXX_COMPILER": "clang++"
}
},
{
"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",
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ target_link_options(
${PROJECT_NAME} PRIVATE $<$<COMPILE_LANG_AND_ID:CXX,GNU>:--coverage>
)

if(NOT WIN32)
if(NOT WIN32 AND TP_THREAD_SANITIZER)
target_compile_options(
${PROJECT_NAME} PRIVATE $<$<COMPILE_LANG_AND_ID:CXX,GNU,Clang>:-fsanitize=thread -g>
)
Expand Down

0 comments on commit 4499e3e

Please sign in to comment.