forked from conan-io/conan
/
targets.py
68 lines (51 loc) · 2.27 KB
/
targets.py
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
68
import textwrap
from conan.tools.cmake.cmakedeps.templates import CMakeDepsFileTemplate
"""
FooTargets.cmake
"""
class TargetsTemplate(CMakeDepsFileTemplate):
@property
def filename(self):
name = "" if not self.find_module_mode else "module-"
name += self.file_name + "Targets.cmake"
return name
@property
def context(self):
data_pattern = "${_DIR}/" if not self.find_module_mode else "${_DIR}/module-"
data_pattern += "{}-*-data.cmake".format(self.file_name)
target_pattern = "" if not self.find_module_mode else "module-"
target_pattern += "{}-Target-*.cmake".format(self.file_name)
ret = {"pkg_name": self.pkg_name,
"target_namespace": self.target_namespace,
"global_target_name": self.global_target_name,
"file_name": self.file_name,
"data_pattern": data_pattern,
"target_pattern": target_pattern}
return ret
@property
def template(self):
return textwrap.dedent("""\
# Load the debug and release variables
get_filename_component(_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
file(GLOB DATA_FILES "{{data_pattern}}")
foreach(f ${DATA_FILES})
include(${f})
endforeach()
# Create the targets for all the components
foreach(_COMPONENT {{ '${' + pkg_name + '_COMPONENT_NAMES' + '}' }} )
if(NOT TARGET {{ target_namespace }}::${_COMPONENT})
add_library({{ target_namespace }}::${_COMPONENT} INTERFACE IMPORTED)
conan_message(STATUS "Conan: Component target declared '{{ target_namespace }}::${_COMPONENT}'")
endif()
endforeach()
if(NOT TARGET {{ target_namespace }}::{{ global_target_name }})
add_library({{ target_namespace }}::{{ global_target_name }} INTERFACE IMPORTED)
conan_message(STATUS "Conan: Target declared '{{ target_namespace }}::{{ global_target_name }}'")
endif()
# Load the debug and release library finders
get_filename_component(_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
file(GLOB CONFIG_FILES "${_DIR}/{{ target_pattern }}")
foreach(f ${CONFIG_FILES})
include(${f})
endforeach()
""")