Debian Codegraph @

cmake/tribits/core/package_arch/TribitsTplFindIncludeDirsAndLibraries.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_guard()
11
12 include(TribitsExternalPackageWriteConfigFile)
13
14 include(AdvancedSet)
15 include(AppendSet)
16 include(AssertDefined)
17 include(DualScopeSet)
18 include(GlobalNullSet)
19 include(GlobalSet)
20 include(MultilineSet)
21 include(CMakeParseArguments)
22 include(SetNotFound)
23 include(Split)
24
25
26 # @FUNCTION: tribits_tpl_allow_pre_find_package()
27 #
28 # Function that determines if a TriBITS find module file
29 # ``FindTPL<tplName>.cmake`` is allowed to call ``find_package(<tplName>
30 # ...)`` before calling `tribits_tpl_find_include_dirs_and_libraries()`_.
31 #
32 # Usage::
33 #
34 # tribits_tpl_allow_pre_find_package( <tplName>
35 # <allowPackagePrefindOut> )
36 #
37 # The required arguments are:
38 #
39 # ``<tplName>`` : The input name of the TriBITS TPL (e.g. ``HDF5``).
40 #
41 # ``<allowPackagePrefindOut>`` : Name of a variable which will be set to
42 # ``TRUE`` on output if ``find_package(<tplName> ...)`` should be called to
43 # find the TPL ``<tplName>`` or ``FALSE`` if it should not be called.
44 #
45 # This function will set ``<allowPackagePrefindOut>`` to ``FALSE`` if any of
46 # the variables ``TPL_<tplName>_INCLUDE_DIRS``, ``${TPL_<tplName>_LIBRARIES``,
47 # or ``TPL_<tplName>_LIBRARY_DIRS`` are set. This allows the user to override
48 # the search for the library components and just specify the absolute
49 # locations. The function will also set ``<allowPackagePrefindOut>`` to
50 # ``FALSE`` if ``<tplName>_INCLUDE_DIRS``, ``<tplName>_LIBRARY_NAMES``, or
51 # ``<tplName>_LIBRARY_DIRS`` is set and ``<tplName>_FORCE_PRE_FIND_PACKAGE``
52 # is set to ``FALSE``. Otherwise, if ``<tplName>_FORCE_PRE_FIND_PACKAGE`` is
53 # set to ``TRUE``, the function will not return ``FALSE`` for
54 # ``<allowPackagePrefindOut>`` no matter what the values of
55 # ``<tplName>_INCLUDE_DIRS``, ``<tplName>_LIBRARY_NAMES``, or
56 # ``<tplName>_LIBRARY_DIRS``. Finally, ``<allowPackagePrefindOut>`` is set to
57 # ``FALSE`` if ``<tplName>_ALLOW_PACKAGE_PREFIND=OFF`` is set in the cache.
58 #
59 # The variable ``<tplName>_FORCE_PRE_FIND_PACKAGE`` is needed to allow users
60 # (or the ``FindTPL<tplName>.cmake`` module itself) to avoid name clashes with
61 # the variables ``<tplName>_INCLUDE_DIRS`` or ``<tplName>_LIBRARY_DIRS`` in
62 # the usage of ``find_package(<tplName> ...)`` because a lot of default
63 # ``Find<tplName>.cmake`` modules also use these variables. This function
64 # sets ``<tplName>_FORCE_PRE_FIND_PACKAGE`` as a cache variable with default
65 # value ``FALSE`` to maintain backward compatibility with existing
66 # ``FindTPL<tplName>.cmake`` modules.
67 #
68 # The cache variable ``<tplName>_ALLOW_PACKAGE_PREFIND`` is to allow the user
69 # to disable the prefind call to ``find_package()`` even if it would be
70 # allowed otherwise.
71 #
72 # See `Creating FindTPL<tplName>.cmake using find_package() without IMPORTED
73 # targets`_ for details in how to use this function to create a
74 # ``FindTPL<tplName>.cmake`` module file.
75 #
76 function(tribits_tpl_allow_pre_find_package TPL_NAME ALLOW_PACKAGE_PREFIND_OUT)
77
78 if (TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE_DEBUG)
79 message("TRIBITS_TPL_ALLOW_PRE_FIND_PACKAGE: '${TPL_NAME}' '${ALLOW_PACKAGE_PREFIND_OUT}'")
80 print_var(${TPL_NAME}_INCLUDE_DIRS)
81 print_var(${TPL_NAME}_LIBRARY_NAMES)
82 print_var(${TPL_NAME}_LIBRARY_DIRS)
83 print_var(${TPL_NAME}_FORCE_PRE_FIND_PACKAGE)
84 endif()
85
86 advanced_set(${TPL_NAME}_FORCE_PRE_FIND_PACKAGE FALSE
87 CACHE BOOL
88 "Determines if the variables ${TPL_NAME}_[INCLUDE_DIRS,LIBRARY_NAMES,LIBRARY_DIRS] should be ignored and the pre-find find_package(${TPL_NAME} should be performed anyway. But this will *not* do the pre-find if any of the TPL_${TPL_NAME}_[INCLUDE_DIRS,LIBRARY_NAMES,LIBRARY_DIRS] vars are set." )
89
90 # Start out with TRUE and set to FALSE in logic below
91 set(${TPL_NAME}_ALLOW_PACKAGE_PREFIND TRUE CACHE BOOL
92 "Set to FALSE to skip find_package() prefind for the TriBITS TPL '${TPL_NAME}'")
93
94 # Start out with TRUE and set to FALSE in logic below
95 set(ALLOW_PACKAGE_PREFIND TRUE)
96
97 if (NOT ${TPL_NAME}_ALLOW_PACKAGE_PREFIND)
98 set(ALLOW_PACKAGE_PREFIND FALSE)
99 elseif (
100 (NOT "${TPL_${TPL_NAME}_INCLUDE_DIRS}" STREQUAL "")
101 OR (NOT "${TPL_${TPL_NAME}_LIBRARIES}" STREQUAL "")
102 OR (NOT "${TPL_${TPL_NAME}_LIBRARY_DIRS}" STREQUAL "")
103 )
104 # The user has selected one or more of the final vars so skip calling
105 # find_package(${TPL_NAME} ...) ...
106 set(ALLOW_PACKAGE_PREFIND FALSE)
107 elseif (
108 (NOT "${${TPL_NAME}_INCLUDE_DIRS}" STREQUAL "")
109 OR (NOT "${${TPL_NAME}_LIBRARY_NAMES}" STREQUAL "")
110 OR (NOT "${${TPL_NAME}_LIBRARY_DIRS}" STREQUAL "")
111 )
112 # One or more of the ${TPL_NAME}_XXX variables are set
113 if (${TPL_NAME}_FORCE_PRE_FIND_PACKAGE)
114 # Even with one or more of the ${TPL_NAME}_XXX vars set, we still want
115 # to do the find_package(${TPL_NAME} ...) search and ignore this
116 # override.
117 else()
118 # We will not ignore the override of these variables and will instead go
119 # ahead and skip the pre-find.
120 set(ALLOW_PACKAGE_PREFIND FALSE)
121 endif()
122 endif()
123
124 set(${ALLOW_PACKAGE_PREFIND_OUT} ${ALLOW_PACKAGE_PREFIND} PARENT_SCOPE)
125
126 endfunction()
127
128
129 # @FUNCTION: tribits_tpl_find_include_dirs_and_libraries()
130 #
131 # This function reads (cache) variables that specify where to find a `TriBITS
132 # TPL`_'s headers and libraries and then creates IMPORTED targets, the
133 # ``<tplName>::all_libs`` target, and writes the file
134 # ``<tplName>Config.cmake`` into the standard location in the build directory.
135 # This function is typically called inside of a ``FindTPL<tplName>.cmake``
136 # module file (see `${TPL_NAME}_FINDMOD`_).
137 #
138 # Usage::
139 #
140 # tribits_tpl_find_include_dirs_and_libraries(
141 # <tplName>
142 # [REQUIRED_HEADERS <header1> <header2> ...]
143 # [MUST_FIND_ALL_HEADERS]
144 # [REQUIRED_LIBS_NAMES "<libname1> <libname1alt1> ..." <libname2> ...]
145 # [MUST_FIND_ALL_LIBS]
146 # [NO_PRINT_ENABLE_SUCCESS_FAIL]
147 # )
148 #
149 # This function can be called to specify/require header files and include
150 # directories and/or a list of libraries.
151 #
152 # The input arguments to this function are:
153 #
154 # ``<tplName>``
155 #
156 # Name of the TPL that is listed in a `<repoDir>/TPLsList.cmake`_ file.
157 #
158 # ``REQUIRED_HEADERS``
159 #
160 # List of header files that are searched in order to find the TPL's
161 # include directories files using ``find_path()``.
162 #
163 # ``MUST_FIND_ALL_HEADERS``
164 #
165 # If set, then all of the header files listed in ``REQUIRED_HEADERS`` must
166 # be found (unless ``TPL_<tplName>_INCLUDE_DIRS`` is already set).
167 #
168 # ``REQUIRED_LIBS_NAMES "<libname1> <libname1alt1> ..." <libname2> ...``
169 #
170 # List of libraries that are searched for when looking for the TPL's
171 # libraries using ``find_library()``. A single list of library names of
172 # the form:
173 #
174 # ``<libname1> <libname2> ...``
175 #
176 # are searched for and must all be found and will define the libraries for
177 # this TPL on the link line in that order. However, a library name along
178 # with alternate library names can be provided using outer quotes with
179 # inner spaces:
180 #
181 # ``"<libname1> <libname1alt1> <libname1alt2> ..."``
182 #
183 # In this case, first, ``<libname1>`` is looked for and used if it is
184 # found. If not found, then the next alternate library name
185 # ``<libname1alt1>`` is looked for and is used if found. This continues
186 # with each successive alternate library name in the set until one is
187 # found. If none of the libraries in the set alternative names are found,
188 # then this is an error. Providing a set of alternate library names (in
189 # order of preference) allows the default find operation to look for
190 # different library names for different situations and implementations.
191 # For example, the BLAS library can be called ``blas``, ``openblas`` or
192 # ``atlas`` for different BLAS implementations and can be specified as:
193 #
194 # ``"blas openblas atlas"``
195 #
196 # The list of required library names can be overridden by the user by
197 # setting ``<tplName>_LIBRARY_NAMES`` (see below).
198 #
199 # ``MUST_FIND_ALL_LIBS``
200 #
201 # If set, then all of the library files listed in ``REQUIRED_LIBS_NAMES``
202 # must be found or the TPL is considered not found (unless
203 # ``TPL_<tplName>_LIBRARIES`` is already set). If the global cache var
204 # ``<Project>_MUST_FIND_ALL_TPL_LIBS`` is set to ``TRUE``, then this is
205 # turned on as well. WARNING: The default is not to require finding all
206 # of the listed libs. (This is to maintain backward compatibility with
207 # some older ``FindTPL<tplName>.cmake`` modules.)
208 #
209 # ``NO_PRINT_ENABLE_SUCCESS_FAIL``
210 #
211 # If set, then the final success/fail will not be printed
212 #
213 # This function implements the TPL find behavior described in `Enabling
214 # support for an optional Third-Party Library (TPL)`_.
215 #
216 # The following (cache) variables, if set, will be used by this function:
217 #
218 # ``<tplName>_INCLUDE_DIRS`` (type ``PATH``)
219 #
220 # List of paths to search first for header files defined in
221 # ``REQUIRED_HEADERS <header1> <header2> ...``.
222 #
223 # ``<tplName>_LIBRARY_DIRS`` (type ``PATH``)
224 #
225 # The list of directories to search first for libraries defined in
226 # ``REQUIRED_LIBS_NAMES <libname1> <libname2> ...``. If, for some reason,
227 # no libraries should be linked in for this particular configuration, then
228 # setting ``<tplName>_LIBRARY_DIRS=OFF`` or is empty will no special paths
229 # will be searched.
230 #
231 # ``<tplName>_LIBRARY_NAMES`` (type ``STRING``)
232 #
233 # List of library names to be looked for instead of what is specified in
234 # ``REQUIRED_LIBS_NAMES <libname1> <libname2> ...``. If set, only a
235 # single set of libraries can be specified of which all need to be found.
236 #
237 # ``<tplName>_LIB_ENABLED_DEPENDENCIES``
238 #
239 # List of direct upstream external package/TPL dependencies that also
240 # define ``<upstreamTplName>::all_libs`` targets.
241 #
242 # An addition, the function will avoid calling the find operations if the
243 # following (cache) variables are set on input:
244 #
245 # ``TPL_<tplName>_INCLUDE_DIRS`` (type ``PATH``)
246 #
247 # A list of common-separated full directory paths that contain the TPL's
248 # header files.
249 #
250 # ``TPL_<tplName>_LIBRARIES`` (type ``FILEPATH``)
251 #
252 # A list of commons-separated full library names (i.e. output from
253 # ``find_library()``) for all of the libraries for the TPL.
254 #
255 # This function produces the following:
256 #
257 # ``TPL_<tplName>_NOT_FOUND`` (type ``BOOL``)
258 #
259 # Will be set to ``ON`` if all of the parts of the TPL could not be found.
260 #
261 # ``<tplName>::<libname>``
262 #
263 # Namespaced IMPORTED target for every library found or specified in
264 # ``TPL_<tplName>_LIBRARIES``. These IMPORTED targets will have the
265 # ``<upstreamTplName>::all_libs`` for the upstream external packages/TPLs
266 # listed in ``<tplName>_LIB_ENABLED_DEPENDENCIES``.
267 #
268 # ``<tplName>::all_libs``
269 #
270 # INTERFACE target that depends on all of the created IMPORTED targets.
271 #
272 # ``<buildDir>/external_packages/<tplName>/<tplName>Config.cmake``
273 #
274 # A package configure file that contains all of the generated IMPORTED
275 # targets ``<tplName>::<libname>`` and the ``<tplName>::all_libs`` target.
276 # This fill will also call ``find_dependency()`` to pull in
277 # ``<upstreamTplName>Config.cmake`` files for upstream TPLs that are
278 # listed in ``<tplName>_LIB_ENABLED_DEPENDENCIES``. (For more
279 # information, see `tribits_extpkg_write_config_file()`_.)
280 #
281 # Note, if ``TPL_TENTATIVE_ENABLE_<tplName>=ON``, then if all of the parts of
282 # the TPL can't be found, then ``TPL_ENABLE_<tplName>`` will be (forced) set
283 # to ``OFF`` in the cache. See `tribits_tpl_tentatively_enable()`_.
284 #
285 function(tribits_tpl_find_include_dirs_and_libraries TPL_NAME)
286
287 # Make sure the right name is used
288 assert_defined(TPL_ENABLE_${TPL_NAME})
289
290 cmake_parse_arguments(
291 #prefix
292 PARSE
293 #options
294 "MUST_FIND_ALL_LIBS;MUST_FIND_ALL_HEADERS;NO_PRINT_ENABLE_SUCCESS_FAIL"
295 #one_value_keywords
296 ""
297 #multi_value_keywords
298 "REQUIRED_HEADERS;REQUIRED_LIBS_NAMES"
299 ${ARGN}
300 )
301
302 tribits_check_for_unparsed_arguments()
303
304 if (${PROJECT_NAME}_VERBOSE_CONFIGURE)
305 set(TRIBITS_TPL_FIND_INCLUDE_DIRS_AND_LIBRARIES_VERBOSE TRUE)
306 endif()
307
308 if (TRIBITS_TPL_FIND_INCLUDE_DIRS_AND_LIBRARIES_VERBOSE)
309 message("TRIBITS_TPL_FIND_INCLUDE_DIRS_AND_LIBRARIES: ${TPL_NAME}")
310 print_var(PARSE_REQUIRED_HEADERS)
311 print_var(PARSE_REQUIRED_LIBS_NAMES)
312 print_var(TPL_${TPL_NAME}_INCLUDE_DIRS)
313 print_var(TPL_${TPL_NAME}_LIBRARIES)
314 endif()
315
316 if (TPL_TENTATIVE_ENABLE_${TPL_NAME})
317 message("-- Attempting to tentatively enable TPL '${TPL_NAME}' ...")
318 set(ERROR_MSG_MODE)
319 else()
320 set(ERROR_MSG_MODE SEND_ERROR)
321 endif()
322
323 # Allow user override for finding libraries even if REQUIRED_LIBS_NAMES is
324 # empty on input
325
326 multiline_set(DOCSTR
327 "List of semi-colon separated names of libraries needed to link to for"
328 " the TPL ${TPL_NAME}. This list of libraries will be search for in"
329 " find_library(...) calls along with the directories specified with"
330 " ${TPL_NAME}_LIBRARY_DIRS. NOTE: This is not the final list of libraries"
331 " used for linking. That is specified by TPL_${TPL_NAME}_LIBRARIES!"
332 )
333 advanced_set(${TPL_NAME}_LIBRARY_NAMES ${PARSE_REQUIRED_LIBS_NAMES}
334 CACHE STRING ${DOCSTR})
335 split("${${TPL_NAME}_LIBRARY_NAMES}" "," ${TPL_NAME}_LIBRARY_NAMES)
336 print_var(${TPL_NAME}_LIBRARY_NAMES)
337
338 # Let the user override what the names of the libraries which might
339 # actually mean that no libraries are searched for.
340 set(REQUIRED_LIBS_NAMES ${${TPL_NAME}_LIBRARY_NAMES})
341
342 #
343 # User options
344 #
345
346 if (REQUIRED_LIBS_NAMES)
347
348 # Library directories
349
350 multiline_set(DOCSTR
351 "List of semi-colon separated paths to look for the TPL ${TPL_NAME}"
352 " libraries. This list of paths will be passed into a find_library(...)"
353 " command to find the libraries listed in ${TPL_NAME}_LIBRARY_NAMES."
354 " Note that this set of paths is also the default value used for"
355 " ${TPL_NAME}_LIBRARY_DIRS. Therefore, if the headers exist in the"
356 " same directories as the library, you do not need to set"
357 " ${TPL_NAME}_LIBRARY_DIRS."
358 )
359
360 advanced_set(${TPL_NAME}_LIBRARY_DIRS "" CACHE PATH ${DOCSTR})
361 if (TRIBITS_TPL_FIND_INCLUDE_DIRS_AND_LIBRARIES_VERBOSE)
362 print_var(${TPL_NAME}_LIBRARY_DIRS)
363 endif()
364
365 # Libraries
366
367 if (${PROJECT_NAME}_MUST_FIND_ALL_TPL_LIBS)
368 set(MUST_FIND_ALL_LIBS TRUE)
369 else()
370 set(MUST_FIND_ALL_LIBS ${PARSE_MUST_FIND_ALL_LIBS})
371 endif()
372
373 if (TRIBITS_TPL_FIND_INCLUDE_DIRS_AND_LIBRARIES_VERBOSE)
374 print_var(${TPL_NAME}_LIBRARY_NAMES)
375 print_var(REQUIRED_LIBS_NAMES)
376 endif()
377
378 else()
379
380 set(${TPL_NAME}_LIBRARY_DIRS "") # Just to ignore below!
381
382 endif()
383
384 # Include directories
385
386 if (PARSE_REQUIRED_HEADERS)
387
388 multiline_set(DOCSTR
389 "List of semi-colon separated paths to look for the TPL ${TPL_NAME}"
390 " headers. This list of paths will be passed into a find_path(...)"
391 " command to find the headers for ${TPL_NAME} (which are known in advance)."
392 )
393 advanced_set(${TPL_NAME}_INCLUDE_DIRS ${${TPL_NAME}_LIBRARY_DIRS}
394 CACHE PATH ${DOCSTR})
395
396 if (TRIBITS_TPL_FIND_INCLUDE_DIRS_AND_LIBRARIES_VERBOSE)
397 print_var(${TPL_NAME}_LIBRARY_DIRS)
398 print_var(${TPL_NAME}_INCLUDE_DIRS)
399 print_var(PARSE_REQUIRED_HEADERS)
400 endif()
401
402 endif()
403
404 #
405 # Set the lib extensions to find
406 #
407
408 # Save the default the first time through
409 if (NOT CMAKE_FIND_LIBRARY_SUFFIXES_DEFAULT)
410 set(TPL_CMAKE_FIND_LIBRARY_SUFFIXES_DEFAULT ${CMAKE_FIND_LIBRARY_SUFFIXES})
411 #print_var(TPL_CMAKE_FIND_LIBRARY_SUFFIXES_DEFAULT)
412 endif()
413
414 # Allow per-TPL shared lib find setting
415 if ("${${TPL_NAME}_FIND_SHARED_LIBS}" STREQUAL "")
416 set(${TPL_NAME}_FIND_SHARED_LIBS ${TPL_FIND_SHARED_LIBS})
417 endif()
418
419 #print_var(TPL_FIND_SHARED_LIBS)
420 #print_var(CMAKE_FIND_LIBRARY_SUFFIXES)
421 # Set libraries to find
422 if (${TPL_NAME}_FIND_SHARED_LIBS)
423 # The default should be to find shared libs first
424 set(TPL_CMAKE_FIND_LIBRARY_SUFFIXES ${TPL_CMAKE_FIND_LIBRARY_SUFFIXES_DEFAULT})
425 else()
426 if (WIN32)
427 set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a)
428 else()
429 set(CMAKE_FIND_LIBRARY_SUFFIXES .a )
430 endif()
431 endif()
432 #print_var(CMAKE_FIND_LIBRARY_SUFFIXES)
433
434 #
435 # Direct build options
436 #
437
438 set(_${TPL_NAME}_ENABLE_SUCCESS TRUE)
439
440 if (REQUIRED_LIBS_NAMES)
441
442 # Libraries
443
444 if (MUST_FIND_ALL_LIBS)
445 set(LIB_NOT_FOUND_MSG_PREFIX "ERROR:")
446 else()
447 set(LIB_NOT_FOUND_MSG_PREFIX "NOTE:")
448 endif()
449
450 if (NOT TPL_${TPL_NAME}_LIBRARIES)
451
452 if (MUST_FIND_ALL_LIBS)
453 message("-- Must find at least one lib in each of the"
454 " lib sets \"${REQUIRED_LIBS_NAMES}\"")
455 endif()
456
457 message( "-- Searching for libs in ${TPL_NAME}_LIBRARY_DIRS='${${TPL_NAME}_LIBRARY_DIRS}'")
458
459 set(LIBRARIES_FOUND "")
460
461 foreach(LIBNAME_SET ${REQUIRED_LIBS_NAMES})
462
463 message("-- Searching for a lib in the set \"${LIBNAME_SET}\":")
464
465 if (TRIBITS_TPL_FIND_INCLUDE_DIRS_AND_LIBRARIES_VERBOSE)
466 print_var(LIBNAME_SET)
467 endif()
468
469 set(LIBNAME_LIST ${LIBNAME_SET})
470 separate_arguments(LIBNAME_LIST)
471
472 set(LIBNAME_SET_LIB "")
473
474 foreach(LIBNAME ${LIBNAME_LIST})
475
476 message("-- Searching for lib '${LIBNAME}' ...")
477
478 if (${TPL_NAME}_LIBRARY_DIRS)
479 set(PATHS_ARG PATHS ${${TPL_NAME}_LIBRARY_DIRS})
480 else()
481 set(PATHS_ARG PATHS)
482 endif()
483
484 set_notfound(_${TPL_NAME}_${LIBNAME}_LIBRARY)
485 find_library( _${TPL_NAME}_${LIBNAME}_LIBRARY
486 NAMES ${LIBNAME}
487 ${PATHS_ARG} NO_DEFAULT_PATH )
488 find_library( _${TPL_NAME}_${LIBNAME}_LIBRARY
489 NAMES ${LIBNAME} )
490 mark_as_advanced(_${TPL_NAME}_${LIBNAME}_LIBRARY)
491
492 if (TRIBITS_TPL_FIND_INCLUDE_DIRS_AND_LIBRARIES_VERBOSE)
493 print_var(_${TPL_NAME}_${LIBNAME}_LIBRARY)
494 endif()
495
496 if (_${TPL_NAME}_${LIBNAME}_LIBRARY)
497 message("-- Found lib '${_${TPL_NAME}_${LIBNAME}_LIBRARY}'")
498 set(LIBNAME_SET_LIB ${_${TPL_NAME}_${LIBNAME}_LIBRARY})
499 break()
500 endif()
501
502 endforeach()
503
504 if (NOT LIBNAME_SET_LIB)
505 message(
506 "-- ${LIB_NOT_FOUND_MSG_PREFIX} Did not find a lib in the lib set \"${LIBNAME_SET}\""
507 " for the TPL '${TPL_NAME}'!")
508 if (MUST_FIND_ALL_LIBS)
509 set(_${TPL_NAME}_ENABLE_SUCCESS FALSE)
510 else()
511 break()
512 endif()
513 endif()
514
515 append_set(LIBRARIES_FOUND ${LIBNAME_SET_LIB})
516
517 endforeach()
518
519 multiline_set(DOCSTR
520 "List of semi-colon separated full paths to the libraries for the TPL"
521 " ${TPL_NAME}. This is the final variable that is used in the link"
522 " commands. The user variable ${TPL_NAME}_LIBRARY_DIRS is used to look"
523 " for the know library names but but is just a suggestion."
524 " This variable, however, is the final value and will not be touched."
525 )
526 advanced_set( TPL_${TPL_NAME}_LIBRARIES ${LIBRARIES_FOUND}
527 CACHE FILEPATH ${DOCSTR} FORCE)
528 # Above, we have to force the set in case the find failed the last
529 # configure in which case this cache var will be empty. NOTE: If the
530 # user specified a non-empty TPL_${TPL_NAME}_LIBRARIES, then we would
531 # never get here in the first place!
532
533 if (NOT TPL_${TPL_NAME}_LIBRARIES OR NOT _${TPL_NAME}_ENABLE_SUCCESS)
534 message(
535 "-- ERROR: Could not find the libraries for the TPL '${TPL_NAME}'!")
536 message(
537 "-- TIP: If the TPL '${TPL_NAME}' is on your system then you can set:\n"
538 " -D${TPL_NAME}_LIBRARY_DIRS='<dir0>;<dir1>;...'\n"
539 " to point to the directories where these libraries may be found.\n"
540 " Or, just set:\n"
541 " -DTPL_${TPL_NAME}_LIBRARIES='<path-to-libs0>;<path-to-libs1>;...'\n"
542 " to point to the full paths for the libraries which will\n"
543 " bypass any search for libraries and these libraries will be used without\n"
544 " question in the build. (But this will result in a build-time error\n"
545 " if not all of the necessary symbols are found.)")
546 tribits_tpl_find_include_dirs_and_libraries_handle_fail()
547 endif()
548
549 endif()
550
551 # Print the final value to be used *always*
552 message("-- TPL_${TPL_NAME}_LIBRARIES='${TPL_${TPL_NAME}_LIBRARIES}'")
553
554 else()
555
556 # There are no libraries so set the libraries to null but don't
557 # change the cache which should not even have this variable in it.
558 # This set command is only to follow the standards for the package
559 # support CMake code.
560 global_null_set(TPL_${TPL_NAME}_LIBRARIES)
561
562 endif()
563
564 # Include directories
565
566 if (PARSE_REQUIRED_HEADERS)
567
568 if (NOT TPL_${TPL_NAME}_INCLUDE_DIRS)
569
570 if (PARSE_MUST_FIND_ALL_HEADERS)
571 message("-- Must find at least one header in each of the"
572 " header sets \"${PARSE_REQUIRED_HEADERS}\"")
573 endif()
574
575 message( "-- Searching for headers in ${TPL_NAME}_INCLUDE_DIRS='${${TPL_NAME}_INCLUDE_DIRS}'")
576
577 foreach(INCLUDE_FILE_SET ${PARSE_REQUIRED_HEADERS})
578
579 message("-- Searching for a header file in the set \"${INCLUDE_FILE_SET}\":")
580
581 set(INCLUDE_FILE_LIST ${INCLUDE_FILE_SET})
582 separate_arguments(INCLUDE_FILE_LIST)
583 set(INCLUDE_FILE_SET_PATH) # Start out as empty list
584
585 foreach(INCLUDE_FILE ${INCLUDE_FILE_LIST})
586
587 message("-- Searching for header '${INCLUDE_FILE}' ...")
588
589 if (TRIBITS_TPL_FIND_INCLUDE_DIRS_AND_LIBRARIES_VERBOSE)
590 print_var(INCLUDE_FILE)
591 endif()
592
593 set_notfound(_${TPL_NAME}_${INCLUDE_FILE}_PATH)
594 find_path( _${TPL_NAME}_${INCLUDE_FILE}_PATH
595 NAMES ${INCLUDE_FILE}
596 PATHS ${${TPL_NAME}_INCLUDE_DIRS}
597 NO_DEFAULT_PATH)
598 find_path( _${TPL_NAME}_${INCLUDE_FILE}_PATH
599 NAMES ${INCLUDE_FILE} )
600 mark_as_advanced(_${TPL_NAME}_${INCLUDE_FILE}_PATH)
601
602 if (TRIBITS_TPL_FIND_INCLUDE_DIRS_AND_LIBRARIES_VERBOSE)
603 print_var(_${TPL_NAME}_${INCLUDE_FILE}_PATH)
604 endif()
605
606 if(_${TPL_NAME}_${INCLUDE_FILE}_PATH)
607 message( "-- Found header '${_${TPL_NAME}_${INCLUDE_FILE}_PATH}/${INCLUDE_FILE}'")
608 append_set(INCLUDE_FILE_SET_PATH ${_${TPL_NAME}_${INCLUDE_FILE}_PATH})
609 break()
610 endif()
611
612 endforeach()
613
614 if(NOT INCLUDE_FILE_SET_PATH)
615 message("-- ERROR: Could not find a header file in"
616 " the set \"${INCLUDE_FILE_SET}\"")
617 if(PARSE_MUST_FIND_ALL_HEADERS)
618 set(_${TPL_NAME}_ENABLE_SUCCESS FALSE)
619 endif()
620 endif()
621
622 append_set(INCLUDES_FOUND ${INCLUDE_FILE_SET_PATH})
623
624 endforeach(INCLUDE_FILE_SET ${PARSE_REQUIRED_HEADERS})
625
626 if (INCLUDES_FOUND)
627 list(REMOVE_DUPLICATES INCLUDES_FOUND)
628 endif()
629
630 multiline_set(DOCSTR
631 "List of semi-colon separated paths to append to the compile invocations"
632 " to find the headers for the TPL ${TPL_NAME}. This is the final variable"
633 " that is used in the build commands. The user variable ${TPL_NAME}_INCLUDE_DIRS"
634 " is used to look for the given headers first but is just a suggestion."
635 " This variable, however, is the final value and will not be touched."
636 )
637
638 advanced_set(TPL_${TPL_NAME}_INCLUDE_DIRS ${INCLUDES_FOUND}
639 CACHE PATH ${DOCSTR} FORCE)
640 # Above, we have to force the set in case the find failed the last
641 # configure in which case this cache var will be empty. NOTE: If the
642 # user specified a non-empty TPL_${TPL_NAME}_INCLUDE_DIRS, then we would
643 # never get here in the first place!
644
645 if (NOT TPL_${TPL_NAME}_INCLUDE_DIRS OR NOT _${TPL_NAME}_ENABLE_SUCCESS)
646 message(
647 "-- ERROR: Could not find the include directories for TPL '${TPL_NAME}'!")
648 message(
649 "-- TIP: If the TPL '${TPL_NAME}' is on your system then you can set:\n"
650 " -D${TPL_NAME}_INCLUDE_DIRS='<dir0>;<dir1>;...'\n"
651 " to point to directories where these header files may be found.\n"
652 " Or, just set:\n"
653 " -DTPL_${TPL_NAME}_INCLUDE_DIRS='<dir0>;<dir1>;...'\n"
654 " to point to the include directories which will bypass any search for\n"
655 " header files and these include directories will be used without\n"
656 " question in the build. (But this will result in a build-time error\n"
657 " obviously if the necessary header files are not found in these\n"
658 " include directories.)")
659 tribits_tpl_find_include_dirs_and_libraries_handle_fail()
660 endif()
661
662 if (TPL_${TPL_NAME}_INCLUDE_DIRS)
663 message("-- Found TPL '${TPL_NAME}' include dirs '${TPL_${TPL_NAME}_INCLUDE_DIRS}'")
664 endif()
665 else()
666
667 # TPL_${TPL_NAME}_INCLUDE_DIRS is already in the cache so leave it alone!
668
669 endif()
670
671 # Print the final value to be used *always*
672 message("-- TPL_${TPL_NAME}_INCLUDE_DIRS='${TPL_${TPL_NAME}_INCLUDE_DIRS}'")
673
674 else()
675
676 if (${TPL_NAME}_INCLUDE_DIRS)
677 advanced_set(TPL_${TPL_NAME}_INCLUDE_DIRS ${${TPL_NAME}_INCLUDE_DIRS}
678 CACHE PATH "User provided include dirs in the absence of include files.")
679 else()
680 if ("${TPL_${TPL_NAME}_INCLUDE_DIRS}" STREQUAL "")
681 # Library has no header files, no user override, so just set them to
682 # null (unless the user has already set this).
683 global_null_set(TPL_${TPL_NAME}_INCLUDE_DIRS)
684 endif()
685 endif()
686
687 endif()
688
689 # Set library directories to null always. We do this because
690 # the package support code expects this variable and it is used
691 # for package dependencies. Therefore, we need it to allow
692 # TPLs and internal packages to be treated in the same way.
693 global_null_set(TPL_${TPL_NAME}_LIBRARY_DIRS)
694
695 if (TRIBITS_TPL_FIND_INCLUDE_DIRS_AND_LIBRARIES_VERBOSE)
696 print_var(TPL_${TPL_NAME}_LIBRARY_DIRS)
697 endif()
698 # 2011/05/09: rabartl: ToDo: Remove this above variable from everywhere!
699
700 #print_var(TPL_TENTATIVE_ENABLE_${TPL_NAME})
701 #print_var(_${TPL_NAME}_ENABLE_SUCCESS)
702 if (TPL_TENTATIVE_ENABLE_${TPL_NAME})
703 if (_${TPL_NAME}_ENABLE_SUCCESS)
704 if (NOT PARSE_NO_PRINT_ENABLE_SUCCESS_FAIL)
705 message("-- Attempt to tentatively enable TPL '${TPL_NAME}' passed!")
706 endif()
707 else()
708 if (NOT PARSE_NO_PRINT_ENABLE_SUCCESS_FAIL)
709 message("-- Attempt to tentatively enable TPL '${TPL_NAME}' failed!"
710 " Setting TPL_ENABLE_${TPL_NAME}=OFF")
711 endif()
712 set(TPL_ENABLE_${TPL_NAME} OFF CACHE STRING
713 "Forced off since tentative enable failed!" FORCE)
714 endif()
715 endif()
716
717 if (_${TPL_NAME}_ENABLE_SUCCESS)
718 global_set(TPL_${TPL_NAME}_NOT_FOUND FALSE)
719 endif()
720
721 set(buildDirExternalPkgsDir
722 "${${PROJECT_NAME}_BINARY_DIR}/${${PROJECT_NAME}_BUILD_DIR_EXTERNAL_PKGS_DIR}")
723 set(tplConfigFileBaseDir "${buildDirExternalPkgsDir}/${TPL_NAME}")
724 set(tplConfigFile "${tplConfigFileBaseDir}/${TPL_NAME}Config.cmake")
725 tribits_extpkg_write_config_file(${TPL_NAME} "${tplConfigFile}")
726 if (NOT ${PROJECT_NAME}_ENABLE_INSTALLATION_TESTING)
727 include("${tplConfigFile}")
728 endif()
729 # NOTE: The file <tplName>ConfigVersion.cmake will get created elsewhere as
730 # will the install targets for the files <tplName>Config and
731 # <tplName>ConfigVersion.cmake.
732
733 endfunction()
734
735
736 # @FUNCTION: tribits_tpl_tentatively_enable()
737 #
738 # Function that sets up for an optionally enabled TPL that is attempted to be
739 # enabled but will be disabled if all of the parts are not found.
740 #
741 # Usage::
742 #
743 # tribits_tpl_tentatively_enable(<tplName>)
744 #
745 # This function can be called from any CMakeLists.txt file to put a TPL in
746 # tentative enable mode. But typically, it is called from an Package's
747 # `<packageDir>/cmake/Dependencies.cmake`_ file (see `How to tentatively
748 # enable an external package/TPL`_).
749 #
750 # This should only be used for optional TPLs. It will not work correctly for
751 # required TPLs because any enabled packages that require this TPL will not be
752 # disabled and instead will fail to configure or fail to build.
753 #
754 # All this function does is to force set ``TPL_ENABLE_<tplName>=ON`` if it has
755 # not already been set, and sets ``TPL_TENTATIVE_ENABLE_<tplName>=ON`` in the
756 # cache.
757 #
758 # NOTE: This function will only tentatively enable a TPL if its enable has not
759 # be explicitly set on input, i.e. if ``-D TPL_ENABLE_<tplName>=""``. If the
760 # TPL has been explicitly enabled (i.e. ``-D TPL_ENABLE_<tplName>=ON``) or
761 # disabled (i.e. ``-D TPL_ENABLE_<tplName>=OFF``), then this function has no
762 # effect and the TPL will be unconditionally enabled or disabled.
763 #
764 function(tribits_tpl_tentatively_enable TPL_NAME)
765
766 if ("${TPL_ENABLE_${TPL_NAME}}" STREQUAL "")
767 # The TPL's enable status has not been set so tentatively enable it.
768 set(TPL_ENABLE_${TPL_NAME} ON CACHE STRING
769 "Set by tribits_tpl_tentatively_enable()" FORCE)
770 advanced_set(TPL_TENTATIVE_ENABLE_${TPL_NAME} ON CACHE STRING
771 "Set by tribits_tpl_tentatively_enable()" FORCE)
772 else()
773 # The TPL's enable status has already be hard set to be ON or OFF so we
774 # will leave it alone.
775 endif()
776
777 endfunction()
778
779
780 # Set find error and print error message
781 #
782 macro(tribits_tpl_find_include_dirs_and_libraries_handle_fail)
783 set(_${TPL_NAME}_ENABLE_SUCCESS FALSE)
784 global_set(TPL_${TPL_NAME}_NOT_FOUND TRUE)
785 message(
786 "-- ERROR: Failed finding all of the parts of TPL '${TPL_NAME}' (see above), Aborting!\n" )
787 if ("${ERROR_MSG_MODE}" STREQUAL "SEND_ERROR")
788 #message("ERROR_MSG_MODE=SEND_ERROR, Aborting")
789 return()
790 endif()
791 endmacro()