diff --git a/rapids-cmake/cmake/support_conda_env.cmake b/rapids-cmake/cmake/support_conda_env.cmake index 574f667f..587d7359 100644 --- a/rapids-cmake/cmake/support_conda_env.cmake +++ b/rapids-cmake/cmake/support_conda_env.cmake @@ -21,20 +21,25 @@ rapids_cmake_support_conda_env .. versionadded:: v21.06.00 -Establish a target that holds the CONDA include and link directories. +Establish a target that holds the necessary compile and link information +to properly support building in CONDA envs. .. code-block:: cmake rapids_cmake_support_conda_env( [MODIFY_PREFIX_PATH] ) Creates a global interface target called `target_name` that holds -the CONDA include and link directories, when executed. +the CONDA compile options, include directories, and link directories when executed. .. versionadded:: v24.06.00 The include directories that `target_name` holds will be `-isystem` to match the behavior of conda when it builds projects. +.. versionadded:: v24.08.00 + +The `target_name` target will add the required compile flags to ensure debug builds +are generated with `-O0` instead of the conda env default of `-O2`. Also offers the ability to modify :cmake:variable:`CMAKE_PREFIX_PATH ` to include the following paths based on the current conda environment: @@ -182,5 +187,11 @@ function(rapids_cmake_support_conda_env target) modify_cmake_prefix_path(PATHS "$ENV{CONDA_PREFIX}") endif() endif() + + # The conda env will have setup `CXXFLAGS`, etc to contain `-O2` which we + # need to override to get proper debug information for local variables, etc. + # Since `target_compile_options` values are appended after `CXXFLAGS` we know + # that this will properly override the conda `-O2` + target_compile_options(${target} INTERFACE "$<$>:-O0>") endif() endfunction() diff --git a/testing/cmake/conda_env-build.cmake b/testing/cmake/conda_env-build.cmake index c52ea306..324f9116 100644 --- a/testing/cmake/conda_env-build.cmake +++ b/testing/cmake/conda_env-build.cmake @@ -26,6 +26,11 @@ if(NOT TARGET conda_env) message(FATAL_ERROR "Expected target conda_env to exist") endif() +get_target_property(compile_options conda_env INTERFACE_COMPILE_OPTIONS) +if( NOT "$<$>:-O0>" IN_LIST compile_options) + message(FATAL_ERROR "Expected $<$>:-O0> to be in the compile options of `conda_env`") +endif() + get_target_property(include_dirs conda_env INTERFACE_SYSTEM_INCLUDE_DIRECTORIES) if( NOT "$ENV{BUILD_PREFIX}/include" IN_LIST include_dirs) message(FATAL_ERROR "Expected env{BUILD_PREFIX} to be in the include dirs of `conda_env`") diff --git a/testing/cmake/conda_env-prefix.cmake b/testing/cmake/conda_env-prefix.cmake index 840dcb27..dfa0742e 100644 --- a/testing/cmake/conda_env-prefix.cmake +++ b/testing/cmake/conda_env-prefix.cmake @@ -21,6 +21,14 @@ set(ENV{PREFIX} "/opt/local/prefix") set(ENV{CONDA_PREFIX} "/opt/conda/prefix") rapids_cmake_support_conda_env(conda_env) +if(NOT TARGET conda_env) + message(FATAL_ERROR "Expected target conda_env to exist") +endif() + +get_target_property(compile_options conda_env INTERFACE_COMPILE_OPTIONS) +if( NOT "$<$>:-O0>" IN_LIST compile_options) + message(FATAL_ERROR "Expected $<$>:-O0> to be in the compile options of `conda_env`") +endif() get_target_property(include_dirs conda_env INTERFACE_SYSTEM_INCLUDE_DIRECTORIES) if( "$ENV{BUILD_PREFIX}/include" IN_LIST include_dirs)