diff --git a/CMakeLists.txt b/CMakeLists.txt index 329c5584..1b352ded 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,17 +31,26 @@ include(CTest) # Build options ################################################################ -include(CMakeDependentOption) -option(BUILD_FAIRMQ "Build FairMQ library and devices." ON) -cmake_dependent_option(BUILD_TESTING "Build tests." OFF "BUILD_FAIRMQ" OFF) -cmake_dependent_option(BUILD_NANOMSG_TRANSPORT "Build nanomsg transport." OFF "BUILD_FAIRMQ" OFF) -cmake_dependent_option(BUILD_OFI_TRANSPORT "Build experimental OFI transport." OFF "BUILD_FAIRMQ" OFF) -cmake_dependent_option(BUILD_DDS_PLUGIN "Build DDS plugin." OFF "BUILD_FAIRMQ" OFF) -cmake_dependent_option(BUILD_PMIX_PLUGIN "Build PMIx plugin." OFF "BUILD_FAIRMQ" OFF) -cmake_dependent_option(BUILD_EXAMPLES "Build FairMQ examples." ON "BUILD_FAIRMQ" OFF) -option(BUILD_SDK "Build the FairMQ controller SDK." OFF) -option(BUILD_DOCS "Build FairMQ documentation." OFF) -option(FAST_BUILD "Fast production build. Not recommended for development." OFF) +fairmq_build_option(BUILD_FAIRMQ "Build FairMQ library and devices." + DEFAULT ON) +fairmq_build_option(BUILD_TESTING "Build tests." + DEFAULT OFF REQUIRES "BUILD_FAIRMQ") +fairmq_build_option(BUILD_NANOMSG_TRANSPORT "Build nanomsg transport." + DEFAULT OFF REQUIRES "BUILD_FAIRMQ") +fairmq_build_option(BUILD_OFI_TRANSPORT "Build experimental OFI transport." + DEFAULT OFF REQUIRES "BUILD_FAIRMQ") +fairmq_build_option(BUILD_DDS_PLUGIN "Build DDS plugin." + DEFAULT OFF REQUIRES "BUILD_FAIRMQ") +fairmq_build_option(BUILD_PMIX_PLUGIN "Build PMIx plugin." + DEFAULT OFF REQUIRES "BUILD_FAIRMQ") +fairmq_build_option(BUILD_EXAMPLES "Build FairMQ examples." + DEFAULT ON REQUIRES "BUILD_FAIRMQ") +fairmq_build_option(BUILD_SDK "Build the FairMQ controller SDK." + DEFAULT OFF) +fairmq_build_option(BUILD_DOCS "Build FairMQ documentation." + DEFAULT OFF) +fairmq_build_option(FAST_BUILD "Fast production build. Not recommended for development." + DEFAULT OFF) ################################################################################ diff --git a/cmake/FairMQLib.cmake b/cmake/FairMQLib.cmake index 9f0fc789..8aa9791d 100644 --- a/cmake/FairMQLib.cmake +++ b/cmake/FairMQLib.cmake @@ -480,3 +480,41 @@ function(build_bundled package bundle) message(STATUS "Building bundled ${package} - done") endfunction() + +macro(fairmq_build_option option description) + cmake_parse_arguments(ARGS "" "DEFAULT;REQUIRES" "" ${ARGN}) + + if(ARGS_DEFAULT) + set(__default__ ON) + else() + set(__default__ OFF) + endif() + + if(ARGS_REQUIRES) + include(CMakeDependentOption) + set(__requires__ ${ARGS_REQUIRES}) + string(REGEX REPLACE " +" ";" __requires_condition__ "${__requires__}") + if(${__requires_condition__}) + else() + if(${option}) + message(WARNING "Cannot enable build option ${option}, depending options are not set: ${__requires_condition__}.") + endif() + endif() + else() + set(__requires__) + endif() + + if(__requires__) + cmake_dependent_option(${option} ${description} ${__default__} ${__requires__} OFF) + else() + option(${option} ${description} ${__default__}) + endif() + + set(__default__) + set(__requires__) + set(__requires_condition__) + set(ARGS_DEFAULT) + set(ARGS_REQUIRES) + set(option) + set(description) +endmacro()