From 5a1d9691f03aaaeb83ab5edb3efea97b09dc165d Mon Sep 17 00:00:00 2001 From: Jan-Matthias Braun Date: Tue, 4 Apr 2023 13:41:59 +0200 Subject: [PATCH] Make the -DTHREAD_SAFE cmake option change the target Issue: Configuring cereal with the -DTHREAD_SAFE=ON option will not lead to any change in the installation. Using target_compile_definitions and target_link_libraries, the cmake targets installed in PREFIX/cmake/cereal will be updated to include the definition and library for thread safety. --- CMakeLists.txt | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 802e2ad9..1eb38f12 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() @@ -63,7 +57,11 @@ target_include_directories(cereal INTERFACE $ $ ) -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)