Skip to content

Make non-system include paths accessible at runtime #19179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,6 @@ install(
PATTERN "pkgconfig" EXCLUDE
)

if(Vc_INCLUDE_DIR)
set(MODULES_ROOT_INCPATH "ROOT_INCLUDE_PATH=${Vc_INCLUDE_DIR}:${ROOT_INCLUDE_PATH}")
endif()

# modules.idx
if(runtime_cxxmodules)
ROOT_GET_LIBRARY_OUTPUT_DIR(library_output_dir)
Expand Down Expand Up @@ -564,7 +560,7 @@ if(WIN32)
set(hsimple_cmd COMMAND ${CMAKE_COMMAND} -E env PATH="${CMAKE_RUNTIME_OUTPUT_DIRECTORY}\\\;%PATH%"
ROOTIGNOREPREFIX=1 ROOT_HIST=0 $<TARGET_FILE:root.exe> -l -q -b -n -x ${CMAKE_SOURCE_DIR}/tutorials/hsimple.C -e return)
else()
set(hsimple_cmd COMMAND ${MODULES_ROOT_INCPATH} ${ld_library_path}=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}:$ENV{${ld_library_path}}
set(hsimple_cmd COMMAND ROOT_INCLUDE_PATH="${DEFAULT_ROOT_INCLUDE_PATH}" ${ld_library_path}=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}:$ENV{${ld_library_path}}
ROOTIGNOREPREFIX=1 ROOT_HIST=0 $<TARGET_FILE:root.exe> -l -q -b -n -x ${CMAKE_SOURCE_DIR}/tutorials/hsimple.C -e return)
endif()
add_custom_command(OUTPUT tutorials/hsimple.root
Expand Down
36 changes: 36 additions & 0 deletions cmake/modules/RootMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2135,3 +2135,39 @@ function(generateManual name input output)

install(FILES ${output} DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
endfunction()

#----------------------------------------------------------------------------
# If path is a system path, set the return variable is_system_path to true.
# The 1st argument is the path that should be checked
# The 2nd argument is the return value
#----------------------------------------------------------------------------
function (IS_SYSTEM_PATH path is_system_path)
foreach (dir ${CMAKE_SYSTEM_PATH})
if ("${path}" STREQUALS "$dir")
set(${is_system_path} true PARENT_SCOPE)
endif()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
endif()
return()
endif()

Maybe my cmake is too rusty, but shouldn't we not always set is_system_path to false at the end of the function?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, I think the return is needed

endforeach()
set(${is_system_path} false PARENT_SCOPE)
Comment on lines +2147 to +2150
Copy link
Member

@hageboeck hageboeck Jun 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The canonical bools are all caps, and we can break out early:

Suggested change
set(${is_system_path} true PARENT_SCOPE)
endif()
endforeach()
set(${is_system_path} false PARENT_SCOPE)
set(${is_system_path} TRUE PARENT_SCOPE)
return()
endif()
endforeach()
set(${is_system_path} FALSE PARENT_SCOPE)

endfunction()

#----------------------------------------------------------------------------
# If path is not a system path, append it to the given variable
# The 1st argument is the path to be checked
# The 2nd argument is the variable that the path gets appended to if it is
# not a system path.
#----------------------------------------------------------------------------
function (IF_NOT_SYSTEM_PATH_APPEND path variable)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this function ever going to be called with another variable than the default root include path? If yes, fair enough, otherwise I would call it something like BUILD_ROOT_INCLUDE_PATH("${Vc_INCLUDE_DIR}"), and remove the second argument, since any negations in names are hard to parse.

IS_SYSTEM_PATH("${path}" is_system_path)
if (NOT is_system_path)
if (${${variable}} STRING_EMPTY)
set(${variable} "${path}" PARENT_SCOPE)
else()
if(WIN32)
set(ROOT_PATH_SEPARATOR ";")
elseif(UNIX)
set(ROOT_PATH_SEPARATOR ":")
endif()
set(${variable} "${${variable}}${ROOT_PATH_SEPARATOR}${path}" PARENT_SCOPE)
endif()
endif()
endfunction()
1 change: 1 addition & 0 deletions cmake/modules/SearchInstalledSoftware.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,7 @@ elseif(vc)
endif()
if(Vc_FOUND)
set_property(DIRECTORY APPEND PROPERTY INCLUDE_DIRECTORIES ${Vc_INCLUDE_DIR})
IF_NOT_SYSTEM_PATH_APPEND("${Vc_INCLUDE_DIR}" DEFAULT_ROOT_INCLUDE_PATH)
endif()
endif()

Expand Down
1 change: 1 addition & 0 deletions config/thisroot.bat
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ cd /D %OLDPATH%
set PATH=%ROOTSYS%\bin;%PATH%
set CMAKE_PREFIX_PATH=%ROOTSYS%;%CMAKE_PREFIX_PATH%
set PYTHONPATH=%ROOTSYS%\bin;%PYTHONPATH%
set ROOT_INCLUDE_PATH=@DEFAULT_ROOT_INLUCDE_PATH@;%ROOT_INCLUDE_PATH%
set OLDPATH=
set THIS=
14 changes: 14 additions & 0 deletions config/thisroot.csh
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ if ($?old_rootsys) then
-e "s;^$old_rootsys/etc/notebook${DOLLAR};;g"`
endif

if ($?ROOT_INCLUDE_PATH) then
setenv ROOT_INCLUDE_PATH `set DOLLAR='$'; echo $ROOT_INCLUDE_PATH | \
sed -e "s;:@DEFAULT_ROOT_INCLUDE_PATH@:;:;g" \
-e "s;:@DEFAULT_ROOT_INCLUDE_PATH@${DOLLAR};;g" \
-e "s;^@DEFAULT_ROOT_INCLUDE_PATH@:;;g" \
-e "s;^@DEFAULT_ROOT_INCLUDE_PATH@${DOLLAR};;g"`
endif

endif


Expand Down Expand Up @@ -232,6 +240,12 @@ else
setenv JUPYTER_CONFIG_DIR ${ROOTSYS}/etc/notebook
endif

if ($?ROOT_INCLUDE_PATH) then
setenv ROOT_INCLUDE_PATH @DEFAULT_ROOT_INLUCDE_PATH@:$ROOT_INCLUDE_PATH
else
setenv ROOT_INCLUDE_PATH @DEFAULT_ROOT_INLUCDE_PATH@
endif

endif # if ("$thisroot" != "")

set thisroot=
Expand Down
1 change: 1 addition & 0 deletions config/thisroot.fish
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ update_path MANPATH "$old_rootsys" "/man" @mandir@
update_path CMAKE_PREFIX_PATH "$old_rootsys" "" $ROOTSYS
update_path JUPYTER_PATH "$old_rootsys" "/etc/notebook" $ROOTSYS/etc/notebook
update_path JUPYTER_CONFIG_DIR "$old_rootsys" "/etc/notebook" $ROOTSYS/etc/notebook
update_path ROOT_INCLUDE_PATH "@DEFAULT_ROOT_INCLUDE_PATH@" "" "@DEFAULT_ROOT_INCLUDE_PATH@"

functions -e update_path
set -e old_rootsys
Expand Down
1 change: 1 addition & 0 deletions config/thisroot.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ $ROOTSYS = split-path -parent (get-item $scriptPath)
$env:PATH = $ROOTSYS + '\bin;' + $env:PATH
$env:CMAKE_PREFIX_PATH = $ROOTSYS + ';' + $env:CMAKE_PREFIX_PATH
$env:PYTHONPATH = $ROOTSYS + '\bin;' + $env:PYTHONPATH
$env:ROOT_INCLUDE_PATH = "@DEFAULT_ROOT_INCLUDE_PATH@" + ';' + $env:ROOT_INCLUDE_PATH
12 changes: 12 additions & 0 deletions config/thisroot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ clean_environment()
default_manpath=""
fi
fi
if [ -n "${ROOT_INCLUDE_PATH-}" ]; then
drop_from_path "$ROOT_INCLUDE_PATH" "@DEFAULT_ROOT_INCLUDE_PATH@"
ROOT_INCLUDE_PATH=$newpath
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newpath seems to be undefined here, or did I miss something?

fi
}

set_environment()
Expand Down Expand Up @@ -162,6 +166,14 @@ set_environment()
else
JUPYTER_CONFIG_DIR=$ROOTSYS/etc/notebook:$JUPYTER_CONFIG_DIR; export JUPYTER_CONFIG_DIR
fi

if [ -z "${ROOT_INCLUDE_PATH-}" ]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable name contains an extra - if I'm not mistaken, so this would always be zero.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is bash syntax for using a default value (of nothing) when the variable is not set.

Copy link
Member

@hageboeck hageboeck Jun 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I had to read up on the subtle difference between ${VAR:-} vs ${VAR-} ...

ROOT_INCLUDE_PATH=@DEFAULT_ROOT_INCLUDE_PATH@
export ROOT_INCLUDE_PATH
else
ROOT_INCLUDE_PATH=@DEFAULT_ROOT_INCLUDE_PATH@:$ROOT_INCLUDE_PATH
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you consider this an issue if DEFAULT_ROOT_INCLUDE_PATH is empty? Not just here but in the other shell setups?

export ROOT_INCLUDE_PATH
Comment on lines +171 to +175
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ROOT_INCLUDE_PATH=@DEFAULT_ROOT_INCLUDE_PATH@
export ROOT_INCLUDE_PATH
else
ROOT_INCLUDE_PATH=@DEFAULT_ROOT_INCLUDE_PATH@:$ROOT_INCLUDE_PATH
export ROOT_INCLUDE_PATH
export ROOT_INCLUDE_PATH=@DEFAULT_ROOT_INCLUDE_PATH@
else
export ROOT_INCLUDE_PATH=@DEFAULT_ROOT_INCLUDE_PATH@:$ROOT_INCLUDE_PATH

fi
}

getTrueShellExeName() { # mklement0 https://stackoverflow.com/a/23011530/7471760
Expand Down
2 changes: 1 addition & 1 deletion roottest/root/io/transient/base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ ROOTTEST_ADD_TEST(hadd_autoload
COMMAND hadd -f data_merge.root data1.root data2.root
OUTREF hadd_autoload${outref_suffix}.ref
FIXTURES_REQUIRED root-io-transient-base-WriteFile-fixture
ENVIRONMENT ROOT_INCLUDE_PATH=${CMAKE_CURRENT_SOURCE_DIR})
ENVIRONMENT ROOT_INCLUDE_PATH=${CMAKE_CURRENT_SOURCE_DIR}:${DEFAULT_ROOT_INCLUDE_PATH})
Loading