-
Notifications
You must be signed in to change notification settings - Fork 119
/
ament_cmake_export_libraries-extras.cmake.in
140 lines (128 loc) · 4.99 KB
/
ament_cmake_export_libraries-extras.cmake.in
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# generated from ament_cmake_export_libraries/cmake/template/ament_cmake_export_libraries.cmake.in
set(_exported_libraries "@_AMENT_EXPORT_LIBRARIES@")
set(_exported_library_names "@_AMENT_EXPORT_LIBRARY_NAMES@")
# populate @PROJECT_NAME@_LIBRARIES
if(NOT _exported_libraries STREQUAL "")
# loop over libraries, either target names or absolute paths
list(LENGTH _exported_libraries _length)
set(_i 0)
while(_i LESS _length)
list(GET _exported_libraries ${_i} _arg)
# pass linker flags along
if("${_arg}" MATCHES "^-" AND NOT "${_arg}" MATCHES "^-[l|framework]")
list(APPEND @PROJECT_NAME@_LIBRARIES "${_arg}")
math(EXPR _i "${_i} + 1")
continue()
endif()
if("${_arg}" MATCHES "^(debug|optimized|general)$")
# remember build configuration keyword
# and get following library
set(_cfg "${_arg}")
math(EXPR _i "${_i} + 1")
if(_i EQUAL _length)
message(FATAL_ERROR "Package '@PROJECT_NAME@' passes the build configuration keyword '${_cfg}' as the last exported library")
endif()
list(GET _exported_libraries ${_i} _library)
else()
# the value is a library without a build configuration keyword
set(_cfg "")
set(_library "${_arg}")
endif()
math(EXPR _i "${_i} + 1")
if(NOT IS_ABSOLUTE "${_library}")
# search for library target relative to this CMake file
set(_lib "NOTFOUND")
find_library(
_lib NAMES "${_library}"
PATHS "${@PROJECT_NAME@_DIR}/../../../lib"
NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH
)
if(NOT _lib)
# warn about not existing library and ignore it
message(FATAL_ERROR "Package '@PROJECT_NAME@' exports the library '${_library}' which couldn't be found")
elseif(NOT IS_ABSOLUTE "${_lib}")
# the found library must be an absolute path
message(FATAL_ERROR "Package '@PROJECT_NAME@' found the library '${_library}' at '${_lib}' which is not an absolute path")
elseif(NOT EXISTS "${_lib}")
# the found library must exist
message(FATAL_ERROR "Package '@PROJECT_NAME@' found the library '${_lib}' which doesn't exist")
else()
list(APPEND @PROJECT_NAME@_LIBRARIES ${_cfg} "${_lib}")
endif()
else()
if(NOT EXISTS "${_library}")
# the found library must exist
message(WARNING "Package '@PROJECT_NAME@' exports the library '${_library}' which doesn't exist")
else()
list(APPEND @PROJECT_NAME@_LIBRARIES ${_cfg} "${_library}")
endif()
endif()
endwhile()
endif()
# find_library() library names with optional LIBRARY_DIRS
# and add the libraries to @PROJECT_NAME@_LIBRARIES
if(NOT _exported_library_names STREQUAL "")
# loop over library names
# but remember related build configuration keyword if available
list(LENGTH _exported_library_names _length)
set(_i 0)
while(_i LESS _length)
list(GET _exported_library_names ${_i} _arg)
# pass linker flags along
if("${_arg}" MATCHES "^-" AND NOT "${_arg}" MATCHES "^-[l|framework]")
list(APPEND @PROJECT_NAME@_LIBRARIES "${_arg}")
math(EXPR _i "${_i} + 1")
continue()
endif()
if("${_arg}" MATCHES "^(debug|optimized|general)$")
# remember build configuration keyword
# and get following library name
set(_cfg "${_arg}")
math(EXPR _i "${_i} + 1")
if(_i EQUAL _length)
message(FATAL_ERROR "Package '@PROJECT_NAME@' passes the build configuration keyword '${_cfg}' as the last exported target")
endif()
list(GET _exported_library_names ${_i} _library)
else()
# the value is a library target without a build configuration keyword
set(_cfg "")
set(_library "${_arg}")
endif()
math(EXPR _i "${_i} + 1")
# extract optional LIBRARY_DIRS from library name
string(REPLACE ":" ";" _library_dirs "${_library}")
list(GET _library_dirs 0 _library_name)
list(REMOVE_AT _library_dirs 0)
set(_lib "NOTFOUND")
if(NOT _library_dirs)
# search for library in the common locations
find_library(
_lib
NAMES "${_library_name}"
)
if(NOT _lib)
# warn about not existing library and later ignore it
message(WARNING "Package '@PROJECT_NAME@' exports library '${_library_name}' which couldn't be found")
endif()
else()
# search for library in the specified directories
find_library(
_lib
NAMES "${_library_name}"
PATHS ${_library_dirs}
NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH
)
if(NOT _lib)
# warn about not existing library and later ignore it
message(WARNING "Package '@PROJECT_NAME@' exports library '${_library_name}' with LIBRARY_DIRS '${_library_dirs}' which couldn't be found")
endif()
endif()
if(_lib)
list(APPEND @PROJECT_NAME@_LIBRARIES ${_cfg} "${_lib}")
endif()
endwhile()
endif()
# TODO(dirk-thomas) deduplicate @PROJECT_NAME@_LIBRARIES
# while maintaining library order
# as well as build configuration keywords
# as well as linker flags