diff --git a/rapids-cmake/cmake/support_conda_env.cmake b/rapids-cmake/cmake/support_conda_env.cmake index 09571255..622a73d3 100644 --- a/rapids-cmake/cmake/support_conda_env.cmake +++ b/rapids-cmake/cmake/support_conda_env.cmake @@ -1,5 +1,5 @@ #============================================================================= -# Copyright (c) 2021-2024, NVIDIA CORPORATION. +# Copyright (c) 2021-2025, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -41,6 +41,14 @@ the behavior of conda when it builds projects. 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`. +.. versionadded:: v25.06.00 + +The flag `-ffile-prefix-map` is now passed to remap absolute paths starting +with `$ENV{PREFIX}` to paths relative to it in binaries generated via +compilation. This ensures paths baked into binaries are relative to the +environment prefix. This prevents Conda from rewriting these paths when the +package is installed. + Also offers the ability to modify :cmake:variable:`CMAKE_PREFIX_PATH ` to include the following paths based on the current conda environment: @@ -164,6 +172,14 @@ function(rapids_cmake_support_conda_env target) "$") endif() + # For built binaries (like libraries), remap environment absolute paths (`$PREFIX/`) to + # paths relative to the environment `$PREFIX` (``). + target_compile_options(${target} + INTERFACE "$<$:-ffile-prefix-map=$ENV{PREFIX}/=''>" + "$<$:-ffile-prefix-map=$ENV{PREFIX}/=''>" + "$<$:-Xcompiler=-ffile-prefix-map=$ENV{PREFIX}/=''>" + ) + if(modify_prefix_path) message(VERBOSE "Conda build detected") set(prefix_paths "$ENV{PREFIX}" "$ENV{BUILD_PREFIX}")