From c8d9fe355dad6bdf85b3c0d334dc3e7524e1f635 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 9 Nov 2026 22:40:43 +0000 Subject: [PATCH] refactor(cmake): replace fairmq_build_option with CMake commands - Use option() and cmake_dependent_option() directly - Keep the error for BUILD_TESTING or BUILD_EXAMPLES without BUILD_FAIRMQ - Option names and defaults are unchanged Co-Authored-By: Claude Sonnet 5.5 --- CMakeLists.txt | 30 ++++++++++++--------- cmake/FairMQBuildOption.cmake | 50 ----------------------------------- 2 files changed, 17 insertions(+), 63 deletions(-) delete mode 100644 cmake/FairMQBuildOption.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 21a7e446..a721d861 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,20 +20,24 @@ include(FairMQProjectSettings) # Build options ################################################################ -include(FairMQBuildOption) +include(CMakeDependentOption) -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_EXAMPLES "Build FairMQ examples." - DEFAULT ON REQUIRES "BUILD_FAIRMQ") -fairmq_build_option(BUILD_TIDY_TOOL "Build the fairmq-tidy tool." - DEFAULT OFF) -fairmq_build_option(USE_EXTERNAL_GTEST "Do not use bundled GTest. Not recommended." - DEFAULT OFF) -fairmq_build_option(FAIRMQ_DEBUG_MODE "Compile in debug mode (may decrease performance)." - DEFAULT OFF) +# The dependent options below need BUILD_FAIRMQ. Keep the error for an +# explicit request, because cmake_dependent_option() would silently disable it. +if(NOT BUILD_FAIRMQ AND DEFINED BUILD_FAIRMQ) + foreach(opt IN ITEMS BUILD_TESTING BUILD_EXAMPLES) + if(${opt}) + message(FATAL_ERROR "Cannot enable build option ${opt}, depending option is not set: BUILD_FAIRMQ") + endif() + endforeach() +endif() + +option(BUILD_FAIRMQ "Build FairMQ library and devices." ON) +cmake_dependent_option(BUILD_TESTING "Build tests." OFF "BUILD_FAIRMQ" OFF) +cmake_dependent_option(BUILD_EXAMPLES "Build FairMQ examples." ON "BUILD_FAIRMQ" OFF) +option(BUILD_TIDY_TOOL "Build the fairmq-tidy tool." OFF) +option(USE_EXTERNAL_GTEST "Do not use bundled GTest. Not recommended." OFF) +option(FAIRMQ_DEBUG_MODE "Compile in debug mode (may decrease performance)." OFF) ################################################################################ diff --git a/cmake/FairMQBuildOption.cmake b/cmake/FairMQBuildOption.cmake deleted file mode 100644 index bd86ec8b..00000000 --- a/cmake/FairMQBuildOption.cmake +++ /dev/null @@ -1,50 +0,0 @@ -################################################################################ -# Copyright (C) 2018-2021 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH # -# # -# This software is distributed under the terms of the # -# GNU Lesser General Public Licence (LGPL) version 3, # -# copied verbatim in the file "LICENSE" # -################################################################################ - -include_guard(GLOBAL) - -include(CMakeDependentOption) - -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) - set(__requires__ ${ARGS_REQUIRES}) - foreach(d ${__requires__}) - string(REGEX REPLACE " +" ";" __requires_condition__ "${d}") - if(${__requires_condition__}) - else() - if(${option}) - message(FATAL_ERROR "Cannot enable build option ${option}, depending option is not set: ${__requires_condition__}") - endif() - endif() - endforeach() - 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()