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

Disable unnecessary stuff if not main project #775

Open
wants to merge 3 commits 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
43 changes: 25 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,38 @@ cmake_minimum_required(VERSION 3.6...3.15)

project(cereal LANGUAGES CXX VERSION 1.3.2)

if(PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(CEREAL_MASTER_PROJECT OFF)
set(CEREAL_NOT_MASTER_PROJECT ON)
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()


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" ${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
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()
Expand All @@ -36,13 +43,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
Expand Down Expand Up @@ -101,29 +108,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()