From dbc8f147c92bf60f06bbed4eabcd93fd206d33dc Mon Sep 17 00:00:00 2001 From: Mike Ellery Date: Wed, 1 Aug 2018 16:46:35 -0700 Subject: [PATCH] Improve subproj handling and deprecated target options: Exclude several libraries from build when we are included in a super-project (this is the case when someone only wants to use xrpl_core). Force several target (deprecated) params to be cache variables since they are now exposed as options. --- Builds/CMake/CMakeFuncs.cmake | 15 +++++++++++---- CMakeLists.txt | 18 ++++++++++++++---- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/Builds/CMake/CMakeFuncs.cmake b/Builds/CMake/CMakeFuncs.cmake index a605dc475e8..a02ac555351 100644 --- a/Builds/CMake/CMakeFuncs.cmake +++ b/Builds/CMake/CMakeFuncs.cmake @@ -50,11 +50,11 @@ macro(parse_target) endif() if (${cur_component} STREQUAL unity) - set(unity true) + set(unity ON CACHE BOOL "" FORCE) endif() if (${cur_component} STREQUAL nounity) - set(unity false) + set(unity OFF CACHE BOOL "" FORCE) endif() if (${cur_component} STREQUAL debug) @@ -66,12 +66,12 @@ macro(parse_target) endif() if (${cur_component} STREQUAL coverage) - set(coverage true) + set(coverage ON CACHE BOOL "" FORCE) set(debug true) endif() if (${cur_component} STREQUAL profile) - set(profile true) + set(profile ON CACHE BOOL "" FORCE) endif() endwhile() endif() @@ -108,3 +108,10 @@ macro(group_sources curdir) group_sources_in(${PROJECT_SOURCE_DIR} ${curdir}) endmacro() +macro (exclude_if_included target_) + if (NOT ${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_SOURCE_DIR}) + set_target_properties (${target_} PROPERTIES EXCLUDE_FROM_ALL ON) + set_target_properties (${target_} PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD ON) + endif () +endmacro () + diff --git a/CMakeLists.txt b/CMakeLists.txt index 27f1e616cd3..323c88b2534 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,12 @@ if (is_multiconfig STREQUAL "NOTFOUND") endif () endif () +if (${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_SOURCE_DIR}) + set (is_root_project ON) +else () + set (is_root_project OFF) +endif () + if ("${CMAKE_CXX_COMPILER_ID}" MATCHES ".*Clang") # both Clang and AppleClang set (is_clang TRUE) elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") @@ -655,6 +661,7 @@ add_custom_command (TARGET lz4 POST_BUILD ${CMAKE_BINARY_DIR}/lz4/include COMMAND ${CMAKE_COMMAND} -E copy $ ${CMAKE_BINARY_DIR}/lz4/lib) +exclude_if_included (lz4) #[===================================================================[ NIH dep: libarchive (via external project) @@ -805,6 +812,7 @@ add_custom_command (TARGET sqlite3 POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $ ${CMAKE_BINARY_DIR}/sqlite3/lib BYPRODUCTS ${CMAKE_BINARY_DIR}/sqlite3/include/sqlite3.h) +exclude_if_included (sqlite3) #[===================================================================[ NIH dep: soci @@ -840,6 +848,7 @@ target_link_libraries (soci Ripple::boost) add_library (NIH::soci ALIAS soci) target_link_libraries (ripple_libs INTERFACE NIH::soci) +exclude_if_included (soci) #[===================================================================[ NIH dep: snappy @@ -862,6 +871,7 @@ target_include_directories (snappy src/snappy/config) add_library (NIH::snappy ALIAS snappy) target_link_libraries (ripple_libs INTERFACE NIH::snappy) +exclude_if_included (snappy) #[===================================================================[ NIH dep: rocksdb @@ -908,6 +918,7 @@ else () endif () add_library (NIH::rocksdb ALIAS rocksdb) target_link_libraries (ripple_libs INTERFACE NIH::rocksdb) +exclude_if_included (rocksdb) #[===================================================================[ NIH dep: nudb @@ -1012,6 +1023,7 @@ target_compile_options (pbufs >) add_library (Ripple::pbufs ALIAS pbufs) target_link_libraries (ripple_libs INTERFACE Ripple::pbufs) +exclude_if_included (pbufs) #[===================================================================[ xrpl_core @@ -2012,6 +2024,7 @@ target_link_libraries (rippled Ripple::libs Ripple::boost Ripple::xrpl_core) +exclude_if_included (rippled) #[===================================================================[ install stuff @@ -2041,7 +2054,7 @@ write_basic_package_version_file ( VERSION ${rippled_version} COMPATIBILITY SameMajorVersion) -if (${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_SOURCE_DIR}) +if (is_root_project) install (TARGETS rippled RUNTIME DESTINATION bin) set_target_properties(rippled PROPERTIES INSTALL_RPATH_USE_LINK_PATH ON) install ( @@ -2063,9 +2076,6 @@ if (${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_SOURCE_DIR}) copy_if_not_exists(\"${CMAKE_CURRENT_SOURCE_DIR}/cfg/rippled-example.cfg\" etc rippled.cfg) copy_if_not_exists(\"${CMAKE_CURRENT_SOURCE_DIR}/cfg/validators-example.txt\" etc validators.txt) ") -else () - set_target_properties (rippled PROPERTIES EXCLUDE_FROM_ALL ON) - set_target_properties (rippled PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD ON) endif () #[===================================================================[