| 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 |
################################################################################ |
| 12 |
# |
| 13 |
# Module TribitsExternalPackageWithImportedTargetsFindTplModuleHelpers.cmake |
| 14 |
# |
| 15 |
# Contains functions for implementing FindTPL<tplName>.cmake files for |
| 16 |
# external packages using find_package(<externalPkg>) that producing modern |
| 17 |
# IMPORTED targets. |
| 18 |
# |
| 19 |
# NOTE: The acronym 'extpkgwit' stands for "External Package With Imported |
| 20 |
# Targets". |
| 21 |
# |
| 22 |
################################################################################ |
| 23 |
|
| 24 |
|
| 25 |
include(TribitsExternalPackageWriteConfigFile) |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
# @FUNCTION: tribits_extpkg_create_imported_all_libs_target_and_config_file() |
| 30 |
# |
| 31 |
# Called from a `FindTPL<tplName>.cmake`_ module which first calls |
| 32 |
# ``find_package(<externalPkg>)``and the calls this function to get and |
| 33 |
# external package that uses modern CMake IMPORTED targets. This function |
| 34 |
# creates the ``<tplName>::all_libs`` target and creates a TriBITS-compliant |
| 35 |
# external package wrapper file `<tplName>Config.cmake`. |
| 36 |
# |
| 37 |
# Usage:: |
| 38 |
# |
| 39 |
# tribits_extpkg_create_imported_all_libs_target_and_config_file( |
| 40 |
# <tplName> |
| 41 |
# INNER_FIND_PACKAGE_NAME <externalPkg> |
| 42 |
# IMPORTED_TARGETS_FOR_ALL_LIBS <importedTarget0> <importedTarget1> ... ) |
| 43 |
# |
| 44 |
# This function is called from a TriBITS ``FindTPL<tplName>.cmake`` wrapper |
| 45 |
# module after it calls ``find_package(<externalPkg>)`` and then this function |
| 46 |
# creates the IMPORTED target ``<tplName>::all_libs`` from the list of |
| 47 |
# IMPORTED targets ``<importedTarget0> <importedTarget1> ...`` which are |
| 48 |
# defined from the call ``find_package(<externalPkg>)``. This function also |
| 49 |
# takes care of generating the correct ``<tplName>Config.cmake`` file under |
| 50 |
# the directory:: |
| 51 |
# |
| 52 |
# ${${PROJECT_NAME}_BINARY_DIR}/${${PROJECT_NAME}_BUILD_DIR_EXTERNAL_PKGS_DIR} |
| 53 |
# |
| 54 |
# The generated ``<tplName>Config.cmake`` file pulls in the upstream |
| 55 |
# TriBITS-compliant ``<UpstreamPkg>Config.cmake` files, calls |
| 56 |
# ``find_dependency(<externalPkg>)`` (with no other arguments), defines the |
| 57 |
# `<tplName>::all_libs`` target, and then sets up the correct dependencies |
| 58 |
# between these targets. |
| 59 |
# |
| 60 |
# For more details, see `Creating FindTPL<tplName>.cmake using find_package() |
| 61 |
# with IMPORTED targets`_. |
| 62 |
# |
| 63 |
function(tribits_extpkg_create_imported_all_libs_target_and_config_file |
| 64 |
tplName |
| 65 |
) |
| 66 |
|
| 67 |
# Parse arguments |
| 68 |
cmake_parse_arguments( |
| 69 |
PARSE_ARGV 1 |
| 70 |
PARSE "" "" # prefix, options, one_value_keywords |
| 71 |
"INNER_FIND_PACKAGE_NAME;IMPORTED_TARGETS_FOR_ALL_LIBS" #multi_value_keywords |
| 72 |
) |
| 73 |
tribits_check_for_unparsed_arguments(PARSE) |
| 74 |
tribits_assert_parse_arg_one_value(PARSE INNER_FIND_PACKAGE_NAME) |
| 75 |
tribits_assert_parse_arg_one_or_more_values(PARSE IMPORTED_TARGETS_FOR_ALL_LIBS) |
| 76 |
|
| 77 |
# Create imported target <tplName>::all_libs |
| 78 |
add_library(${tplName}::all_libs INTERFACE IMPORTED GLOBAL) |
| 79 |
foreach (importedTarget IN LISTS PARSE_IMPORTED_TARGETS_FOR_ALL_LIBS) |
| 80 |
target_link_libraries(${tplName}::all_libs INTERFACE ${importedTarget}) |
| 81 |
endforeach() |
| 82 |
|
| 83 |
# Create the TriBITS-compliant <tplName>Config.cmake wrapper file |
| 84 |
tribits_extpkgwit_create_package_config_file( |
| 85 |
${tplName} |
| 86 |
INNER_FIND_PACKAGE_NAME ${PARSE_INNER_FIND_PACKAGE_NAME} |
| 87 |
IMPORTED_TARGETS_FOR_ALL_LIBS ${PARSE_IMPORTED_TARGETS_FOR_ALL_LIBS} ) |
| 88 |
|
| 89 |
endfunction() |