Debian Codegraph @

cmake/tribits/core/package_arch/TribitsProcessPackagesAndDirsLists.cmake

raw
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 include(SetCacheOnOffEmpty)
12 include(MultilineSet)
13 include(AdvancedOption)
14 include(AdvancedSet)
15 include(AssertDefined)
16 include(PrintVar)
17 include(MessageWrapper)
18 include(TribitsListHelpers)
19
20
21 #
22 # Helper functions
23 #
24
25
26 # @MACRO: tribits_repository_define_packages()
27 #
28 # Define the set of packages for a given `TriBITS Repository`_. This macro is
29 # typically called from inside of a `<repoDir>/PackagesList.cmake`_ file for a
30 # given TriBITS repo.
31 #
32 # Usage::
33 #
34 # tribits_repository_define_packages(
35 # <pkg0> <pkg0_dir> <pkg0_classif>
36 # <pkg1> <pkg1_dir> <pkg1_classif>
37 # ...
38 # )
39 #
40 # This macro sets up a 2D array of ``NumPackages`` by ``NumColumns`` listing
41 # out the packages for a TriBITS repository. Each row (with 3 column entries)
42 # specifies a package which contains the columns (ordered 0-2):
43 #
44 # 0. **PACKAGE** (``<pkgi>``): The name of the TriBITS package. This name
45 # must be unique across all other TriBITS packages in this or any other
46 # TriBITS repo that might be combined into a single TriBITS project
47 # meta-build (see `Globally unique TriBITS package names`_). The name
48 # should be a valid identifier (e.g. matches the regex
49 # ``[a-zA-Z_][a-zA-Z0-9_]*``). The package names tend to use mixed case
50 # (e.g. ```SomePackge`` not ``SOMEPACKGE``).
51 #
52 # 1. **DIR** (``<pkgi_dir>``): The relative directory for the package
53 # ``<packageDir>``. This directory is relative to the TriBITS repository
54 # base directory ``<repoDir>``. Under this directory will be a
55 # package-specific ``cmake/`` directory with the file
56 # `<packageDir>/cmake/Dependencies.cmake`_ and a base-level
57 # `<packageDir>/CMakeLists.txt`_ file. The entire contents of the package
58 # including all of the source code and all of the tests should be contained
59 # under this directory. The TriBITS testing infrastructure relies on the
60 # mapping of changed files to these base directories when deciding what
61 # packages are modified and need to be retested (along with downstream
62 # packages). For details, see `checkin-test.py`_.
63 #
64 # 2. **CLASSIFICATION** (``<pkgi_classif>``): Gives the `Package Test
65 # Group`_ `PT`_, `ST`_, or `EX`_ and the maturity level ``EP``, ``RS``,
66 # ``PG``, ``PM``, ``GRS``, ``GPG``, ``GPM``, ``UM``. These are separated
67 # by a coma with no space in between such as ``"RS,PT"`` for a "Research
68 # Stable", "Primary Tested" package. No spaces are allowed so that CMake
69 # treats this a one field in the array. The maturity level can be left off
70 # in which case it is assumed to be ``UM`` for "Unspecified Maturity".
71 # This classification for individual packages can be changed to ``EX`` for
72 # specific platforms by calling `tribits_disable_package_on_platforms()`_.
73 #
74 # **IMPORTANT:** The packages must be listed in increasing order of package
75 # dependencies. That is `No circular dependencies of any kind are allowed`_
76 # (see the *ADP (Acyclic Dependencies Principle)* in `Software Engineering
77 # Packaging Principles`_). Package ``i`` can only list dependencies (in
78 # `<packageDir>/cmake/Dependencies.cmake`_) for packages listed before this
79 # package in this list (or in upstream TriBITS repositories). This avoids an
80 # expensive package sorting algorithm and makes it easy to flag packages with
81 # circular dependencies or misspelling of package names.
82 #
83 # NOTE: For some rare use cases, the package directory ``<pkgi_dir>`` is
84 # allowed to be specified as an absolute directory but this absolute directory
85 # must be a subdirectory of the project source base directory given by
86 # `PROJECT_SOURCE_DIR`_. If not, ``message(FATAL_ERROR ...)`` is called and
87 # processing stops immediately.
88 #
89 # NOTE: This macro just sets the variable::
90 #
91 # ${REPOSITORY_NAME}_PACKAGES_AND_DIRS_AND_CLASSIFICATIONS
92 #
93 # in the current scope. The advantages of using this macro instead of
94 # directly setting this variable are that the macro:
95 #
96 # * Asserts that the variable ``REPOSITORY_NAME`` is defined and set
97 #
98 # * Avoids having to hard-code the assumed repository name
99 # ``${REPOSITORY_NAME}``. This provides more flexibility for how other
100 # TriBITS projects choose to name a given TriBITS repo (i.e. the name of
101 # repo subdirs).
102 #
103 # * Avoid misspelling the name of the variable
104 # ``${REPOSITORY_NAME}_PACKAGES_AND_DIRS_AND_CLASSIFICATIONS``. If one
105 # misspells the name of the macro, it is an immediate error in CMake.
106 #
107 macro(tribits_repository_define_packages)
108 assert_defined(REPOSITORY_NAME)
109 set(${REPOSITORY_NAME}_PACKAGES_AND_DIRS_AND_CLASSIFICATIONS "${ARGN}")
110 endmacro()
111
112
113 # @FUNCTION: tribits_allow_missing_external_packages()
114 #
115 # Allow listed packages to be missing and automatically excluded from the
116 # package dependency data-structures.
117 #
118 # Usage::
119 #
120 # tribits_allow_missing_external_packages(<pkg0> <plg1> ...)
121 #
122 # If the missing upstream package ``<pkgi>`` is optional, then the effect
123 # will be to simply ignore the missing package (i.e. it will never be added to
124 # package's list and not added to dependency data-structures) and remove it
125 # from the dependency lists for downstream packages that have an optional
126 # dependency on the missing upstream package ``<pkgi>``. However, all
127 # downstream packages that have a required dependency on the missing
128 # upstream package ``<pkgi>`` will be hard disabled,
129 # i.e. ``${PROJECT_NAME}_ENABLE_{CURRENT_PACKAGE}=OFF`` and a note on the
130 # disable will be printed.
131 #
132 # **WARNING**: This macro just sets the cache variable
133 # ``<pkgi>_ALLOW_MISSING_EXTERNAL_PACKAGE=TRUE`` for each package
134 # ``<pkgi>``. Therefore, using this function effectively turns off error
135 # checking for misspelled package names so it is important to only use it when
136 # it absolutely is needed (use cases mentioned below). Also note that missing
137 # packages are silently ignored by default. Therefore, when doing development
138 # involving these packages, it is usually a good idea to set::
139 #
140 # -D<pkgi>_ALLOW_MISSING_EXTERNAL_PACKAGE=FALSE
141 #
142 # so that it will catch errors in the misspelling of package names or source
143 # directories. However, notes on what missing packages are being ignored can
144 # printed by configuring with::
145 #
146 # -D <Project>_WARN_ABOUT_MISSING_EXTERNAL_PACKAGES=TRUE
147 #
148 # This macro is typically called in one of two different contexts:
149 #
150 # * Called from `<packageDir>/cmake/Dependencies.cmake`_ when the upstream
151 # package ``<pkgi>`` is defined in an optional upstream `TriBITS
152 # Repository`_. This allows the downstream repos and packages to still be
153 # enabled (assuming they don't have required dependencies on the missing
154 # packages) when one or more upstream repos are missing.
155 #
156 # * Called from `<repoDir>/PackagesList.cmake`_ when the package ``<pkgi>``
157 # might be defined in an optional non-TriBITS repo (see `How to insert a
158 # package into an upstream repo`_).
159 #
160 # For some meta-projects that composes packages from may different TriBITS
161 # repositories, one might need to also call this function from the file
162 # `<projectDir>/cmake/ProjectDependenciesSetup.cmake`_.
163 #
164 function(tribits_allow_missing_external_packages)
165 foreach(TRIBITS_PACKAGE ${ARGN})
166 advanced_set(${TRIBITS_PACKAGE}_ALLOW_MISSING_EXTERNAL_PACKAGE TRUE
167 CACHE BOOL
168 "Default set by tribits_allow_missing_external_packages()!"
169 )
170 endforeach()
171 endfunction()
172
173
174 #
175 # Below, we change the value of user cache values like
176 # ${PROJECT_NAME}_ENABLE_${PACKAGE_NAME},
177 # ${PACKAGE_NAME}_ENABLE_TESTS, and ${PACKAGE_NAME}_ENABLE_EXAMPLES by
178 # just setting them to regular variables that live in the top scope
179 # instead of putting them back in the cache. That means that they are
180 # used as global variables but we don't want to disturb the cache
181 # since that would change the behavior for future invocations of cmake
182 # (which is very confusing). Because of this, these macros must all
183 # be called from the top-level ${PROJECT_NAME} CMakeLists.txt file and
184 # macros must call macros as not to change the variable scope.
185 #
186 # I had to do it this way in order to be able to get the right behavior which
187 # is:
188 #
189 # 1) Override the value of these variables in all CMake processing
190 #
191 # 2) Avoid changing the user cache values because that would be confusing and
192 # would make it hard to change package enables/disable later without blowing
193 # away the cache
194 #
195
196
197 # Macro that sets up standard user options a package
198 #
199 # On completion, the following variables are set:
200 #
201 # * ${PACKAGE_NAME_IN}_TESTGROUP: Set to PT, ST, or EX
202 #
203 macro(tribits_insert_standard_package_options PACKAGE_NAME_IN PACKAGE_TESTGROUP_IN)
204
205 if (TRIBITS_INSERT_STANDARD_PACKAGE_OPTIONS_DEBUG)
206 message("TRIBITS_INSERT_STANDARD_PACKAGE_OPTIONS: ${PACKAGE_NAME_IN} ${PACKAGE_TESTGROUP_IN}")
207 print_var(${PACKAGE_NAME_IN}_TESTGROUP)
208 endif()
209
210 set(PACKAGE_TESTGROUP_LOCAL ${PACKAGE_TESTGROUP_IN})
211
212 # ${PROJECT_NAME}_ELEVATE_ST_TO_PT is deprecated but allowed for backward compatibility
213 if (${PROJECT_NAME}_ELEVATE_SS_TO_PS)
214 set(${PROJECT_NAME}_ELEVATE_ST_TO_PT ON)
215 endif()
216
217 if (${PACKAGE_TESTGROUP_IN} STREQUAL PT OR ${PACKAGE_TESTGROUP_IN} STREQUAL ST)
218 if (TRIBITS_INSERT_STANDARD_PACKAGE_OPTIONS_DEBUG)
219 message("-- " "PT or ST")
220 print_var(${PROJECT_NAME}_ELEVATE_ST_TO_PT)
221 endif()
222 if (${PROJECT_NAME}_ELEVATE_ST_TO_PT)
223 set(PACKAGE_TESTGROUP_LOCAL PT)
224 endif()
225 if (TRIBITS_INSERT_STANDARD_PACKAGE_OPTIONS_DEBUG)
226 print_var(PACKAGE_TESTGROUP_LOCAL)
227 endif()
228 set(PACKAGE_ENABLE "")
229 elseif (${PACKAGE_TESTGROUP_IN} STREQUAL EX)
230 if (TRIBITS_INSERT_STANDARD_PACKAGE_OPTIONS_DEBUG)
231 message("-- " "EX")
232 endif()
233 set(PACKAGE_ENABLE OFF)
234 else()
235 message(FATAL_ERROR "Error the package classification '${PACKAGE_TESTGROUP_IN}'"
236 " for the package ${PACKAGE_NAME_IN} is not a valid classification." )
237 endif()
238
239 if (TRIBITS_INSERT_STANDARD_PACKAGE_OPTIONS_DEBUG)
240 print_var(PACKAGE_ENABLE)
241 print_var(${PACKAGE_NAME_IN}_TESTGROUP)
242 endif()
243
244 if ("${${PACKAGE_NAME_IN}_TESTGROUP}" STREQUAL "") # Allow testing override
245 if (TRIBITS_INSERT_STANDARD_PACKAGE_OPTIONS_DEBUG)
246 message("-- " "Setting classification to ${PACKAGE_TESTGROUP_LOCAL}")
247 print_var(PACKAGE_TESTGROUP_LOCAL)
248 endif()
249 set(${PACKAGE_NAME_IN}_TESTGROUP "${PACKAGE_TESTGROUP_LOCAL}")
250 endif()
251
252 if (TRIBITS_INSERT_STANDARD_PACKAGE_OPTIONS_DEBUG)
253 print_var(${PACKAGE_NAME_IN}_TESTGROUP)
254 endif()
255
256 multiline_set(DOCSTR
257 "Enable the package ${PACKAGE_NAME_IN}. Set to 'ON', 'OFF', or leave"
258 " empty to allow for other logic to decide."
259 )
260 set_cache_on_off_empty( ${PROJECT_NAME}_ENABLE_${PACKAGE_NAME_IN}
261 "${PACKAGE_ENABLE}" ${DOCSTR} )
262
263 endmacro()
264
265
266 # Function that determines if a package is a primary meta-project package
267 # according to the variables
268 # ${PARENT_REPO_NAME}_NO_PRIMARY_META_PROJECT_PACKAGES[_EXCEPT].
269 #
270 function(tribits_is_primary_meta_project_package PACKAGE_NAME_IN
271 IS_PRIMARY_META_PROJECT_PACKAGE_OUT
272 )
273
274 set(IS_PRIMARY_META_PROJECT_PACKAGE TRUE)
275
276 assert_defined(${PACKAGE_NAME_IN}_PARENT_REPOSITORY)
277 set(PARENT_REPO_NAME ${${PACKAGE_NAME_IN}_PARENT_REPOSITORY})
278 if (${PARENT_REPO_NAME}_NO_PRIMARY_META_PROJECT_PACKAGES)
279 find_list_element(
280 ${PARENT_REPO_NAME}_NO_PRIMARY_META_PROJECT_PACKAGES_EXCEPT
281 ${PACKAGE_NAME_IN} PACKAGE_EXCEPTED
282 )
283 if (PACKAGE_EXCEPTED)
284 if (${PROJECT_NAME}_VERBOSE_CONFIGURE)
285 message("-- "
286 "NOTE: ${PACKAGE_NAME_IN} is classified as a primary meta-project packages even"
287 " though ${PARENT_REPO_NAME}_NO_PRIMARY_META_PROJECT_PACKAGES=ON "
288 " because the package is included in the list ${PARENT_REPO_NAME}_NO_PRIMARY_META_PROJECT_PACKAGES_EXCEPT!")
289 endif()
290 else()
291 if (${PROJECT_NAME}_VERBOSE_CONFIGURE)
292 message("-- "
293 "NOTE: ${PACKAGE_NAME_IN} is not as a primary meta-project packages"
294 " because ${PARENT_REPO_NAME}_NO_PRIMARY_META_PROJECT_PACKAGES=ON "
295 )
296 endif()
297 set(IS_PRIMARY_META_PROJECT_PACKAGE FALSE)
298 endif()
299 endif()
300
301 set(${IS_PRIMARY_META_PROJECT_PACKAGE_OUT} ${IS_PRIMARY_META_PROJECT_PACKAGE}
302 PARENT_SCOPE )
303
304 endfunction()
305
306
307 # Function that determines if it is okay to allow an implicit enable of an
308 # upstream package given the disable of a downstream package that depends on
309 # it.
310 #
311 function(tribits_implicit_package_enable_is_allowed upstreamPackageName
312 packageName implictPackageEnableAllowedOut
313 )
314
315 if (${packageName}_PACKAGE_BUILD_STATUS STREQUAL "EXTERNAL")
316 set(implicitPackageEnableAllowed FALSE)
317 elseif (${packageName}_TESTGROUP STREQUAL "PT")
318 set(implicitPackageEnableAllowed TRUE)
319 elseif (${packageName}_TESTGROUP STREQUAL "ST"
320 AND ${PROJECT_NAME}_ENABLE_SECONDARY_TESTED_CODE
321 )
322 set(implicitPackageEnableAllowed TRUE)
323 else()
324 if (upstreamPackageName)
325 message("-- " "NOTE: Not Setting ${PROJECT_NAME}_ENABLE_${packageName}=ON"
326 " even though ${upstreamPackageName} has an optional dependence on"
327 " ${packageName} because ${PROJECT_NAME}_ENABLE_SECONDARY_TESTED_CODE=OFF" )
328 endif()
329 set(implicitPackageEnableAllowed FALSE)
330 endif()
331
332 set(${implictPackageEnableAllowedOut} "${implicitPackageEnableAllowed}"
333 PARENT_SCOPE )
334
335 endfunction()
336
337
338 # @MACRO: tribits_process_packages_and_dirs_lists()
339 #
340 # Usage::
341 #
342 # tribits_process_packages_and_dirs_lists()
343 #
344 # Macro that processes the list variable::
345 #
346 # ${REPOSITORY_NAME}_PACKAGES_AND_DIRS_AND_CLASSIFICATIONS
347 #
348 # from a `<repoDir>/PackagesList.cmake`_ file that just got read in and
349 # creates/updates the top-level non-cache variables:
350 #
351 # * `${PROJECT_NAME}_DEFINED_INTERNAL_TOPLEVEL_PACKAGES`_
352 # * `${PROJECT_NAME}_NUM_DEFINED_INTERNAL_TOPLEVEL_PACKAGES`_
353 # * ``${PROJECT_NAME}_LAST_DEFINED_INTERNAL_TOPLEVEL_PACKAGE_IDX``
354 #
355 # For each of the listed top-level (parent) packages ${PACKAGE_NAME}, it also
356 # sets up constant variables defined in `TriBITS Package Top-Level Local
357 # Variables`_ like:
358 #
359 # * `${PACKAGE_NAME}_SOURCE_DIR`_
360 # * `${PACKAGE_NAME}_REL_SOURCE_DIR`_
361 # * `${PACKAGE_NAME}_PARENT_PACKAGE`_ (to empty "")
362 # * `${PACKAGE_NAME}_PARENT_REPOSITORY`_ (to empty "")
363 # * `${PACKAGE_NAME}_TESTGROUP`_
364 # * `${PACKAGE_NAME}_PACKAGE_BUILD_STATUS`_ (to ``INTERNAL``)
365 #
366 # and sets up some standard enable/disable vars with default values as defined
367 # in `TriBITS Package Cache Variables`_ like:
368 #
369 # * `${PROJECT_NAME}_ENABLE_${PACKAGE_NAME}`_
370 #
371 # NOTE: Set ``TRIBITS_PROCESS_PACKAGES_AND_DIRS_LISTS_VERBOSE=TRUE`` to see
372 # really verbose debug output from this macro.
373 #
374 # See `Function call tree for constructing package dependency graph`_.
375 #
376 macro(tribits_process_packages_and_dirs_lists REPOSITORY_NAME REPOSITORY_DIR)
377
378 if (${PROJECT_NAME}_VERBOSE_CONFIGURE)
379 message("TRIBITS_PROCESS_PACKAGES_AND_DIRS_LISTS: '${REPOSITORY_NAME}' '${REPOSITORY_DIR}'")
380 endif()
381
382 #
383 # Separate out separate lists of package names and directories
384 #
385
386 # Get the total number of packages defined
387
388 assert_defined(${REPOSITORY_NAME}_PACKAGES_AND_DIRS_AND_CLASSIFICATIONS)
389 if (TRIBITS_PROCESS_PACKAGES_AND_DIRS_LISTS_VERBOSE)
390 print_var(${REPOSITORY_NAME}_PACKAGES_AND_DIRS_AND_CLASSIFICATIONS)
391 endif()
392 list(LENGTH ${REPOSITORY_NAME}_PACKAGES_AND_DIRS_AND_CLASSIFICATIONS
393 ${REPOSITORY_NAME}_NUM_PACKAGES_AND_FIELDS )
394 math(EXPR ${REPOSITORY_NAME}_NUM_DEFINED_INTERNAL_TOPLEVEL_PACKAGES
395 "${${REPOSITORY_NAME}_NUM_PACKAGES_AND_FIELDS}/${PLH_NUM_FIELDS_PER_PACKAGE}")
396 if (TRIBITS_PROCESS_PACKAGES_AND_DIRS_LISTS_VERBOSE)
397 print_var(${REPOSITORY_NAME}_NUM_DEFINED_INTERNAL_TOPLEVEL_PACKAGES)
398 endif()
399 math(EXPR ${REPOSITORY_NAME}_LAST_DEFINED_INTERNAL_TOPLEVEL_PACKAGE_IDX
400 "${${REPOSITORY_NAME}_NUM_DEFINED_INTERNAL_TOPLEVEL_PACKAGES}-1")
401
402 # Process each of the packages defined
403
404 if (${REPOSITORY_NAME}_NUM_DEFINED_INTERNAL_TOPLEVEL_PACKAGES GREATER 0)
405
406 foreach(PACKAGE_IDX RANGE
407 ${${REPOSITORY_NAME}_LAST_DEFINED_INTERNAL_TOPLEVEL_PACKAGE_IDX}
408 )
409
410 if (TRIBITS_PROCESS_PACKAGES_AND_DIRS_LISTS_VERBOSE)
411 message("")
412 print_var(${PROJECT_NAME}_DEFINED_INTERNAL_TOPLEVEL_PACKAGES)
413 endif()
414
415 math(EXPR PACKAGE_NAME_IDX "${PACKAGE_IDX}*${PLH_NUM_FIELDS_PER_PACKAGE}+0")
416 list(GET ${REPOSITORY_NAME}_PACKAGES_AND_DIRS_AND_CLASSIFICATIONS
417 ${PACKAGE_NAME_IDX} TRIBITS_PACKAGE )
418 if (TRIBITS_PROCESS_PACKAGES_AND_DIRS_LISTS_VERBOSE)
419 print_var(TRIBITS_PACKAGE)
420 endif()
421
422 math(EXPR PACKAGE_DIR_IDX
423 "${PACKAGE_IDX}*${PLH_NUM_FIELDS_PER_PACKAGE}+${PLH_NUM_PACKAGE_DIR_OFFSET}")
424 list(GET ${REPOSITORY_NAME}_PACKAGES_AND_DIRS_AND_CLASSIFICATIONS
425 ${PACKAGE_DIR_IDX} PACKAGE_DIR )
426 if (TRIBITS_PROCESS_PACKAGES_AND_DIRS_LISTS_VERBOSE)
427 print_var(PACKAGE_DIR)
428 endif()
429
430 math(EXPR PACKAGE_CLASSIFICATION_IDX
431 "${PACKAGE_IDX}*${PLH_NUM_FIELDS_PER_PACKAGE}+${PLH_NUM_PACKAGE_CLASSIFICATION_OFFSET}")
432 list(GET ${REPOSITORY_NAME}_PACKAGES_AND_DIRS_AND_CLASSIFICATIONS
433 ${PACKAGE_CLASSIFICATION_IDX} PACKAGE_CLASSIFICATION )
434 if (TRIBITS_PROCESS_PACKAGES_AND_DIRS_LISTS_VERBOSE)
435 print_var(PACKAGE_CLASSIFICATION)
436 endif()
437
438 # ToDo: Parse out TESTGROUP and MATURITYLEVEL (Trilinos #6042)
439 set(PACKAGE_TESTGROUP ${PACKAGE_CLASSIFICATION})
440
441 tribits_update_ps_pt_ss_st(Package ${TRIBITS_PACKAGE} PACKAGE_TESTGROUP)
442
443 if (${TRIBITS_PACKAGE}_SOURCE_DIR_OVERRIDE)
444 message("-- "
445 "NOTE: ${TRIBITS_PACKAGE}_SOURCE_DIR_OVERRIDE='${${TRIBITS_PACKAGE}_SOURCE_DIR_OVERRIDE}'"
446 " is overriding default path '${PACKAGE_DIR}'")
447 set(PACKAGE_DIR "${${TRIBITS_PACKAGE}_SOURCE_DIR_OVERRIDE}")
448 endif()
449
450 if (IS_ABSOLUTE "${PACKAGE_DIR}")
451
452 set(PACKAGE_ABS_DIR "${PACKAGE_DIR}")
453
454 string(LENGTH "${PROJECT_SOURCE_DIR}" PROJECT_SOURCE_DIR_LEN)
455 string(LENGTH "${PACKAGE_ABS_DIR}" PACKAGE_ABS_DIR_LEN)
456
457 # See if the package dir is under the project dir
458
459 set(PACKAGE_ABS_DIR_UNDER_PROJECT_SOURCE_DIR TRUE)
460
461 if (PACKAGE_ABS_DIR_UNDER_PROJECT_SOURCE_DIR)
462 # Determine package abs dir is too short to be under project
463 if (PACKAGE_ABS_DIR_LEN LESS PROJECT_SOURCE_DIR_LEN)
464 set(PACKAGE_ABS_DIR_UNDER_PROJECT_SOURCE_DIR FALSE)
465 endif()
466 endif()
467
468 if (PACKAGE_ABS_DIR_UNDER_PROJECT_SOURCE_DIR)
469 # Determine if the package abs base dir base is the project dir
470 string(SUBSTRING "${PACKAGE_ABS_DIR}" 0 ${PROJECT_SOURCE_DIR_LEN}
471 PROJECT_SOURCE_DIR_BASE_MATCH)
472 print_var(PROJECT_SOURCE_DIR_BASE_MATCH)
473 if (NOT PROJECT_SOURCE_DIR_BASE_MATCH STREQUAL "${PROJECT_SOURCE_DIR}")
474 set(PACKAGE_ABS_DIR_UNDER_PROJECT_SOURCE_DIR FALSE)
475 endif()
476 endif()
477
478 if (PACKAGE_ABS_DIR_UNDER_PROJECT_SOURCE_DIR)
479 # Get the path of the package dir under the project dir
480 math(EXPR PACKAGE_REL_DIR_BEGIN "${PROJECT_SOURCE_DIR_LEN}+1")
481 string(SUBSTRING "${PACKAGE_ABS_DIR}" ${PACKAGE_REL_DIR_BEGIN} -1
482 REPOSITORY_AND_PACKAGE_DIR)
483 else()
484 message_wrapper(FATAL_ERROR
485 "Error: The package '${TRIBITS_PACKAGE}' was given an absolute directory '${PACKAGE_ABS_DIR}' which is *not* under the project's source directory '${PROJECT_SOURCE_DIR}/'!")
486 set(REPOSITORY_AND_PACKAGE_DIR "ERROR-BAD-PACKAGE-ABS-DIR")
487 # ToDo: We could just put in a relative path but that requires
488 # knowing the common path between the two directory paths but CMake
489 # does not give an easy way to determine that. I would have to
490 # write that function myself.
491 endif()
492
493 else()
494
495 # PACKAGE_DIR is a relative path
496
497 if ("${REPOSITORY_DIR}" STREQUAL ".")
498 set(REPOSITORY_AND_PACKAGE_DIR "${PACKAGE_DIR}")
499 elseif("${PACKAGE_DIR}" STREQUAL ".")
500 set(REPOSITORY_AND_PACKAGE_DIR "${REPOSITORY_DIR}")
501 else()
502 set(REPOSITORY_AND_PACKAGE_DIR "${REPOSITORY_DIR}/${PACKAGE_DIR}")
503 endif()
504 set(PACKAGE_ABS_DIR "${PROJECT_SOURCE_DIR}/${REPOSITORY_AND_PACKAGE_DIR}")
505
506 endif()
507
508 set(packageDependenciesFile "${PACKAGE_ABS_DIR}/cmake/Dependencies.cmake")
509 if (EXISTS "${packageDependenciesFile}")
510 set(PACKAGE_EXISTS TRUE)
511 else()
512 set(PACKAGE_EXISTS FALSE)
513 endif()
514
515 if (TRIBITS_PROCESS_PACKAGES_AND_DIRS_LISTS_VERBOSE)
516 print_var(PROJECT_SOURCE_DIR)
517 print_var(REPOSITORY_AND_PACKAGE_DIR)
518 print_var(PACKAGE_ABS_DIR)
519 print_var(PACKAGE_EXISTS)
520 print_var(${PROJECT_NAME}_ASSERT_DEFINED_DEPENDENCIES)
521 print_var(${TRIBITS_PACKAGE}_ALLOW_MISSING_EXTERNAL_PACKAGE)
522 endif()
523
524 if (${PROJECT_NAME}_ASSERT_DEFINED_DEPENDENCIES IN_LIST
525 ${PROJECT_NAME}_ASSERT_DEFINED_DEPENDENCIES_ERROR_VALUES_LIST
526 AND NOT PACKAGE_EXISTS
527 AND NOT ${TRIBITS_PACKAGE}_ALLOW_MISSING_EXTERNAL_PACKAGE
528 )
529 message(
530 "\n***"
531 "\n*** Error, the package ${TRIBITS_PACKAGE} dependencies file"
532 " '${packageDependenciesFile}' does *NOT* exist!"
533 "\n***\n" )
534 message(FATAL_ERROR "Stopping due to above error!")
535 elseif((NOT PACKAGE_EXISTS) AND (EXISTS "${PACKAGE_ABS_DIR}")
536 AND (${PROJECT_NAME}_ASSERT_DEFINED_DEPENDENCIES STREQUAL "WARNING")
537 )
538 message(WARNING "${TRIBITS_PACKAGE}: Package base directory '${PACKAGE_ABS_DIR}'"
539 " exists but the dependencies file '${packageDependenciesFile}' does *NOT*"
540 " exist! Package is being ignored anyway!")
541 endif()
542
543 if (PACKAGE_EXISTS OR ${PROJECT_NAME}_IGNORE_PACKAGE_EXISTS_CHECK)
544 list(APPEND ${PROJECT_NAME}_DEFINED_INTERNAL_TOPLEVEL_PACKAGES ${TRIBITS_PACKAGE})
545 set(${TRIBITS_PACKAGE}_SOURCE_DIR
546 "${PROJECT_SOURCE_DIR}/${REPOSITORY_AND_PACKAGE_DIR}")
547 set(${TRIBITS_PACKAGE}_REL_SOURCE_DIR
548 "${REPOSITORY_AND_PACKAGE_DIR}")
549 set(${TRIBITS_PACKAGE}_PARENT_PACKAGE "")
550 set(${TRIBITS_PACKAGE}_PARENT_REPOSITORY ${REPOSITORY_NAME})
551 tribits_insert_standard_package_options(${TRIBITS_PACKAGE} ${PACKAGE_TESTGROUP})
552 set(${TRIBITS_PACKAGE}_PACKAGE_BUILD_STATUS INTERNAL)
553 set(${TRIBITS_PACKAGE}_IS_TRIBITS_COMPLIANT TRUE)
554 else()
555 if (${PROJECT_NAME}_VERBOSE_CONFIGURE)
556 message(
557 "\n***"
558 "\n*** NOTE: Excluding package ${TRIBITS_PACKAGE} because ${PACKAGE_ABS_DIR}"
559 " does not exist!"
560 "\n***\n" )
561 endif()
562 endif()
563 # NOTE: The variable ${PROJECT_NAME}_IGNORE_PACKAGE_EXISTS_CHECK only
564 # gets set to TRUE for some unit tests. Otherwise, in every legitimate
565 # usage of this macro it is always FALSE.
566
567 if (TRIBITS_PROCESS_PACKAGES_AND_DIRS_LISTS_VERBOSE
568 OR ${PROJECT_NAME}_VERBOSE_CONFIGURE
569 )
570 print_var(${TRIBITS_PACKAGE}_SOURCE_DIR)
571 print_var(${TRIBITS_PACKAGE}_REL_SOURCE_DIR)
572 print_var(${TRIBITS_PACKAGE}_PARENT_PACKAGE)
573 print_var(${TRIBITS_PACKAGE}_PARENT_REPOSITORY)
574 print_var(${TRIBITS_PACKAGE}_PACKAGE_BUILD_STATUS)
575 print_var(${TRIBITS_PACKAGE}_IS_TRIBITS_COMPLIANT)
576 endif()
577
578 if (TRIBITS_PROCESS_PACKAGES_AND_DIRS_LISTS_VERBOSE)
579 print_var(${PROJECT_NAME}_DEFINED_INTERNAL_TOPLEVEL_PACKAGES)
580 endif()
581
582 endforeach()
583
584 # Get the actual number of packages that actually exist
585
586 list(LENGTH ${PROJECT_NAME}_DEFINED_INTERNAL_TOPLEVEL_PACKAGES
587 ${PROJECT_NAME}_NUM_DEFINED_INTERNAL_TOPLEVEL_PACKAGES )
588 math(EXPR ${PROJECT_NAME}_LAST_DEFINED_INTERNAL_TOPLEVEL_PACKAGE_IDX
589 "${${PROJECT_NAME}_NUM_DEFINED_INTERNAL_TOPLEVEL_PACKAGES}-1")
590
591 else()
592
593 set(${REPOSITORY_NAME}_NUM_DEFINED_INTERNAL_TOPLEVEL_PACKAGES 0)
594
595 endif()
596
597 message("-- After reading above PackagesList.cmake file: "
598 "${PROJECT_NAME}_NUM_DEFINED_INTERNAL_TOPLEVEL_PACKAGES"
599 "='${${PROJECT_NAME}_NUM_DEFINED_INTERNAL_TOPLEVEL_PACKAGES}'")
600
601 # Print the final set of packages in debug mode
602
603 if (${PROJECT_NAME}_VERBOSE_CONFIGURE)
604 print_var(${PROJECT_NAME}_DEFINED_INTERNAL_TOPLEVEL_PACKAGES)
605 endif()
606
607 endmacro()