Debian Codegraph @

cmake/tribits/core/package_arch/TribitsSubPackageMacros.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 include(TribitsPackageMacros)
11 include(TribitsReportInvalidTribitsUsage)
12
13
14 # @MACRO: tribits_subpackage()
15 #
16 # Forward declare a `TriBITS Subpackage`_ called at the top of the
17 # subpackage's `<packageDir>/<spkgDir>/CMakeLists.txt`_ file.
18 #
19 # Usage::
20 #
21 # tribits_subpackage(<spkgName>)
22 #
23 # Once called, the following local variables are in scope:
24 #
25 # ``PARENT_PACKAGE_NAME``
26 #
27 # The name of the parent package.
28 #
29 # ``SUBPACKAGE_NAME``
30 #
31 # The local name of the subpackage (does not contain
32 # the parent package name).
33 #
34 # ``SUBPACKAGE_FULLNAME``
35 #
36 # The full project-level name of the subpackage (which includes the parent
37 # package name at the beginning,
38 # ``${PARENT_PACKAGE_NAME}${SUBPACKAGE_NAME}``).
39 #
40 # ``PACKAGE_NAME``
41 #
42 # Inside the subpackage, the same as ``SUBPACKAGE_FULLNAME``.
43 #
44 macro(tribits_subpackage SUBPACKAGE_NAME_IN)
45
46 if (${PROJECT_NAME}_VERBOSE_CONFIGURE)
47 message("\nSUBPACKAGE: ${SUBPACKAGE_NAME_IN}")
48 endif()
49
50 tribits_subpackage_assert_call_context()
51
52 # To provide context for various macros
53 set(PACKAGE_NAME ${SUBPACKAGE_FULLNAME})
54
55 set(PARENT_PACKAGE_SOURCE_DIR "${PACKAGE_SOURCE_DIR}")
56 set(PARENT_PACKAGE_BINARY_DIR "${PACKAGE_BINARY_DIR}")
57
58 # Now override the package-like variables
59 tribits_set_common_vars(${SUBPACKAGE_FULLNAME})
60 tribits_define_linkage_vars(${SUBPACKAGE_FULLNAME})
61 tribits_pkg_init_exported_vars(${SUBPACKAGE_FULLNAME})
62
63 tribits_append_package_specific_compiler_flags()
64 if(${PROJECT_NAME}_VERBOSE_CONFIGURE)
65 message("Final subpackage compiler flags:")
66 endif()
67 tribits_print_package_compiler_flags()
68
69 # Set flags that are used to check that macros are called in the correct order
70 set(${SUBPACKAGE_FULLNAME}_TRIBITS_SUBPACKAGE_CALLED TRUE)
71 set(${SUBPACKAGE_FULLNAME}_TRIBITS_SUBPACKAGE_POSTPROCESS_CALLED FALSE)
72
73 endmacro()
74
75
76 function(tribits_subpackage_assert_call_context)
77
78 # check that this is not being called from a package
79 if (NOT CURRENTLY_PROCESSING_SUBPACKAGE)
80 # we are in a package
81 tribits_report_invalid_tribits_usage(
82 "Cannot call tribits_subpackage() from a package."
83 " Use tribits_package() instead"
84 " ${CURRENT_PACKAGE_CMAKELIST_FILE}")
85 else()
86 # We are in a subpackage
87 # check to see if postprocess is called before subpackage
88 if(${SUBPACKAGE_FULLNAME}_TRIBITS_SUBPACKAGE_POSTPROCESS_CALLED)
89 tribits_report_invalid_tribits_usage(
90 "tribits_subpackage_postprocess() called before tribits_subpackage()")
91 endif()
92
93 # check to see if we have already called this macro
94 if(${SUBPACKAGE_FULLNAME}_TRIBITS_SUBPACKAGE_CALLED)
95 tribits_report_invalid_tribits_usage(
96 "Already called tribits_subpackge() for the"
97 " ${PARENT_PACKAGE_NAME} subpackage ${TRIBITS_SUBPACKAGE}")
98 endif()
99
100 # make sure the name in the macro call matches the name in the packages cmake file
101 if (NOT ${SUBPACKAGE_NAME_IN} STREQUAL ${SUBPACKAGE_NAME})
102 tribits_report_invalid_tribits_usage(
103 "Error, the package-defined subpackage name"
104 " '${SUBPACKAGE_NAME_IN}' is not the same as the subpackage name"
105 " '${SUBPACKAGE_NAME}' defined in the parent packages's"
106 " Dependencies.cmake file")
107 endif()
108 endif()
109
110 endfunction()
111
112
113 # @MACRO: tribits_subpackage_postprocess()
114 #
115 # Macro that performs standard post-processing after defining a `TriBITS
116 # Subpackage`_ which is called at the bottom of a subpackage's
117 # `<packageDir>/<spkgDir>/CMakeLists.txt`_ file.
118 #
119 # Usage::
120 #
121 # tribits_subpackage_postprocess()
122 #
123 # NOTE: This creates the aliased target ``${PACKAGE_NAME}::all_libs`` for all
124 # libraries in all subdirectories that don't have the TRIBITS_TESTONLY_LIB
125 # target property set on them.
126 #
127 # NOTE: It is unfortunate that a Subpackages's CMakeLists.txt file must call
128 # this macro but limitations of the CMake language make it necessary to do so.
129 #
130 macro(tribits_subpackage_postprocess)
131 tribits_subpackage_postprocess_assert_call_context()
132 tribits_package_postprocess_common()
133 endmacro()
134
135
136 macro(tribits_subpackage_postprocess_assert_call_context)
137
138 # check that this is not being called from a package
139 if (NOT CURRENTLY_PROCESSING_SUBPACKAGE)
140 # This is being called from a package
141 tribits_report_invalid_tribits_usage(
142 "Cannot call tribits_subpackage_postprocess() from a package."
143 " Use tribits_package_postprocess() instead"
144 " ${CURRENT_PACKAGE_CMAKELIST_FILE}")
145 else()
146 # This is being called from a subpackage
147 # check to make sure this has not already been called
148 if (${SUBPACKAGE_FULLNAME}_TRIBITS_SUBPACKAGE_POSTPROCESS_CALLED)
149 tribits_report_invalid_tribits_usage(
150 "Already called tribits_subpackge_postprocess() for the"
151 " ${PARENT_PACKAGE_NAME} subpackage ${TRIBITS_SUBPACKAGE}")
152 endif()
153
154 # make sure subpackage is called prior to subpackage postprocess
155 if(NOT ${SUBPACKAGE_FULLNAME}_TRIBITS_SUBPACKAGE_CALLED)
156 tribits_report_invalid_tribits_usage(
157 "tribits_subpackage() must be called before tribits_subpackage_postprocess()"
158 " for the ${PARENT_PACKAGE_NAME} subpackage ${TRIBITS_SUBPACKAGE}")
159 endif()
160 endif()
161
162 # Set flags that are used to check that macros are called in the correct order
163 dual_scope_set(${SUBPACKAGE_FULLNAME}_TRIBITS_SUBPACKAGE_POSTPROCESS_CALLED TRUE)
164
165 endmacro()