From 4c19cb8a2215983ac338c2b3151a16450d57eea1 Mon Sep 17 00:00:00 2001 From: Sergey Linev Date: Thu, 24 Apr 2025 12:45:07 +0200 Subject: [PATCH] [cmake] do not check none-existing variables Then checking ROOTSYS, do not try to modify none-existing variables. Like LD_LIBRARY_PATH on windows. Also no need to change ROOTSYS if it set correctly --- CMakeLists.txt | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 772f4aadc7310..a00f38e001262 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,19 +57,26 @@ set(DIR_PERMISSIONS DIRECTORY_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE G # Before setting ROOTSYS, make sure that the environment isn't polluted by a different # ROOT build. This is significant e,g. for roottest, which will otherwise have libraries # of a different ROOT build available / visible / reachable. -if(NOT $ENV{ROOTSYS} STREQUAL "") +if(NOT $ENV{ROOTSYS} STREQUAL "" AND NOT $ENV{ROOTSYS} STREQUAL "${CMAKE_BINARY_DIR}") function(strip_path ENV_VAR _path) - string(REPLACE ":${_path}:" ":" _temp_envvar $ENV{${ENV_VAR}}) - string(REGEX REPLACE "^${_path}:" "" _temp_envvar ${_temp_envvar}) - string(REGEX REPLACE ":${_path}$" "" _temp_envvar ${_temp_envvar}) - if (_temp_envvar STREQUAL _path) - set(ENV{ENV_VAR} "") - else() - set(ENV{ENV_VAR} "${_temp_envvar}") + if(NOT $ENV{${ENV_VAR}} STREQUAL "") + string(REPLACE ":${_path}:" ":" _temp_envvar $ENV{${ENV_VAR}}) + string(REGEX REPLACE "^${_path}:" "" _temp_envvar ${_temp_envvar}) + string(REGEX REPLACE ":${_path}$" "" _temp_envvar ${_temp_envvar}) + if (_temp_envvar STREQUAL _path) + set(ENV{ENV_VAR} "") + else() + set(ENV{ENV_VAR} "${_temp_envvar}") + endif() endif() endfunction() strip_path("PATH" "$ENV{ROOTSYS}/bin") - strip_path("LD_LIBRARY_PATH" "$ENV{ROOTSYS}/lib") + if(not WIN32) + strip_path("LD_LIBRARY_PATH" "$ENV{ROOTSYS}/lib") + endif() + if(APPLE) + strip_path("DYLD_LIBRARY_PATH" "$ENV{ROOTSYS}/lib") + endif() strip_path("PYTHONPATH" "$ENV{ROOTSYS}/lib") # if we leave the ':' it will result in an empty entry in the CMAKE_PREFIX_PATH # which will interpreted as the current directory.