| 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 |
|
| 11 |
# TriBITS package_arch includes |
| 12 |
include(TribitsConfigureTiming) |
| 13 |
include(TribitsGetPackageSublists) |
| 14 |
|
| 15 |
# TriBITS utils includes |
| 16 |
include(FindListElement) |
| 17 |
|
| 18 |
|
| 19 |
# @MACRO: tribits_exclude_files() |
| 20 |
# |
| 21 |
# Exclude package files/dirs from the source distribution by appending |
| 22 |
# ``CPACK_SOURCE_IGNORE_FILES``. |
| 23 |
# |
| 24 |
# Usage:: |
| 25 |
# |
| 26 |
# tribits_exclude_files(<file0> <file1> ...) |
| 27 |
# |
| 28 |
# This is called in the top-level parent package's |
| 29 |
# `<packageDir>/CMakeLists.txt`_ file and each file or directory name |
| 30 |
# ``<filei>`` is actually interpreted by CMake/CPack as a regex that is |
| 31 |
# prefixed by the project's and package's source directory names so as to not |
| 32 |
# exclude files and directories of the same name and path from other packages. |
| 33 |
# If ``<filei>`` is an absolute path it is not prefixed but is appended to |
| 34 |
# ``CPACK_SOURCE_IGNORE_FILES`` unmodified. |
| 35 |
# |
| 36 |
# In general, do **NOT** put in excludes for files and directories that are |
| 37 |
# not under this package's source tree. If the given package is not enabled, |
| 38 |
# then this command will never be called! For example, don't put in excludes |
| 39 |
# for PackageB's files in PackageA's ``CMakeLists.txt`` file because if |
| 40 |
# PackageB is enabled but PackageA is not, the excludes for PackageB will |
| 41 |
# never get added to ``CPACK_SOURCE_IGNORE_FILES``. |
| 42 |
# |
| 43 |
# Also, be careful to note that the ``<filei>`` arguments are actually regexes |
| 44 |
# and one must be very careful to understand how CPack will use these regexes |
| 45 |
# to match files that get excluded from the tarball. For more details, see |
| 46 |
# `Creating Source Distributions`_. |
| 47 |
# |
| 48 |
macro(tribits_exclude_files) |
| 49 |
|
| 50 |
if (NOT "${${PACKAGE_NAME}_PARENT_PACKAGE}" STREQUAL "") |
| 51 |
message(FATAL_ERROR |
| 52 |
"ERROR: tribits_exclude_files() was called in a subpackage CmakeLists.txt file!" |
| 53 |
" Instead, move this call to the file" |
| 54 |
" ${${${PACKAGE_NAME}_PARENT_PACKAGE}_SOURCE_DIR}/CMakeLists.txt" |
| 55 |
" and adjust the paths accordingly!" ) |
| 56 |
endif() |
| 57 |
|
| 58 |
set(FILES_TO_EXCLUDE ${ARGN}) |
| 59 |
|
| 60 |
# Need to add "/<project source dir>/<package dir>/" to each file to prevent |
| 61 |
# someone from trying to exclude a file like "readme" and having it |
| 62 |
# inadvertently exclude a file matching that name in another package. |
| 63 |
set(MODIFIED_FILES_TO_EXCLUDE "") |
| 64 |
|
| 65 |
set(${PROJECT_NAME}_SOURCE_PATH ${${PROJECT_NAME}_SOURCE_DIR}) |
| 66 |
|
| 67 |
foreach(FILE ${FILES_TO_EXCLUDE}) |
| 68 |
#Ensure that if the full path was specified for the file that we don't add |
| 69 |
#"/<project source dir>/<package dir>/" again. |
| 70 |
set(MATCH_STRING "${${PACKAGE_NAME}_SOURCE_DIR}") |
| 71 |
string(REGEX MATCH ${MATCH_STRING} MATCHED ${FILE} ) |
| 72 |
if(NOT MATCHED) |
| 73 |
list(APPEND MODIFIED_FILES_TO_EXCLUDE |
| 74 |
"${${PACKAGE_NAME}_SOURCE_DIR}/${FILE}") |
| 75 |
else() |
| 76 |
list(APPEND MODIFIED_FILES_TO_EXCLUDE ${FILE}) |
| 77 |
endif() |
| 78 |
endforeach() |
| 79 |
|
| 80 |
#Leaving in for debugging purposes |
| 81 |
# message("List of files being excluded for package ${PACKAGE_NAME}") |
| 82 |
# foreach(NEW_FILE ${MODIFIED_FILES_TO_EXCLUDE}) |
| 83 |
# message(${NEW_FILE}) |
| 84 |
# endforeach() |
| 85 |
|
| 86 |
list(APPEND CPACK_SOURCE_IGNORE_FILES ${MODIFIED_FILES_TO_EXCLUDE}) |
| 87 |
if (NOT ${PROJECT_NAME}_BINARY_DIR STREQUAL ${PACKAGE_NAME}_BINARY_DIR) |
| 88 |
set(CPACK_SOURCE_IGNORE_FILES ${CPACK_SOURCE_IGNORE_FILES} PARENT_SCOPE) |
| 89 |
endif() |
| 90 |
|
| 91 |
endmacro() |
| 92 |
|
| 93 |
|
| 94 |
# Set up for packaging and distribution |
| 95 |
# |
| 96 |
macro(tribits_setup_packaging_and_distribution) |
| 97 |
|
| 98 |
tribits_config_code_start_timer(CPACK_SETUP_TIME_START_SECONDS) |
| 99 |
|
| 100 |
# K.1) Run callback function for the base project. |
| 101 |
|
| 102 |
tribits_project_define_packaging_runner() |
| 103 |
# The above must define the basic project settings for CPACK that are |
| 104 |
# specific to the project and should not be provided by the user. |
| 105 |
|
| 106 |
# K.2) Removing any packages or packages not enabled from the tarball |
| 107 |
|
| 108 |
if (${PROJECT_NAME}_EXCLUDE_DISABLED_SUBPACKAGES_FROM_DISTRIBUTION) |
| 109 |
set(tribitsPackageList ${${PROJECT_NAME}_DEFINED_INTERNAL_PACKAGES}) |
| 110 |
else() |
| 111 |
set(tribitsPackageList ${${PROJECT_NAME}_DEFINED_INTERNAL_TOPLEVEL_PACKAGES}) |
| 112 |
endif() |
| 113 |
|
| 114 |
tribits_get_sublist_nonenabled(tribitsPackageList nonEnabledTribitsPackage "") |
| 115 |
|
| 116 |
foreach(TRIBITS_PACKAGE ${nonEnabledTribitsPackage}) |
| 117 |
|
| 118 |
# Determine if this is a package to not ignore |
| 119 |
find_list_element(TRIBITS_CPACK_PACKAGES_TO_NOT_IGNORE |
| 120 |
${TRIBITS_PACKAGE} TRIBITS_PACKAGE_DONT_IGNORE) |
| 121 |
|
| 122 |
if (NOT TRIBITS_PACKAGE_DONT_IGNORE) |
| 123 |
|
| 124 |
# Checking if we have a relative path to the package's files. Since the |
| 125 |
# exclude is a regular expression any "../" will be interpreted as <any |
| 126 |
# char><any char>/ which would never match the package's actual |
| 127 |
# directory. There isn't a direct way in cmake to convert a relative |
| 128 |
# path into an absolute path with string operations so as a way of |
| 129 |
# making sure that we get the correct path of the package we use a |
| 130 |
# find_path for the CMakeLists.txt file for the package. Since the |
| 131 |
# package has to have this file to work correctly it should be |
| 132 |
# guaranteed to be there. |
| 133 |
string(REGEX MATCH "[.][.]/" RELATIVE_PATH_CHARS_MATCH |
| 134 |
${${TRIBITS_PACKAGE}_REL_SOURCE_DIR}) |
| 135 |
if ("${RELATIVE_PATH_CHARS_MATCH}" STREQUAL "") |
| 136 |
list(PREPEND CPACK_SOURCE_IGNORE_FILES |
| 137 |
"${PROJECT_SOURCE_DIR}/${${TRIBITS_PACKAGE}_REL_SOURCE_DIR}/") |
| 138 |
else() |
| 139 |
find_path(ABSOLUTE_PATH CMakeLists.txt PATHS |
| 140 |
"${PROJECT_SOURCE_DIR}/${${TRIBITS_PACKAGE}_REL_SOURCE_DIR}" |
| 141 |
NO_DEFAULT_PATH) |
| 142 |
if ("${ABSOLUTE_PATH}" STREQUAL "ABSOLUTE_PATH-NOTFOUND") |
| 143 |
message(AUTHOR_WARNING "Relative path found for disabled package" |
| 144 |
" ${TRIBITS_PACKAGE} but package was missing a CMakeLists.txt file." |
| 145 |
" This disabled package will likely not be excluded from a source release") |
| 146 |
endif() |
| 147 |
list(PREPEND CPACK_SOURCE_IGNORE_FILES "${ABSOLUTE_PATH}") |
| 148 |
endif() |
| 149 |
endif() |
| 150 |
|
| 151 |
endforeach() |
| 152 |
|
| 153 |
# Add excludes for VC files/dirs |
| 154 |
list(APPEND CPACK_SOURCE_IGNORE_FILES |
| 155 |
/[.]git/ |
| 156 |
[.]gitignore$ |
| 157 |
) |
| 158 |
|
| 159 |
# K.3) Set up install component dependencies |
| 160 |
|
| 161 |
tribits_get_sublist_enabled( |
| 162 |
${PROJECT_NAME}_DEFINED_INTERNAL_TOPLEVEL_PACKAGES |
| 163 |
enabledInternalToplevelPackages "") |
| 164 |
|
| 165 |
foreach(pkgName ${enabledInternalToplevelPackages}) |
| 166 |
if(NOT "${${pkgName}_LIB_ENABLED_DEPENDENCIES}" STREQUAL "") |
| 167 |
string(TOUPPER ${pkgName} upperPkgName) |
| 168 |
set(CPACK_COMPONENT_${upperPkgName}_DEPENDS ${${pkgName}_LIB_ENABLED_DEPENDENCIES}) |
| 169 |
# ToDo: The above needs to be changed to the list of *internal* enabled |
| 170 |
# package dependencies! (But there are no tests for this currently and |
| 171 |
# I am not sure who is using this.) |
| 172 |
endif() |
| 173 |
endforeach() |
| 174 |
|
| 175 |
# K.4) Resetting the name to avoid overwriting registry keys when installing |
| 176 |
|
| 177 |
if(WIN32) |
| 178 |
set(CPACK_PACKAGE_NAME "${CPACK_PACKAGE_NAME}-${${PROJECT_NAME}_VERSION}") |
| 179 |
if (TPL_ENABLE_MPI) |
| 180 |
set(CPACK_PACKAGE_NAME "${CPACK_PACKAGE_NAME}-mpi") |
| 181 |
ELSE () |
| 182 |
set(CPACK_PACKAGE_NAME "${CPACK_PACKAGE_NAME}-serial") |
| 183 |
endif() |
| 184 |
set(CPACK_GENERATOR "NSIS") |
| 185 |
set(CPACK_NSIS_MODIFY_PATH OFF) |
| 186 |
endif() |
| 187 |
|
| 188 |
# K.5) Determine the source generator |
| 189 |
if ("${${PROJECT_NAME}_CPACK_SOURCE_GENERATOR_DEFAULT}" STREQUAL "") |
| 190 |
set(${PROJECT_NAME}_CPACK_SOURCE_GENERATOR_DEFAULT "TGZ") |
| 191 |
endif() |
| 192 |
set(${PROJECT_NAME}_CPACK_SOURCE_GENERATOR |
| 193 |
${${PROJECT_NAME}_CPACK_SOURCE_GENERATOR_DEFAULT} |
| 194 |
CACHE STRING |
| 195 |
"The types of source generators to use for CPACK_SOURCE_GENERATOR.") |
| 196 |
set(CPACK_SOURCE_GENERATOR ${${PROJECT_NAME}_CPACK_SOURCE_GENERATOR}) |
| 197 |
|
| 198 |
# K.6) Loop through the Repositories and run their callback functions. |
| 199 |
foreach(REPO ${${PROJECT_NAME}_ALL_REPOSITORIES}) |
| 200 |
tribits_get_repo_name_dir(${REPO} REPO_NAME REPO_DIR) |
| 201 |
if (${PROJECT_NAME}_VERBOSE_CONFIGURE) |
| 202 |
message("Processing packaging call-backs for ${REPO_NAME}") |
| 203 |
endif() |
| 204 |
tribits_repository_define_packaging_runner(${REPO_NAME}) |
| 205 |
endforeach() |
| 206 |
|
| 207 |
# K.7) Include <Project>RepoVersion.txt if generated |
| 208 |
set(PROJECT_REPO_VERSION_FILE |
| 209 |
"${CMAKE_CURRENT_BINARY_DIR}/${${PROJECT_NAME}_REPO_VERSION_FILE_NAME}") |
| 210 |
if (EXISTS "${PROJECT_REPO_VERSION_FILE}") |
| 211 |
foreach(SOURCE_GEN ${CPACK_SOURCE_GENERATOR}) |
| 212 |
set(CPACK_INSTALL_COMMANDS ${CPACK_INSTALL_COMMANDS} |
| 213 |
"${CMAKE_COMMAND} -E copy '${PROJECT_REPO_VERSION_FILE}' '${CMAKE_CURRENT_BINARY_DIR}/_CPack_Packages/Linux-Source/${SOURCE_GEN}/${CPACK_PACKAGE_NAME}-${${PROJECT_NAME}_VERSION}-Source/${${PROJECT_NAME}_REPO_VERSION_FILE_NAME}'") |
| 214 |
endforeach() |
| 215 |
endif() |
| 216 |
|
| 217 |
# Print the set of excluded files |
| 218 |
if(${PROJECT_NAME}_VERBOSE_CONFIGURE OR |
| 219 |
${PROJECT_NAME}_DUMP_CPACK_SOURCE_IGNORE_FILES |
| 220 |
) |
| 221 |
message("Exclude files when building source packages:") |
| 222 |
foreach(item IN LISTS CPACK_SOURCE_IGNORE_FILES) |
| 223 |
message(${item}) |
| 224 |
endforeach() |
| 225 |
endif() |
| 226 |
|
| 227 |
# K.8) Finally process with CPack |
| 228 |
include(CPack) |
| 229 |
|
| 230 |
tribits_config_code_stop_timer(CPACK_SETUP_TIME_START_SECONDS |
| 231 |
"Total time to set up for CPack packaging") |
| 232 |
|
| 233 |
endmacro() |
| 234 |
|
| 235 |
|
| 236 |
macro(tribits_project_define_packaging_runner) |
| 237 |
set(CALLBACK_DEFINE_PACKAGING_FILE |
| 238 |
"${PROJECT_SOURCE_DIR}/cmake/CallbackDefineProjectPackaging.cmake") |
| 239 |
#print_var(CALLBACK_DEFINE_PACKAGING_FILE) |
| 240 |
if (EXISTS ${CALLBACK_DEFINE_PACKAGING_FILE}) |
| 241 |
if (${PROJECT_NAME}_VERBOSE_CONFIGURE) |
| 242 |
message("Processing call-back file and macros in" |
| 243 |
" '${CALLBACK_DEFINE_PACKAGING_FILE}'") |
| 244 |
endif() |
| 245 |
# Define the callback macros as empty in case it is not defined |
| 246 |
# in this file. |
| 247 |
create_empty_tribits_project_define_packaging() |
| 248 |
# Include the file which will define the callback macros |
| 249 |
tribits_trace_file_processing(PROJECT INCLUDE |
| 250 |
"${CALLBACK_DEFINE_PACKAGING_FILE}") |
| 251 |
include(${CALLBACK_DEFINE_PACKAGING_FILE}) |
| 252 |
# Call the callback macros to inject project-specific behavir |
| 253 |
tribits_project_define_packaging() |
| 254 |
# Set back the callback macros to empty to ensure that no-one calls them |
| 255 |
create_empty_tribits_project_define_packaging() |
| 256 |
endif() |
| 257 |
endmacro() |
| 258 |
|
| 259 |
|
| 260 |
macro(create_empty_tribits_repository_setup_extra_options) |
| 261 |
macro(tribits_repository_setup_extra_options) |
| 262 |
endmacro() |
| 263 |
endmacro() |
| 264 |
|
| 265 |
|
| 266 |
macro(tribits_repository_setup_extra_options_runner REPO_NAME) |
| 267 |
set(CALLBACK_SETUP_EXTRA_OPTIONS_FILE |
| 268 |
"${${REPO_NAME}_SOURCE_DIR}/cmake/CallbackSetupExtraOptions.cmake") |
| 269 |
#print_var(CALLBACK_SETUP_EXTRA_OPTIONS_FILE) |
| 270 |
if (EXISTS ${CALLBACK_SETUP_EXTRA_OPTIONS_FILE}) |
| 271 |
if (${PROJECT_NAME}_VERBOSE_CONFIGURE) |
| 272 |
message("Processing call-back file and macros in" |
| 273 |
" '${CALLBACK_SETUP_EXTRA_OPTIONS_FILE}'") |
| 274 |
endif() |
| 275 |
# Define the callback macros as empty in case it is not defined |
| 276 |
# in this file. |
| 277 |
create_empty_tribits_repository_setup_extra_options() |
| 278 |
# Include the file which will define the callback macros |
| 279 |
set(REPOSITORY_NAME ${REPO_NAME}) |
| 280 |
tribits_trace_file_processing(REPOSITORY INCLUDE |
| 281 |
"${CALLBACK_SETUP_EXTRA_OPTIONS_FILE}") |
| 282 |
include(${CALLBACK_SETUP_EXTRA_OPTIONS_FILE}) |
| 283 |
# Call the callback macros to inject repository-specific behavir |
| 284 |
tribits_repository_setup_extra_options() |
| 285 |
# Set back the callback macros to empty to ensure that nonone calls them |
| 286 |
create_empty_tribits_repository_setup_extra_options() |
| 287 |
endif() |
| 288 |
endmacro() |
| 289 |
|
| 290 |
|
| 291 |
macro(create_empty_tribits_repository_define_packaging) |
| 292 |
macro(tribits_repository_define_packaging) |
| 293 |
endmacro() |
| 294 |
endmacro() |
| 295 |
|
| 296 |
|
| 297 |
macro(tribits_repository_define_packaging_runner REPO_NAME) |
| 298 |
set(CALLBACK_DEFINE_PACKAGING_FILE |
| 299 |
"${${REPO_NAME}_SOURCE_DIR}/cmake/CallbackDefineRepositoryPackaging.cmake") |
| 300 |
#print_var(CALLBACK_DEFINE_PACKAGING_FILE) |
| 301 |
if (EXISTS ${CALLBACK_DEFINE_PACKAGING_FILE}) |
| 302 |
if (${PROJECT_NAME}_VERBOSE_CONFIGURE) |
| 303 |
message("Processing call-back file and macros in" |
| 304 |
" '${CALLBACK_DEFINE_PACKAGING_FILE}'") |
| 305 |
endif() |
| 306 |
# Define the callback macros as empty in case it is not defined |
| 307 |
# in this file. |
| 308 |
create_empty_tribits_repository_define_packaging() |
| 309 |
# Include the file which will define the callback macros |
| 310 |
tribits_trace_file_processing(REPOSITORY INCLUDE |
| 311 |
"${CALLBACK_DEFINE_PACKAGING_FILE}") |
| 312 |
include(${CALLBACK_DEFINE_PACKAGING_FILE}) |
| 313 |
# Call the callback macros to inject repository-specific behavir |
| 314 |
tribits_repository_define_packaging() |
| 315 |
# Set back the callback macros to empty to ensure that nonone calls them |
| 316 |
create_empty_tribits_repository_define_packaging() |
| 317 |
endif() |
| 318 |
endmacro() |
| 319 |
|
| 320 |
|
| 321 |
macro(create_empty_tribits_project_define_packaging) |
| 322 |
macro(tribits_project_define_packaging) |
| 323 |
endmacro() |
| 324 |
endmacro() |