diff --git a/CMakeLists.txt b/CMakeLists.txt index 772f4aadc7310..3f7dff04eeaf2 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.