| 1 |
# @HEADER |
| 2 |
# ***************************************************************************** |
| 3 |
# TriBITS: Tribal Build, Integrate, and Test System |
| 4 |
# |
| 5 |
# Copyright 2013-2016 NTESS and the TriBITS contributors. |
| 6 |
# SPDX-License-Identifier: BSD-3-Clause |
| 7 |
# ***************************************************************************** |
| 8 |
# @HEADER |
| 9 |
|
| 10 |
include(TribitsDeprecatedHelpers) |
| 11 |
|
| 12 |
|
| 13 |
# Function that creates enable-only dependency data-structures |
| 14 |
# |
| 15 |
# For each enabled package `<Package>`, this function sets up the global list |
| 16 |
# var:: |
| 17 |
# |
| 18 |
# <Package>_FULL_ENABLED_DEP_PACKAGES |
| 19 |
# |
| 20 |
# If ``${PROJECT_NAME}_GENERATE_EXPORT_FILES_FOR_ONLY_LISTED_PACKAGES`` is |
| 21 |
# set, then ``<Package>_FULL_ENABLED_DEP_PACKAGES`` will only be sets for |
| 22 |
# those packages. Otherwise, ``<Package>_FULL_ENABLED_DEP_PACKAGES`` will be |
| 23 |
# set for all packages listed in `${PROJECT_NAME}_ENABLED_INTERNAL_PACKAGES`_. |
| 24 |
# |
| 25 |
# NOTE: The modern TriBITS implementation does not need this full list of |
| 26 |
# dependencies for each package. Only the function |
| 27 |
# `tribits_find_most_recent_file_timestamp()` needs this. (Therefore, this |
| 28 |
# could not be striped out of TriBITS because there are still some projects |
| 29 |
# that use this function.) |
| 30 |
# |
| 31 |
function(tribits_set_up_enabled_only_dependencies) |
| 32 |
|
| 33 |
set(GENERATE_EXPORT_DEPENDENCIES ${${PROJECT_NAME}_GENERATE_EXPORT_FILE_DEPENDENCIES}) |
| 34 |
if ("${${PROJECT_NAME}_GENERATE_EXPORT_FILES_FOR_ONLY_LISTED_PACKAGES}" STREQUAL "" |
| 35 |
AND NOT |
| 36 |
"${${PROJECT_NAME}_GENERATE_EXPORT_FILES_FOR_ONLY_LISTED_SE_PACKAGES}" STREQUAL "" |
| 37 |
) |
| 38 |
tribits_deprecated( |
| 39 |
"The cache var" |
| 40 |
" ${PROJECT_NAME}_GENERATE_EXPORT_FILES_FOR_ONLY_LISTED_SE_PACKAGES" |
| 41 |
"='${${PROJECT_NAME}_GENERATE_EXPORT_FILES_FOR_ONLY_LISTED_SE_PACKAGES}'" |
| 42 |
" is deprecated! Please instead set" |
| 43 |
" ${PROJECT_NAME}_GENERATE_EXPORT_FILES_FOR_ONLY_LISTED_PACKAGES" |
| 44 |
"='${${PROJECT_NAME}_GENERATE_EXPORT_FILES_FOR_ONLY_LISTED_SE_PACKAGES}'") |
| 45 |
set(${PROJECT_NAME}_GENERATE_EXPORT_FILES_FOR_ONLY_LISTED_PACKAGES |
| 46 |
${${PROJECT_NAME}_GENERATE_EXPORT_FILES_FOR_ONLY_LISTED_SE_PACKAGES} ) |
| 47 |
endif() |
| 48 |
|
| 49 |
# Determine lastExportTribitsPackage if not to generate any of these full |
| 50 |
# dependency lists |
| 51 |
set(lastExportTribitsPackage "") |
| 52 |
if (GENERATE_EXPORT_DEPENDENCIES |
| 53 |
AND ${PROJECT_NAME}_GENERATE_EXPORT_FILES_FOR_ONLY_LISTED_PACKAGES |
| 54 |
) |
| 55 |
# Find the last enabled package for which an export file is requested. |
| 56 |
set(LAST_PKG_IDX -1) |
| 57 |
set(LAST_PKG) |
| 58 |
foreach(tribitsPkg IN LISTS |
| 59 |
${PROJECT_NAME}_GENERATE_EXPORT_FILES_FOR_ONLY_LISTED_PACKAGES |
| 60 |
) |
| 61 |
set(PKG_IDX ${${tribitsPkg}_PKG_IDX}) |
| 62 |
if (NOT "${PKG_IDX}" STREQUAL "") |
| 63 |
# The listed package is enabled so we will consider it |
| 64 |
if (PKG_IDX GREATER ${LAST_PKG_IDX}) |
| 65 |
set(LAST_PKG_IDX ${PKG_IDX}) |
| 66 |
set(LAST_PKG ${tribitsPkg}) |
| 67 |
endif() |
| 68 |
endif() |
| 69 |
endforeach() |
| 70 |
if (LAST_PKG) |
| 71 |
# At least one listed package was enabled |
| 72 |
set(lastExportTribitsPackage ${LAST_PKG}) |
| 73 |
else() |
| 74 |
# None of the listed packages were enabled so don't bother generating |
| 75 |
# any export dependencies |
| 76 |
set(GENERATE_EXPORT_DEPENDENCIES FALSE) |
| 77 |
endif() |
| 78 |
|
| 79 |
endif() |
| 80 |
|
| 81 |
if (GENERATE_EXPORT_DEPENDENCIES) |
| 82 |
|
| 83 |
if (lastExportTribitsPackage) |
| 84 |
message("\nSetting up export dependencies up through ${lastExportTribitsPackage} ...\n") |
| 85 |
else() |
| 86 |
message("\nSetting up export dependencies for all enabled packages ...\n") |
| 87 |
endif() |
| 88 |
|
| 89 |
foreach(tribitsPackage IN LISTS ${PROJECT_NAME}_ENABLED_INTERNAL_PACKAGES) |
| 90 |
tribits_package_set_full_enabled_dep_packages(${tribitsPackage}) |
| 91 |
if (${PROJECT_NAME}_DUMP_PACKAGE_DEPENDENCIES) |
| 92 |
set(printedVar FALSE) |
| 93 |
print_nonempty_var_with_spaces(${tribitsPackage}_FULL_ENABLED_DEP_PACKAGES |
| 94 |
printedVar) |
| 95 |
if (NOT printedVar) |
| 96 |
message("-- ${tribitsPackage}: No library dependencies!") |
| 97 |
endif() |
| 98 |
endif() |
| 99 |
if ("${lastExportTribitsPackage}" STREQUAL "${tribitsPackage}") |
| 100 |
break() |
| 101 |
endif() |
| 102 |
endforeach() |
| 103 |
|
| 104 |
endif() |
| 105 |
|
| 106 |
endfunction() |
| 107 |
|
| 108 |
|
| 109 |
# Function that sets up the full package dependencies for the given *internal* |
| 110 |
# enabled package ``${packageName}``, including all of its indirect upstream |
| 111 |
# *internal* package dependencies. |
| 112 |
# |
| 113 |
# After running, this function sets the internal cache var: |
| 114 |
# |
| 115 |
# * ``${packageName}_FULL_ENABLED_DEP_PACKAGES`` |
| 116 |
# |
| 117 |
# NOTE: This function must be called for all of the upstream internal packages |
| 118 |
# before calling it for this package. |
| 119 |
# |
| 120 |
# NOTE: The complexity of this function is O(<numPackages>^2) due to the |
| 121 |
# sorting algorithm. That is why it would be good to get rid of this function |
| 122 |
# at some point (or refactor it to have a better complexity). |
| 123 |
# |
| 124 |
function(tribits_package_set_full_enabled_dep_packages packageName) |
| 125 |
|
| 126 |
tribits_package_build_unsorted_full_enabled_dep_packages(${packageName} |
| 127 |
packageFullDepsList) |
| 128 |
|
| 129 |
tribits_package_sort_full_enabled_dep_packages(packageFullDepsList |
| 130 |
orderedPackageFullDepsList) |
| 131 |
|
| 132 |
global_set(${packageName}_FULL_ENABLED_DEP_PACKAGES ${orderedPackageFullDepsList}) |
| 133 |
|
| 134 |
endfunction() |
| 135 |
|
| 136 |
|
| 137 |
# Helper function that builds the full list of internal upstream dep packages |
| 138 |
# (with no duplicates) for a given internal package. |
| 139 |
# |
| 140 |
function(tribits_package_build_unsorted_full_enabled_dep_packages packageName |
| 141 |
packageFullDepsListOut |
| 142 |
) |
| 143 |
|
| 144 |
set(packageFullDepsList "") |
| 145 |
foreach(depPkg IN LISTS ${packageName}_LIB_DEFINED_DEPENDENCIES) |
| 146 |
if ((${depPkg}_PACKAGE_BUILD_STATUS STREQUAL "INTERNAL") |
| 147 |
AND ((${packageName}_LIB_DEP_REQUIRED AND ${PROJECT_NAME}_ENABLE_${depPkg}) |
| 148 |
OR ((NOT ${packageName}_LIB_DEP_REQUIRED) AND ${packageName}_ENABLE_${depPkg})) |
| 149 |
) |
| 150 |
list(APPEND packageFullDepsList ${depPkg}) |
| 151 |
endif() |
| 152 |
endforeach() |
| 153 |
|
| 154 |
if(packageFullDepsList) |
| 155 |
list(REMOVE_DUPLICATES packageFullDepsList) |
| 156 |
|
| 157 |
foreach(DEP_PACKAGE IN LISTS packageFullDepsList) |
| 158 |
list(APPEND packageFullDepsList ${${DEP_PACKAGE}_FULL_ENABLED_DEP_PACKAGES}) |
| 159 |
endforeach() |
| 160 |
|
| 161 |
list(REMOVE_DUPLICATES packageFullDepsList) |
| 162 |
endif() |
| 163 |
|
| 164 |
set(${packageFullDepsListOut} ${packageFullDepsList} PARENT_SCOPE) |
| 165 |
|
| 166 |
endfunction() |
| 167 |
|
| 168 |
|
| 169 |
# Helper function to sort the full set of upstream dep packages for a given |
| 170 |
# internal package. |
| 171 |
# |
| 172 |
function(tribits_package_sort_full_enabled_dep_packages packageFullDepsListName |
| 173 |
orderedPackageFullDepsListOut |
| 174 |
) |
| 175 |
|
| 176 |
set(orderedPackageFullDepsList "") |
| 177 |
|
| 178 |
foreach(depPkg IN LISTS ${packageFullDepsListName}) |
| 179 |
|
| 180 |
set(depPkgIdx ${${depPkg}_PKG_IDX}) |
| 181 |
|
| 182 |
set(sortedIndex 0) |
| 183 |
set(insertedDepPkg FALSE) |
| 184 |
|
| 185 |
foreach(sortedPackage IN LISTS orderedPackageFullDepsList) |
| 186 |
|
| 187 |
set(sortedPackageIdx ${${sortedPackage}_PKG_IDX}) |
| 188 |
|
| 189 |
if (${depPkgIdx} GREATER ${sortedPackageIdx}) |
| 190 |
list(INSERT orderedPackageFullDepsList ${sortedIndex} ${depPkg}) |
| 191 |
set(insertedDepPkg TRUE) |
| 192 |
break() |
| 193 |
endif() |
| 194 |
|
| 195 |
math(EXPR sortedIndex ${sortedIndex}+1) |
| 196 |
|
| 197 |
endforeach() |
| 198 |
|
| 199 |
if(NOT insertedDepPkg) |
| 200 |
list(APPEND orderedPackageFullDepsList ${depPkg}) |
| 201 |
endif() |
| 202 |
|
| 203 |
endforeach() |
| 204 |
|
| 205 |
set(${orderedPackageFullDepsListOut} ${orderedPackageFullDepsList} PARENT_SCOPE) |
| 206 |
|
| 207 |
endfunction() |