From cfbc46a1320dbdda8dd3cd6c0338407e36959676 Mon Sep 17 00:00:00 2001 From: Zachary Ferguson Date: Mon, 12 Oct 2026 14:02:46 -0400 Subject: [PATCH] Fix CMake options being forced in the cache - Default IPC_TOOLKIT_BUILD_TESTS to ON only at the top level instead of forcing it and IPC_TOOLKIT_BUILD_PYTHON OFF in a parent's cache - Shadow IPC_TOOLKIT_WITH_SIMD with a normal variable when SIMD is not found - Set BUILD_SHARED_LIBS as a function-local variable when building oneTBB - Fall back to a CPU build when CUDA is requested but no compiler is found Co-Authored-By: Claude Sonnet 5.5 --- CMakeLists.txt | 30 +++++++++++++++++++----------- cmake/recipes/onetbb.cmake | 35 +++++------------------------------ 2 files changed, 24 insertions(+), 41 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 66b98594c..206196e34 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,15 +82,10 @@ if(IPC_TOOLKIT_TOPLEVEL_PROJECT) endif() endif() -if(IPC_TOOLKIT_TOPLEVEL_PROJECT) - option(IPC_TOOLKIT_BUILD_TESTS "Build unit-tests" ON) - option(IPC_TOOLKIT_BUILD_PYTHON "Build Python bindings" OFF) -else() - # If this is not the top-level project, we don't want to build tests or Python - # bindings. This is useful for projects that use IPC Toolkit as a submodule. - set(IPC_TOOLKIT_BUILD_TESTS OFF CACHE BOOL "Build unit-tests" FORCE) - set(IPC_TOOLKIT_BUILD_PYTHON OFF CACHE BOOL "Build Python bindings" FORCE) -endif() +# If this is not the top-level project, we don't build tests or Python bindings +# by default. This is useful for projects that use IPC Toolkit as a submodule. +option(IPC_TOOLKIT_BUILD_TESTS "Build unit-tests" ${IPC_TOOLKIT_TOPLEVEL_PROJECT}) +option(IPC_TOOLKIT_BUILD_PYTHON "Build Python bindings" OFF) option(IPC_TOOLKIT_WITH_CUDA "Enable CUDA CCD" OFF) option(IPC_TOOLKIT_WITH_SIMD "Enable SIMD" ON) @@ -138,7 +133,17 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON) # Verify Options ################################################################################ -# CUDA support +# Check for CUDA support +if (IPC_TOOLKIT_WITH_CUDA) + include(CheckLanguage) + check_language(CUDA) + if (NOT CMAKE_CUDA_COMPILER) + message(WARNING "CUDA support requested but no CUDA compiler found. Continuing without CUDA.") + set(IPC_TOOLKIT_WITH_CUDA OFF) + endif() +endif() + +# Enable CUDA support if requested if(IPC_TOOLKIT_WITH_CUDA) # If CMAKE_CUDA_ARCHITECTURES was not specified, set it to native. if(DEFINED CMAKE_CUDA_ARCHITECTURES) @@ -172,7 +177,10 @@ if(IPC_TOOLKIT_WITH_SIMD) message(STATUS "SIMD support found: ${SIMD_CXX_FLAGS}") else() message(WARNING "SIMD support requested but not found. Continuing without SIMD.") - set(IPC_TOOLKIT_WITH_SIMD OFF CACHE BOOL "Enable SIMD" FORCE) + # We shadow the cache entry with a normal variable instead of forcing the + # cache off. Forcing would overwrite the user's request, and the option + # would stay OFF in this build directory even after SIMD becomes available. + set(IPC_TOOLKIT_WITH_SIMD OFF) endif() endif() diff --git a/cmake/recipes/onetbb.cmake b/cmake/recipes/onetbb.cmake index b7ad50789..c14739587 100644 --- a/cmake/recipes/onetbb.cmake +++ b/cmake/recipes/onetbb.cmake @@ -19,43 +19,18 @@ option(TBB_PREFER_STATIC "Use the static version of TBB for the alias target" ON unset(TBB_DIR CACHE) function(onetbb_import_target) - macro(push_variable var value) - if(DEFINED CACHE{${var}}) - set(ONETBB_OLD_${var}_VALUE "${${var}}") - set(ONETBB_OLD_${var}_TYPE CACHE_TYPE) - elseif(DEFINED ${var}) - set(ONETBB_OLD_${var}_VALUE "${${var}}") - set(ONETBB_OLD_${var}_TYPE NORMAL_TYPE) - else() - set(ONETBB_OLD_${var}_TYPE NONE_TYPE) - endif() - set(${var} "${value}" CACHE PATH "" FORCE) - endmacro() - - macro(pop_variable var) - if(ONETBB_OLD_${var}_TYPE STREQUAL CACHE_TYPE) - set(${var} "${ONETBB_OLD_${var}_VALUE}" CACHE PATH "" FORCE) - elseif(ONETBB_OLD_${var}_TYPE STREQUAL NORMAL_TYPE) - unset(${var} CACHE) - set(${var} "${ONETBB_OLD_${var}_VALUE}") - elseif(ONETBB_OLD_${var}_TYPE STREQUAL NONE_TYPE) - unset(${var} CACHE) - else() - message(FATAL_ERROR "Trying to pop a variable that has not been pushed: ${var}") - endif() - endmacro() - + # We set BUILD_SHARED_LIBS as a normal variable. oneTBB's subdirectory + # inherits it, and it disappears when this function returns, so the caller's + # value is restored for free. if(TBB_PREFER_STATIC) - push_variable(BUILD_SHARED_LIBS OFF) + set(BUILD_SHARED_LIBS OFF) else() - push_variable(BUILD_SHARED_LIBS ON) + set(BUILD_SHARED_LIBS ON) endif() set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME tbb) include(CPM) CPMAddPackage("gh:uxlfoundation/oneTBB@2022.3.0") - - pop_variable(BUILD_SHARED_LIBS) endfunction() onetbb_import_target()