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)