From 934263c0b24d1b563b775ca789e1f455412e4c08 Mon Sep 17 00:00:00 2001 From: Luca Ciucci Date: Mon, 2 Jan 2023 11:55:36 +0100 Subject: [PATCH 1/3] some options renamed --- CMakeLists.txt | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 802e2ad9..58512d48 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,22 +11,22 @@ if(APPLE) option(SKIP_PORTABILITY_TEST "Skip portability (32 bit) tests" ON) endif() -option(BUILD_DOC "Build documentation" ON) -option(BUILD_SANDBOX "Build sandbox examples" ON) -option(SKIP_PERFORMANCE_COMPARISON "Skip building performance sandbox comparison (requires boost)" OFF) +option(CEREAL_BUILD_DOC "Build documentation" ON) +option(CEREAL_BUILD_SANDBOX "Build sandbox examples" ON) +option(CEREAL_SKIP_PERFORMANCE_COMPARISON "Skip building performance sandbox comparison (requires boost)" OFF) # TODO: should not be needed! CK if(NOT CMAKE_VERSION VERSION_LESS 3.0) # installing cereal requires INTERFACE lib - option(JUST_INSTALL_CEREAL "Don't do anything besides installing the library" OFF) + option(CEREAL_JUST_INSTALL_CEREAL "Don't do anything besides installing the library" OFF) endif() set(CEREAL_THREAD_LIBS) if(UNIX) - option(THREAD_SAFE "Use mutexes to ensure thread safety" OFF) - if(THREAD_SAFE) + option(CEREAL_THREAD_SAFE "Use mutexes to ensure thread safety" OFF) + if(CEREAL_THREAD_SAFE) message(STATUS "Use mutexes") - add_definitions(-DCEREAL_THREAD_SAFE=1) + add_definitions(-DCEREAL_CEREAL_THREAD_SAFE=1) set(CEREAL_THREAD_LIBS pthread) endif() endif() @@ -36,13 +36,13 @@ if(MSVC) add_compile_options(/bigobj /W3 /WX) else() add_compile_options(-Wall -Wextra -pedantic -Wshadow -Wold-style-cast) - option(WITH_WERROR "Compile with '-Werror' C++ compiler flag" ON) - if(WITH_WERROR) + option(CEREAL_WITH_WERROR "Compile with '-Werror' C++ compiler flag" ON) + if(CEREAL_WITH_WERROR) add_compile_options(-Werror) endif() - option(CLANG_USE_LIBCPP "Use libc++ for clang compilation" OFF) - if(APPLE OR CLANG_USE_LIBCPP) + option(CEREAL_CLANG_USE_LIBCPP "Use libc++ for clang compilation" OFF) + if(APPLE OR CEREAL_CLANG_USE_LIBCPP) message(STATUS "Use libc++") add_compile_options(-stdlib=libc++) # TODO: use add_link_options(-stdlib=libc++ -lc++abi") bud this needs cmake 3.13! CK @@ -101,29 +101,29 @@ if(CEREAL_INSTALL) endif() -if(JUST_INSTALL_CEREAL) +if(CEREAL_JUST_INSTALL_CEREAL) return() endif() -if(NOT SKIP_PERFORMANCE_COMPARISON) +if(NOT CEREAL_SKIP_PERFORMANCE_COMPARISON) # Boost serialization for performance sandbox find_package(Boost REQUIRED COMPONENTS serialization) endif() -option(BUILD_TESTS "Build tests" ${CEREAL_MASTER_PROJECT}) -if(BUILD_TESTS) +option(CEREAL_BUILD_TESTS "Build tests" ${CEREAL_MASTER_PROJECT}) +if(CEREAL_BUILD_TESTS) enable_testing() add_subdirectory(unittests) endif() -if(BUILD_SANDBOX) +if(CEREAL_BUILD_SANDBOX) add_subdirectory(sandbox) endif() -if(BUILD_DOC) +if(CEREAL_BUILD_DOC) add_subdirectory(doc) endif() From 3ee4bae1f1093b8082dfdb4266d347514860add6 Mon Sep 17 00:00:00 2001 From: Luca Ciucci Date: Mon, 2 Jan 2023 12:01:55 +0100 Subject: [PATCH 2/3] changed default options values when not main project --- CMakeLists.txt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 58512d48..65f4279c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,8 +2,11 @@ cmake_minimum_required(VERSION 3.6...3.15) project(cereal LANGUAGES CXX VERSION 1.3.2) +set(CEREAL_MASTER_PROJECT OFF) +set(CEREAL_NOT_MASTER_PROJECT ON) if(PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) set(CEREAL_MASTER_PROJECT ON) + set(CEREAL_NOT_MASTER_PROJECT OFF) endif() @@ -11,9 +14,9 @@ if(APPLE) option(SKIP_PORTABILITY_TEST "Skip portability (32 bit) tests" ON) endif() -option(CEREAL_BUILD_DOC "Build documentation" ON) -option(CEREAL_BUILD_SANDBOX "Build sandbox examples" ON) -option(CEREAL_SKIP_PERFORMANCE_COMPARISON "Skip building performance sandbox comparison (requires boost)" OFF) +option(CEREAL_BUILD_DOC "Build documentation" ${CEREAL_MASTER_PROJECT}) +option(CEREAL_BUILD_SANDBOX "Build sandbox examples" ${CEREAL_MASTER_PROJECT}) +option(CEREAL_SKIP_PERFORMANCE_COMPARISON "Skip building performance sandbox comparison (requires boost)" ${CEREAL_NOT_MASTER_PROJECT}) # TODO: should not be needed! CK if(NOT CMAKE_VERSION VERSION_LESS 3.0) # installing cereal requires INTERFACE lib From 2c981020adc3e24993bdb88ecaecdacbd5dd679e Mon Sep 17 00:00:00 2001 From: Luca Ciucci Date: Mon, 2 Jan 2023 12:04:49 +0100 Subject: [PATCH 3/3] more complete main project check --- CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 65f4279c..740afc34 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,11 @@ project(cereal LANGUAGES CXX VERSION 1.3.2) set(CEREAL_MASTER_PROJECT OFF) set(CEREAL_NOT_MASTER_PROJECT ON) -if(PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) +if( + (PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) AND + (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) AND + (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) +) set(CEREAL_MASTER_PROJECT ON) set(CEREAL_NOT_MASTER_PROJECT OFF) endif()