Debian Codegraph @

cmake/tribits/core/package_arch/TribitsProcessEnabledTpls.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 # Standard TriBITS Includes
12 include(TribitsExternalPackageWithImportedTargetsFindTplModuleHelpers)
13 include(TribitsExternalPackageWriteConfigFile)
14 include(TribitsTplFindIncludeDirsAndLibraries)
15 include(TribitsGeneralMacros)
16 include(TribitsConfigureTiming)
17
18 # Standard TriBITS utilities includes
19 include(AppendStringVar)
20 include(TribitsStandardizePaths)
21 include(TribitsCreateReverseList)
22
23
24 # @MACRO: tribits_process_enabled_tpls()
25 #
26 # Gather information and targets from enabled TPLs
27 #
28 # For more info, see `Processing of external packages/TPLs and
29 # TriBITS-compliant external packages`_.
30 #
31 macro(tribits_process_enabled_tpls)
32
33 tribits_config_code_start_timer(CONFIGURE_TPLS_TIME_START_SECONDS)
34
35 tribits_filter_package_list_from_var(${PROJECT_NAME}_DEFINED_TOPLEVEL_PACKAGES
36 EXTERNAL ON NONEMPTY ${PROJECT_NAME}_enabledExternalTopLevelPackages)
37
38 tribits_project_has_tribits_compliant_external_packages(
39 ${PROJECT_NAME}_enabledExternalTopLevelPackages
40 projectHasTribitsCompliantExternalPackages )
41
42 if (projectHasTribitsCompliantExternalPackages)
43 message("")
44 message("Getting information for all enabled TriBITS-compliant"
45 " or upstream external packages/TPLs in reverse order ...")
46 message("")
47
48 tribits_create_reverse_list(${PROJECT_NAME}_enabledExternalTopLevelPackages
49 ${PROJECT_NAME}_reverseEnabledExternalTopLevelPackages)
50
51 foreach(TPL_NAME IN LISTS ${PROJECT_NAME}_reverseEnabledExternalTopLevelPackages)
52 if (${TPL_NAME}_IS_TRIBITS_COMPLIANT
53 OR ${TPL_NAME}_PROCESSED_BY_DOWNSTREAM_TRIBITS_EXTERNAL_PACKAGE
54 )
55 tribits_process_enabled_tribits_compliant_or_upstream_tpl(${TPL_NAME})
56 endif()
57 endforeach()
58
59 set(remainingTplsTextStr " remaining")
60
61 else()
62
63 set(remainingTplsTextStr "")
64
65 endif()
66
67 message("")
68 message("Getting information for all${remainingTplsTextStr} enabled external packages/TPLs ...")
69 message("")
70
71 foreach(TPL_NAME IN LISTS ${PROJECT_NAME}_enabledExternalTopLevelPackages)
72 if ((NOT ${TPL_NAME}_IS_TRIBITS_COMPLIANT)
73 AND (NOT ${TPL_NAME}_PROCESSED_BY_DOWNSTREAM_TRIBITS_EXTERNAL_PACKAGE)
74 )
75 tribits_process_enabled_standard_tpl(${TPL_NAME})
76 endif()
77 endforeach()
78
79 tribits_config_code_stop_timer(CONFIGURE_TPLS_TIME_START_SECONDS
80 "\nTotal time to configure enabled external packages/TPLs")
81
82 endmacro()
83
84
85 macro(tribits_process_enabled_tribits_compliant_or_upstream_tpl TPL_NAME)
86
87 tribits_get_enabled_tpl_processing_string(${TPL_NAME} tplProcessingString)
88 message("${tplProcessingString}")
89
90 if (NOT ${PROJECT_NAME}_TRACE_DEPENDENCY_HANDLING_ONLY)
91 if ( (NOT TARGET ${TPL_NAME}::all_libs) AND ${TPL_NAME}_IS_TRIBITS_COMPLIANT )
92 tribits_process_enabled_tribits_compliant_tpl(${TPL_NAME})
93 set(${TPL_NAME}_PROCESSED_BY_DOWNSTREAM_TRIBITS_EXTERNAL_PACKAGE FALSE)
94 elseif (TARGET ${TPL_NAME}::all_libs)
95 message("-- "
96 "The external package/TPL ${TPL_NAME} was defined by a downstream"
97 " TriBITS-compliant external package already processed")
98 elseif (${TPL_NAME}_FINDMOD AND (NOT ${TPL_NAME}_FINDMOD STREQUAL "TRIBITS_PKG"))
99 message("-- "
100 "The external package/TPL ${TPL_NAME} was *NOT* defined by a downstream"
101 " TriBITS-compliant external package and must be found again in below loop")
102 set(${TPL_NAME}_PROCESSED_BY_DOWNSTREAM_TRIBITS_EXTERNAL_PACKAGE FALSE)
103 else()
104 message(FATAL_ERROR
105 "Error, the external package/TPL ${TPL_NAME} was *NOT* defined by a downstream"
106 " TriBITS-compliant external package and has not find module!")
107 endif()
108 endif()
109
110 endmacro()
111 # NOTE: Above, handles the case where an upstream external package/TPL should
112 # have been defined a downstream external package that was already processed
113 # but it was not defined (because the downstream packages was not a fully
114 # TriBITS-compliant external package). For a TriBITS-compliant external
115 # package/TPL that should have been defined by a downstream TriBITS-compliant
116 # an external package/TPL, the first if-statement above takes care of that
117 # case by calling find_package(${TPL_NAME}) (because ${TPL_NAME}::all_libs
118 # will not be defined). However, if the upstream external package/TPL is
119 # *NOT* TriBITS-compliant, then it may be a legacy TriBITS TPL which means
120 # that it must be processed in ascending order in order to build the
121 # downstream TriBITS TPLs correctly.
122
123
124 # @MACRO: tribits_process_enabled_standard_tpl()
125 #
126 # Process an enabled TPL's FindTPL${TPL_NAME}.cmake module.
127 #
128 macro(tribits_process_enabled_standard_tpl TPL_NAME)
129
130 tribits_get_enabled_tpl_processing_string(${TPL_NAME} tplProcessingString)
131 message("${tplProcessingString}")
132
133 if (NOT ${PROJECT_NAME}_TRACE_DEPENDENCY_HANDLING_ONLY)
134
135 # Locate the FindTPL${TPL_NAME}.cmake module
136 if (${PROJECT_NAME}_VERBOSE_CONFIGURE)
137 print_var(${TPL_NAME}_FINDMOD)
138 endif()
139
140 tribits_process_enabled_tribits_find_tpl_mod_file(${TPL_NAME})
141 tribits_address_failed_tpl_find(${TPL_NAME})
142 tribits_generate_tpl_version_file_and_add_package_config_install_targets(
143 ${TPL_NAME})
144
145 endif()
146
147 endmacro()
148
149
150 # Get external package/TPL processing string
151 #
152 function(tribits_get_enabled_tpl_processing_string TPL_NAME tplProcessingStringOut)
153 set(tplProcessingString "Processing enabled external package/TPL: ${TPL_NAME} (")
154 if (${TPL_NAME}_ENABLING_PKG)
155 string(APPEND tplProcessingString "enabled by ${${TPL_NAME}_ENABLING_PKG}," )
156 else()
157 string(APPEND tplProcessingString "enabled explicitly," )
158 endif()
159 string(APPEND tplProcessingString " disable with -DTPL_ENABLE_${TPL_NAME}=OFF)" )
160 set(${tplProcessingStringOut} "${tplProcessingString}" PARENT_SCOPE)
161 endfunction()
162
163
164 # Process an enabled TPL defined using a TriBITS-compliant external package
165 # <tplName>Config.cmake file
166 #
167 macro(tribits_process_enabled_tribits_compliant_tpl TPL_NAME)
168 message("-- "
169 "Calling find_package(${TPL_NAME}) for TriBITS-compliant external package")
170 find_package(${TPL_NAME} CONFIG REQUIRED)
171 if (${TPL_NAME}_DIR)
172 message("-- " "Found ${TPL_NAME}_DIR='${${TPL_NAME}_DIR}'")
173 else()
174 message(FATAL_ERROR
175 "ERROR! Failed to find TriBITS-compliant external package ${TPL_NAME}!")
176 endif()
177 endmacro()
178
179
180 # Process an enabled TPL defined using a FindTPL<tplName>.cmake module
181 #
182 macro(tribits_process_enabled_tribits_find_tpl_mod_file TPL_NAME)
183
184 if (IS_ABSOLUTE ${${TPL_NAME}_FINDMOD})
185 #message("${${TPL_NAME}_FINDMOD} is absolute!")
186 set(CURRENT_TPL_PATH "${${TPL_NAME}_FINDMOD}")
187 else()
188 #message("${${TPL_NAME}_FINDMOD} is *NOT* absolute!")
189 set(CURRENT_TPL_PATH "${PROJECT_SOURCE_DIR}/${${TPL_NAME}_FINDMOD}")
190 endif()
191 #print_var(CURRENT_TPL_PATH)
192
193 # Process the FindTPL${TPL_NAME}.cmake module
194 tribits_trace_file_processing(TPL INCLUDE "${CURRENT_TPL_PATH}")
195 set(TRIBITS_FINDING_RAW_${TPL_NAME}_PACKAGE_FIRST TRUE)
196 include("${CURRENT_TPL_PATH}")
197 unset(TRIBITS_FINDING_RAW_${TPL_NAME}_PACKAGE_FIRST)
198 # NOTE: Above, setting TRIBITS_FINDING_RAW_${TPL_NAME}_PACKAGE_FIRST=TRUE
199 # triggers special logic in the TriBITS-created
200 # ${TPL_NAME}ConfigVersion.cmake file to set
201 # PACKAGE_VERSION_COMPATIBLE=FALSE and result in find_package(${TPL_NAME})
202 # that may be called inside of ${TPL_NAME}_FINDMOD to not find a
203 # TriBITS-generated ${TPL_NAME}Config.cmake file. This allows
204 # find_package(${TPL_NAME}) to usae a proper non-TriBITS
205 # Find${TPL_NAME}.cmake module or find a non-TriBITS
206 # ${TPL_NAME}Config.cmake module.
207
208 if (${PROJECT_NAME}_VERBOSE_CONFIGURE)
209 print_var(TPL_${TPL_NAME}_NOT_FOUND)
210 endif()
211
212 endmacro()
213
214
215 function(tribits_address_failed_tpl_find TPL_NAME)
216 # Address failed find of the TPL
217 if (TPL_${TPL_NAME}_NOT_FOUND AND NOT TPL_TENTATIVE_ENABLE_${TPL_NAME})
218 message(
219 "-- NOTE: The find module file for this failed TPL '${TPL_NAME}' is:\n"
220 " ${CURRENT_TPL_PATH}\n"
221 " which is pointed to in the file:\n"
222 " ${${TPL_NAME}_TPLS_LIST_FILE}\n"
223 )
224 if (${TPL_NAME}_ENABLING_PKG)
225 message(
226 "TIP: One way to get past the configure failure for the\n"
227 "TPL '${TPL_NAME}' is to simply disable it with:\n"
228 " -DTPL_ENABLE_${TPL_NAME}=OFF\n"
229 "which will disable it and will recursively disable all of the\n"
230 "downstream packages that have required dependencies on it, including\n"
231 "the package '${${TPL_NAME}_ENABLING_PKG}' which triggered its enable.\n"
232 "When you reconfigure, just grep the cmake stdout for '${TPL_NAME}'\n"
233 "and then follow the disables that occur as a result to see what impact\n"
234 "this TPL disable has on the configuration of ${PROJECT_NAME}.\n"
235 )
236 else()
237 message(
238 "TIP: Even though the TPL '${TPL_NAME}' was explicitly enabled in input,\n"
239 "it can be disabled with:\n"
240 " -DTPL_ENABLE_${TPL_NAME}=OFF\n"
241 "which will disable it and will recursively disable all of the\n"
242 "downstream packages that have required dependencies on it.\n"
243 "When you reconfigure, just grep the cmake stdout for '${TPL_NAME}'\n"
244 "and then follow the disables that occur as a result to see what impact\n"
245 "this TPL disable has on the configuration of ${PROJECT_NAME}.\n"
246 )
247 endif()
248 message(FATAL_ERROR
249 "ERROR: TPL_${TPL_NAME}_NOT_FOUND=${TPL_${TPL_NAME}_NOT_FOUND}, aborting!")
250 endif()
251 endfunction()
252
253
254 # Generate the <tplName>ConfigVersion.cmake file for a TriBITS TPL and install
255 # the already generated <tplName>Config.cmake file
256 #
257 function(tribits_generate_tpl_version_file_and_add_package_config_install_targets
258 TPL_NAME
259 )
260 set(buildDirExternalPkgsDir
261 "${${PROJECT_NAME}_BINARY_DIR}/${${PROJECT_NAME}_BUILD_DIR_EXTERNAL_PKGS_DIR}")
262 set(tplConfigFile
263 "${buildDirExternalPkgsDir}/${TPL_NAME}/${TPL_NAME}Config.cmake")
264 set(tplConfigVersionFile
265 "${buildDirExternalPkgsDir}/${TPL_NAME}/${TPL_NAME}ConfigVersion.cmake")
266 tribits_extpkg_write_config_version_file(${TPL_NAME}
267 "${tplConfigVersionFile}")
268 tribits_extpkg_install_config_file(${TPL_NAME} "${tplConfigFile}")
269 tribits_extpkg_install_config_version_file(${TPL_NAME}
270 "${tplConfigVersionFile}")
271 endfunction()
272
273
274 function(tribits_project_has_tribits_compliant_external_packages
275 enabledExternalTopLevelPackagesListName
276 projectHasTribitsCompliantExternalPackagesOut
277 )
278
279 set(projectHasTribitsCompliantExternalPackages FALSE)
280
281 foreach(TPL_NAME IN LISTS ${enabledExternalTopLevelPackagesListName})
282 if (${TPL_NAME}_IS_TRIBITS_COMPLIANT
283 OR ${TPL_NAME}_PROCESSED_BY_DOWNSTREAM_TRIBITS_EXTERNAL_PACKAGE
284 )
285 set(projectHasTribitsCompliantExternalPackages TRUE)
286 break()
287 endif()
288 endforeach()
289
290 set(${projectHasTribitsCompliantExternalPackagesOut}
291 ${projectHasTribitsCompliantExternalPackages} PARENT_SCOPE)
292
293 endfunction()