# @HEADER # ***************************************************************************** # TriBITS: Tribal Build, Integrate, and Test System # # Copyright 2013-2016 NTESS and the TriBITS contributors. # SPDX-License-Identifier: BSD-3-Clause # ***************************************************************************** # @HEADER ################################################################################ # # Module TribitsExternalPackageWithImportedTargetsFindTplModuleHelpers.cmake # # Contains functions for implementing FindTPL.cmake files for # external packages using find_package() that producing modern # IMPORTED targets. # # NOTE: The acronym 'extpkgwit' stands for "External Package With Imported # Targets". # ################################################################################ include(TribitsExternalPackageWriteConfigFile) # @FUNCTION: tribits_extpkg_create_imported_all_libs_target_and_config_file() # # Called from a `FindTPL.cmake`_ module which first calls # ``find_package()``and the calls this function to get and # external package that uses modern CMake IMPORTED targets. This function # creates the ``::all_libs`` target and creates a TriBITS-compliant # external package wrapper file `Config.cmake`. # # Usage:: # # tribits_extpkg_create_imported_all_libs_target_and_config_file( # # INNER_FIND_PACKAGE_NAME # IMPORTED_TARGETS_FOR_ALL_LIBS ... ) # # This function is called from a TriBITS ``FindTPL.cmake`` wrapper # module after it calls ``find_package()`` and then this function # creates the IMPORTED target ``::all_libs`` from the list of # IMPORTED targets `` ...`` which are # defined from the call ``find_package()``. This function also # takes care of generating the correct ``Config.cmake`` file under # the directory:: # # ${${PROJECT_NAME}_BINARY_DIR}/${${PROJECT_NAME}_BUILD_DIR_EXTERNAL_PKGS_DIR} # # The generated ``Config.cmake`` file pulls in the upstream # TriBITS-compliant ``Config.cmake` files, calls # ``find_dependency()`` (with no other arguments), defines the # `::all_libs`` target, and then sets up the correct dependencies # between these targets. # # For more details, see `Creating FindTPL.cmake using find_package() # with IMPORTED targets`_. # function(tribits_extpkg_create_imported_all_libs_target_and_config_file tplName ) # Parse arguments cmake_parse_arguments( PARSE_ARGV 1 PARSE "" "" # prefix, options, one_value_keywords "INNER_FIND_PACKAGE_NAME;IMPORTED_TARGETS_FOR_ALL_LIBS" #multi_value_keywords ) tribits_check_for_unparsed_arguments(PARSE) tribits_assert_parse_arg_one_value(PARSE INNER_FIND_PACKAGE_NAME) tribits_assert_parse_arg_one_or_more_values(PARSE IMPORTED_TARGETS_FOR_ALL_LIBS) # Create imported target ::all_libs add_library(${tplName}::all_libs INTERFACE IMPORTED GLOBAL) foreach (importedTarget IN LISTS PARSE_IMPORTED_TARGETS_FOR_ALL_LIBS) target_link_libraries(${tplName}::all_libs INTERFACE ${importedTarget}) endforeach() # Create the TriBITS-compliant Config.cmake wrapper file tribits_extpkgwit_create_package_config_file( ${tplName} INNER_FIND_PACKAGE_NAME ${PARSE_INNER_FIND_PACKAGE_NAME} IMPORTED_TARGETS_FOR_ALL_LIBS ${PARSE_IMPORTED_TARGETS_FOR_ALL_LIBS} ) endfunction()