-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathBoostWriteCMakeImportFiles.cmake.in
252 lines (215 loc) · 8.62 KB
/
BoostWriteCMakeImportFiles.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# - List all dynamic libraries installed by the Boost port
# Simply glob the lib/root directory for .so/.dylib files
# Implemented as a CMake script so we can run it post-install of the
# root port. It will generate a file that can be used by the
# library depends file to create imported targets
#
#-----------------------------------------------------------------------
# FUNCTIONS FOR WRITING "XXXLibraryDepends-MODE.cmake" FILES
#-----------------------------------------------------------------------
# Write header for library import file
#
function(make_import_header var mode)
set(${var} "
# - Imported targets for Boost port in mode '${mode}'
# Generally copies CMake's autogenerated version
#
# Commands may need to know the format version.
SET(CMAKE_IMPORT_FILE_VERSION 1)
# Compute the installation prefix relative to this file.
GET_FILENAME_COMPONENT(_IMPORT_PREFIX \"\${CMAKE_CURRENT_LIST_FILE}\" PATH)
GET_FILENAME_COMPONENT(_IMPORT_PREFIX \"\${_IMPORT_PREFIX}\" PATH)
GET_FILENAME_COMPONENT(_IMPORT_PREFIX \"\${_IMPORT_PREFIX}\" PATH)
GET_FILENAME_COMPONENT(_IMPORT_PREFIX \"\${_IMPORT_PREFIX}\" PATH)
"
PARENT_SCOPE
)
endfunction()
#-----------------------------------------------------------------------
# Write footer for library import file
#
function(make_import_footer var)
set(${var} "
# Loop over all imported files and verify that they actually exist
FOREACH(target \${_IMPORT_CHECK_TARGETS} )
FOREACH(file \${_IMPORT_CHECK_FILES_FOR_\${target}} )
IF(NOT EXISTS \"\${file}\" )
MESSAGE(FATAL_ERROR \"The imported target '\${target}' references the file
'\${file}'
but this file does not exist. Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
'\${CMAKE_CURRENT_LIST_FILE}'
but not all the files it references.
\")
ENDIF()
ENDFOREACH()
UNSET(_IMPORT_CHECK_FILES_FOR_\${target})
ENDFOREACH()
UNSET(_IMPORT_CHECK_TARGETS)
# Cleanup temporary variables.
SET(_IMPORT_PREFIX)
# Commands beyond this point should not need to know the version.
SET(CMAKE_IMPORT_FILE_VERSION)
"
PARENT_SCOPE
)
endfunction()
#-----------------------------------------------------------------------
# Template for import stanza
function(make_import_target var target lib mode)
string(TOUPPER "${mode}" mode)
set(${var} "
# Import target \"${target}\" for configuration \"${mode}\"
SET_PROPERTY(TARGET ${target} APPEND PROPERTY IMPORTED_CONFIGURATIONS ${mode})
SET_TARGET_PROPERTIES(${target} PROPERTIES
IMPORTED_LOCATION_${mode} \"\${_IMPORT_PREFIX}/lib/${lib}\"
)
LIST(APPEND _IMPORT_CHECK_TARGETS ${target} )
LIST(APPEND _IMPORT_CHECK_FILES_FOR_${target} \"\${_IMPORT_PREFIX}/lib/${lib}\")
"
PARENT_SCOPE
) # End stanza
endfunction()
#-----------------------------------------------------------------------
# CUSTOM BOOST LIBDEP FILE WRITER
#-----------------------------------------------------------------------
#
function(write_boost_libdepfile _var _dir _link _thread _variant)
set(_filename "BoostLibraryDepends-${_link}-${_thread}-${_variant}.cmake")
message(STATUS "Writing ${_filename}")
string(TOUPPER "${_link}" _libtype)
if("${_link}" STREQUAL "shared")
set(_libsuffix "@CMAKE_SHARED_LIBRARY_SUFFIX@")
set(_libprefix "@CMAKE_SHARED_LIBRARY_PREFIX@boost_")
else()
set(_libsuffix "@CMAKE_STATIC_LIBRARY_SUFFIX@")
set(_libprefix "@CMAKE_STATIC_LIBRARY_PREFIX@boost_")
endif()
if("${_thread}" STREQUAL "multithread")
set(_libmttag "-mt")
endif()
if("${_variant}" STREQUAL "debug")
set(_libvrtag "-d")
endif()
# Header
make_import_header(_ldheader ${_variant})
# Import config
set(_addimports)
foreach(_comp ${ARGN})
# Write the stanza
# Handle the weird case of boost_thread, which is always -mt
if(_comp STREQUAL "thread" AND NOT _libmttag)
make_import_target(_text boost_${_comp} "${_libprefix}${_comp}-mt${_libvrtag}${_libsuffix}" ${_variant})
else()
make_import_target(_text boost_${_comp} "${_libprefix}${_comp}${_libmttag}${_libvrtag}${_libsuffix}" ${_variant})
endif()
set(_addimports "${_addimports}${_text}")
# Here's where we'd need to handle any link dependencies
# e.g. filesystem => system etc
endforeach()
# Footer
make_import_footer(_ldfooter)
# Write the file
file(WRITE "${_dir}/${_filename}" "${_ldheader}${_addimports}${_ldfooter}")
set(${_var} "${_dir}/${_filename}" PARENT_SCOPE)
endfunction()
#-----------------------------------------------------------------------
# PROCESSING
#-----------------------------------------------------------------------
# Configure the various options...
set(OUTPUT_DIR "@PROJECT_BINARY_DIR@")
set(CMAKE_BUILD_TYPE "@CMAKE_BUILD_TYPE@")
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "noconfig")
endif()
set(BOOST_LIBDIR "@CMAKE_INSTALL_PREFIX@/lib")
set(BOOST_CMAKEDIR "${BOOST_LIBDIR}/cmake/Boost-@Boost_VERSION@")
set(BOOST_LIBPREFIX "@CMAKE_SHARED_LIBRARY_PREFIX@")
set(BOOST_SHARED_LIBSUFFIX "@CMAKE_SHARED_LIBRARY_SUFFIX@")
set(BOOST_STATIC_LIBSUFFIX "@CMAKE_STATIC_LIBRARY_SUFFIX@")
set(BOOST_THREADING_MODELS multithread)
set(BOOST_HAS_ST @boost.singlethread@)
if(BOOST_HAS_ST)
list(APPEND BOOST_THREADING_MODELS singlethread)
endif()
set(BOOST_HAS_STATIC @boost.staticlibs@)
set(BOOST_LINKING_MODELS shared)
if(BOOST_HAS_STATIC)
list(APPEND BOOST_LINKING_MODELS static)
endif()
set(BOOST_HAS_DEBUG @boost.debuglibs@)
set(BOOST_VARIANT_MODELS release)
if(BOOST_HAS_DEBUG)
list(APPEND BOOST_VARIANT_MODELS debug)
endif()
#-----------------------------------------------------------------------
# Determine which components were installed
# This is really the key to the whole file - hence the slight tricks
# with the globbing and regexing!
set(BOOST_COMPONENTS)
file(GLOB BOOST_COMPONENTS RELATIVE "${BOOST_LIBDIR}" "${BOOST_LIBDIR}/${BOOST_LIBPREFIX}boost_*${BOOST_SHARED_LIBSUFFIX}")
string(REPLACE "${BOOST_SHARED_LIBSUFFIX}" "" BOOST_COMPONENTS "${BOOST_COMPONENTS}")
string(REGEX REPLACE "libboost_|(-d|-mt)" "" BOOST_COMPONENTS "${BOOST_COMPONENTS}")
list(REMOVE_DUPLICATES BOOST_COMPONENTS)
#-----------------------------------------------------------------------
# The structure of the libdeps file is as follows:
# Boost_USE_MULTITHREADED (if on use -mt libs)
# Boost_USE_STATIC_LIBS (if on use static libs)
#
# The setting of these would need to make the top level config fall over
# if the given model isn't supported.
#
# So the config file needs to load:
#
# include("${__cfl_boost_config_dir}/BoostLibraryDepends-<libtype>-<threadingmodel>.cmake
#
# That file in turn needs to load
# BoostLibraryDepends-<libtype>-<threadingmodel>-*.cmake
#
# So here we'd have the release and debug files
#
# So a full build would have
# the following main libdeps files, and their nested loads based on mode
# BoostLibraryDepends-shared-singlethread.cmake
# BoostLibraryDepends-shared-singlethread-Release.cmake
# BoostLibraryDepends-shared-singlethread-Debug.cmake
# BoostLibraryDepends-shared-multithread.cmake
# BoostLibraryDepends-shared-multithread-Release.cmake
# BoostLibraryDepends-shared-multithread-Debug.cmake
# BoostLibraryDepends-static-singlethread.cmake
# BoostLibraryDepends-static-singlethread-Release.cmake
# BoostLibraryDepends-static-singlethread-Debug.cmake
# BoostLibraryDepends-static-multithread.cmake
# BoostLibraryDepends-static-multithread-Release.cmake
# BoostLibraryDepends-static-multithread-Debug.cmake
#
# That's a lot of files, but the structure is fairly easy to configure
# on the fly
#-----------------------------------------------------------------------
# Create the tree of BoostLibraryDepends files, then install them
#
set(_ldfiles)
foreach(_lm ${BOOST_LINKING_MODELS})
foreach(_tm ${BOOST_THREADING_MODELS})
set(BOOST_LINK_MODEL_TAG ${_lm})
set(BOOST_THREAD_MODEL_TAG ${_tm})
string(TOUPPER ${_lm} BOOST_LINK_MODEL)
# Configure the front end lib depends file for the link+thread
# model
configure_file(@PROJECT_SOURCE_DIR@/BoostLibraryDepends.cmake.in
@PROJECT_BINARY_DIR@/BoostLibraryDepends-${_lm}-${_tm}.cmake
@ONLY
)
list(APPEND _ldfiles @PROJECT_BINARY_DIR@/BoostLibraryDepends-${_lm}-${_tm}.cmake)
foreach(_vm ${BOOST_VARIANT_MODELS})
# Write file for the join of link+thread+variant models
message(STATUS "Writing BoostLibraryDepends-${_lm}-${_tm}-${_vm}.cmake")
write_boost_libdepfile(_fname ${OUTPUT_DIR} ${_lm} ${_tm} ${_vm} ${BOOST_COMPONENTS})
list(APPEND _ldfiles "${_fname}")
endforeach()
endforeach()
endforeach()
message(STATUS "Installing Boost LibraryDepends Files")
file(COPY ${_ldfiles} DESTINATION "${BOOST_CMAKEDIR}")