Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the -DTHREAD_SAFE cmake option change the target #786

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,8 @@ if(NOT CMAKE_VERSION VERSION_LESS 3.0) # installing cereal requires INTERFACE li
endif()


set(CEREAL_THREAD_LIBS)
if(UNIX)
option(THREAD_SAFE "Use mutexes to ensure thread safety" OFF)
if(THREAD_SAFE)
message(STATUS "Use mutexes")
add_definitions(-DCEREAL_THREAD_SAFE=1)
set(CEREAL_THREAD_LIBS pthread)
endif()
endif()


Expand Down Expand Up @@ -63,7 +57,11 @@ target_include_directories(cereal INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
list(APPEND CEREAL_THREAD_LIBS cereal::cereal)
if(THREAD_SAFE)
message(STATUS "Use mutexes")
target_compile_definitions(cereal INTERFACE CEREAL_THREAD_SAFE=1)
target_link_libraries(cereal INTERFACE pthread)
endif()

if(NOT CMAKE_VERSION VERSION_LESS 3.8)
target_compile_features(cereal INTERFACE cxx_std_11)
Expand Down