-
Notifications
You must be signed in to change notification settings - Fork 213
/
CreateImportedTarget.cmake
67 lines (61 loc) · 1.9 KB
/
CreateImportedTarget.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# - A smarter replacement for list(REMOVE_DUPLICATES) for library lists
#
# create_imported_target(<libname> [SHARED|STATIC|MODULE] [<library dependency>...]) - where
# ${libname}_LIBRARIES is set to this library's paths.
#
# Removes duplicates from the list then sorts while preserving "optimized",
# "debug", and "general" labeling
#
# Requires CMake 2.6 or newer (uses the 'function' command)
#
# Original Author:
# 2009-2010 Rylie Pavlik <[email protected]>
# https://ryliepavlik.com/
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright 2009-2010, Iowa State University
#
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
#
# SPDX-License-Identifier: BSL-1.0
if(__create_imported_target)
return()
endif()
set(__create_imported_target YES)
function(create_imported_target _libname)
if(ARGN)
list(FIND ARGN SHARED _target_shared)
list(FIND ARGN STATIC _target_static)
list(FIND ARGN MODULE _target_module)
if(${_target_shared} GREATER -1)
set(_target_type SHARED)
elseif(${_target_static} GREATER -1)
set(_target_type STATIC)
elseif(${_target_module} GREATER -1)
set(_target_type MODULE)
else()
set(_target_type UNKNOWN)
endif()
set(_deps ${ARGN})
list(REMOVE_ITEM _deps SHARED STATIC MODULE UNKNOWN)
else()
set(_target_type UNKNOWN)
set(_deps)
endif()
if(${_libname}_LIBRARIES AND NOT TARGET ${_libname}_imported)
add_library(${_libname}_imported ${_target_type} IMPORTED)
#message(STATUS "Library ${_libname}: lib ${${_libname}_LIBRARIES}")
#message(STATUS "Deps: ${_deps}")
set_target_properties(${_libname}_imported
PROPERTIES
IMPORTED_LOCATION
"${${_libname}_LIBRARIES}"
IMPORTED_LINK_INTERFACE_LIBRARIES
"${_deps}")
endif()
if(TARGET ${_libname}_imported)
set(${_libname}_LIBRARIES ${_libname}_imported PARENT_SCOPE)
endif()
endfunction()