| 1 |
# -*- mode: cmake -*- |
| 2 |
# @HEADER |
| 3 |
# ***************************************************************************** |
| 4 |
# TriBITS: Tribal Build, Integrate, and Test System |
| 5 |
# |
| 6 |
# Copyright 2013-2016 NTESS and the TriBITS contributors. |
| 7 |
# SPDX-License-Identifier: BSD-3-Clause |
| 8 |
# ***************************************************************************** |
| 9 |
# @HEADER |
| 10 |
# |
| 11 |
# Based on version from MSTK project which has the following: |
| 12 |
# ACKNOWLEDGEMENT: |
| 13 |
# This capability was developed for the Amanzi code base under the DOE/ASCEM |
| 14 |
# project and used here in the MSTK project owing to its open source BSD license |
| 15 |
# Many thanks to the Amanzi build system developers |
| 16 |
# |
| 17 |
|
| 18 |
# |
| 19 |
# Print variable |
| 20 |
# |
| 21 |
# |
| 22 |
# add_imported_library(name [SHARED | STATIC] |
| 23 |
# LOCATION <path> |
| 24 |
# [ LINK_LANGUAGES <lang1> <lang2> <lang3> ... ] |
| 25 |
# [ LINK_INTERFACE_LIBRARIES <lib1> <lib2> ... ] |
| 26 |
# ) |
| 27 |
# |
| 28 |
# |
| 29 |
|
| 30 |
include(CMakeParseArguments) |
| 31 |
function(add_imported_library target_name) |
| 32 |
|
| 33 |
set(_options SHARED STATIC) |
| 34 |
set(_oneValueArgs LOCATION) |
| 35 |
set(_multiValueArgs LINK_LANGUAGES LINK_INTERFACE_LIBRARIES) |
| 36 |
|
| 37 |
cmake_parse_arguments(PARSE "${_options}" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN} ) |
| 38 |
|
| 39 |
# --- Check what has been passed in |
| 40 |
|
| 41 |
# SHARED and STATIC can not be set at the same time |
| 42 |
if ( "${PARSE_STATIC}" AND "${PARSE_SHARED}" ) |
| 43 |
message(FATAL_ERROR "Can not specify imported library as shared and static.") |
| 44 |
endif() |
| 45 |
|
| 46 |
# Require a location |
| 47 |
if ( NOT PARSE_LOCATION ) |
| 48 |
message(FATAL_ERROR "Must specify a location to define an imported library target.") |
| 49 |
endif() |
| 50 |
|
| 51 |
# Check to see if name already exists as a target |
| 52 |
if ( NOT TARGET "${target_name}" ) |
| 53 |
|
| 54 |
# --- Set the library type |
| 55 |
set(lib_type UNKNOWN) |
| 56 |
if(PARSE_STATIC) |
| 57 |
set(lib_type STATIC) |
| 58 |
endif() |
| 59 |
if(PARSE_SHARED) |
| 60 |
set(lib_type SHARED) |
| 61 |
endif() |
| 62 |
|
| 63 |
# --- Add the library target |
| 64 |
add_library(${target_name} ${lib_type} IMPORTED) |
| 65 |
|
| 66 |
# --- Update the global property that tracks imported targets |
| 67 |
set(prop_name IMPORTED_${lib_type}_LIBRARIES) |
| 68 |
get_property(prop_value GLOBAL PROPERTY ${prop_name}) |
| 69 |
set_property(GLOBAL PROPERTY ${prop_name} ${prop_value} ${target_name}) |
| 70 |
|
| 71 |
# --- Set the properties |
| 72 |
set_target_properties(${target_name} PROPERTIES |
| 73 |
IMPORTED_LOCATION ${PARSE_LOCATION}) |
| 74 |
if ( PARSE_LINK_LANGUAGES ) |
| 75 |
set_target_properties(${target_name} PROPERTIES |
| 76 |
IMPORTED_LINK_INTERFACE_LANGUAGES "${PARSE_LINK_LANGUAGES}") |
| 77 |
endif() |
| 78 |
if ( PARSE_LINK_INTERFACE_LIBRARIES ) |
| 79 |
set_target_properties(${target_name} PROPERTIES |
| 80 |
IMPORTED_LINK_INTERFACE_LIBRARIES "${PARSE_LINK_INTERFACE_LIBRARIES}") |
| 81 |
endif() |
| 82 |
|
| 83 |
endif() |
| 84 |
endfunction() |
| 85 |
|