Skip to content

Commit

Permalink
Add cet_transitive_paths() function
Browse files Browse the repository at this point in the history
This function accepts a path name and a project name (default is the
current project name).  For each transitive dependency of the
specificied project name, the value of the corresponding path name is
appended to an output variable.
  • Loading branch information
knoepfel committed Jan 19, 2024
1 parent 3e0ea4a commit 0d9476c
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 14 deletions.
18 changes: 4 additions & 14 deletions Modules/CetTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ include(CetMake)
include(CetPackagePath)
# May need to escape a string to avoid misinterpretation as regex
include(CetRegexEscape)
# Need to specify transitive BINARY_DIR paths for COMPILE_ONLY tests
include(CetTransitivePaths)

##################
# Programs and Modules
Expand Down Expand Up @@ -688,8 +690,8 @@ test ${test} must be defined already to be specified as a fixture for ${CET_TARG
endif()
endif()
if (CET_COMPILE_ONLY)
_transitive_binary_directories(${CETMODULES_CURRENT_PROJECT_NAME})
list(JOIN TRANSITIVE_BINARY_DIRS ":" DIRS_FOR_PREFIX_PATH)
cet_transitive_paths(BINARY_DIR IN_TREE)
list(JOIN TRANSITIVE_PATHS_WITH_BINARY_DIR ":" DIRS_FOR_PREFIX_PATH)
set(TEST_CMAKE_PREFIX_PATH "CMAKE_PREFIX_PATH=path_list_prepend:${DIRS_FOR_PREFIX_PATH}")
get_test_property(${target} ENVIRONMENT_MODIFICATION CET_TEST_ENV_TMP)
if (CET_TEST_ENV_TMP)
Expand Down Expand Up @@ -1100,15 +1102,3 @@ function(_update_defined_test_groups)
FORCE
)
endfunction()

function(_transitive_binary_directories PKG)
set(TRANSITIVE_BINARY_DIRS_TMP ${${PKG}_BINARY_DIR})
foreach(DEP IN LISTS CETMODULES_FIND_DEPS_PNAMES_PROJECT_${PKG})
if (${DEP}_IN_TREE)
_transitive_binary_directories(${DEP})
list(APPEND TRANSITIVE_BINARY_DIRS_TMP ${TRANSITIVE_BINARY_DIRS})
endif()
endforeach()
list(REMOVE_DUPLICATES TRANSITIVE_BINARY_DIRS_TMP)
set(TRANSITIVE_BINARY_DIRS ${TRANSITIVE_BINARY_DIRS_TMP} PARENT_SCOPE)
endfunction()
88 changes: 88 additions & 0 deletions Modules/CetTransitivePaths.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#[================================================================[.rst:
CetTransitivePaths
------------------
Defines the function :commmand:`cet_transitive_paths`.
#]================================================================]

include_guard()

#[================================================================[.rst:
.. command:: cet_transitive_paths
Get a list of path values for all transitive dependencies of the
given project name. For a given path name, the dependency tree of
the given project is searched according to the dependencies
specified via ``find_package``.
For example, if the path name ``"MY_PATH"`` is supplied, the
function will traverse the dependency structure and collect all
values of the path name ``"<project-or-dependency name>_MY_PATH"``.
The result can be accessed via the variable
``"TRANSITIVE_PATHS_WITH_MY_PATH"``.
.. code-block:: cmake
cet_transitive_paths(<path-name> [<project-variable localization options>] [IN_TREE] [PROJECT <project-name>])
Options
^^^^^^^
``[PROJECT] <project-name>``
The top-level project from which the transitive dependency
traversal occurs. (default
:variable:`${CETMODULES_CURRENT_PROJECT_NAME}
<CETMODULES_CURRENT_PROJECT_NAME>`).
``IN_TREE``
Include paths only from projects that are included in the build tree.
Non-option arguments
^^^^^^^^^^^^^^^^^^^^
``[<path-name>]``
The name of the path that serves as the suffix for the top-level
project and all transitive dependencies. The path name can be a
Cetmodules project variable, in which case the options to
:command:`cet_localize_pv` may also be provided.
#]================================================================]

function(cet_transitive_paths PATH)
cmake_parse_arguments(PARSE_ARGV 1 CTP "IN_TREE;BINARY;SOURCE;TRY_BINARY" "PROJECT" "")
cet_passthrough(FLAG APPEND CTP_BINARY clpv_args)
cet_passthrough(FLAG APPEND CTP_SOURCE clpv_args)
cet_passthrough(FLAG APPEND CTP_TRY_BINARY clpv_args)

set(PKG ${CETMODULES_CURRENT_PROJECT_NAME})
if (CTP_PROJECT)
set(PKG ${CTP_PROJECT})
endif()

_cet_transitive_project_names(${PKG} PNAMES_RESULT CTP_IN_TREE)
foreach(DEP IN LISTS PNAMES_RESULT)
if (DEFINED CACHE{CETMODULES_${PATH}_PROPERTIES_PROJECT_${DEP}})
cet_localize_pv(${DEP} ${PATH} ${clpv_args})
endif()
list(APPEND TRANSITIVE_PATHS_TMP ${${DEP}_${PATH}})
endforeach()
set(TRANSITIVE_PATHS_WITH_${PATH} ${TRANSITIVE_PATHS_TMP} PARENT_SCOPE)

endfunction()

function(_cet_transitive_project_names PKG RESULT_LIST)
set(RESULT_LIST_TMP ${${RESULT_LIST}})
foreach(DEP IN LISTS CETMODULES_FIND_DEPS_PNAMES_PROJECT_${PKG})
if (PKG STREQUAL DEP OR
(ARGN STREQUAL "IN_TREE" AND NOT ${DEP}_IN_TREE))
continue()
endif()
if (NOT "${DEP}" IN_LIST RESULT_LIST_TMP)
_cet_transitive_project_names("${DEP}" RESULT_LIST_TMP ${ARGN})
endif()
endforeach()
list(PREPEND RESULT_LIST_TMP ${PKG})
set(${RESULT_LIST} ${RESULT_LIST_TMP} PARENT_SCOPE)
endfunction()

0 comments on commit 0d9476c

Please sign in to comment.