diff --git a/Modules/CetTest.cmake b/Modules/CetTest.cmake index 21451220..13494dc7 100644 --- a/Modules/CetTest.cmake +++ b/Modules/CetTest.cmake @@ -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 @@ -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) @@ -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() diff --git a/Modules/CetTransitivePaths.cmake b/Modules/CetTransitivePaths.cmake new file mode 100644 index 00000000..315b7a71 --- /dev/null +++ b/Modules/CetTransitivePaths.cmake @@ -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 ``"_MY_PATH"``. + The result can be accessed via the variable + ``"TRANSITIVE_PATHS_WITH_MY_PATH"``. + + .. code-block:: cmake + + cet_transitive_paths( [] [IN_TREE] [PROJECT ]) + + Options + ^^^^^^^ + + ``[PROJECT] `` + The top-level project from which the transitive dependency + traversal occurs. (default + :variable:`${CETMODULES_CURRENT_PROJECT_NAME} + `). + + ``IN_TREE`` + Include paths only from projects that are included in the build tree. + + Non-option arguments + ^^^^^^^^^^^^^^^^^^^^ + + ``[]`` + The variable in which the value(s) of project variable + ```` in project ```` shall be returned. If + not specified, the property's values shall be returned in a + variable in caller's scope whose name is ````. + +#]================================================================] + +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()