Skip to content

Commit a9fadb3

Browse files
authored
[runtimes] Modernize installation targets (#171677)
This patch moves away from using cmake_install scripts to install the various targets when building runtimes, since those have been deprecated by CMake. Instead, we use `cmake --install` which is the prefered method. This patch also localizes how we set dependencies on the various installation targets, allowing the removal of a few global variables that were used as lists. Finally, it makes the way we set up installation targets for libc++, libc++abi and libunwind consistent again.
1 parent dd63dff commit a9fadb3

File tree

7 files changed

+92
-106
lines changed

7 files changed

+92
-106
lines changed

libcxx/include/CMakeLists.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,10 +1751,8 @@ if (LIBCXX_INSTALL_HEADERS)
17511751

17521752
if (NOT CMAKE_CONFIGURATION_TYPES)
17531753
add_custom_target(install-cxx-headers
1754-
DEPENDS cxx-headers
1755-
COMMAND "${CMAKE_COMMAND}"
1756-
-DCMAKE_INSTALL_COMPONENT=cxx-headers
1757-
-P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
1754+
DEPENDS cxx-headers
1755+
COMMAND "${CMAKE_COMMAND}" --install "${CMAKE_BINARY_DIR}" --component cxx-headers)
17581756
# Stripping is a no-op for headers
17591757
add_custom_target(install-cxx-headers-stripped DEPENDS install-cxx-headers)
17601758
endif()

libcxx/modules/CMakeLists.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,8 @@ if (LIBCXX_INSTALL_MODULES)
259259

260260
if (NOT CMAKE_CONFIGURATION_TYPES)
261261
add_custom_target(install-cxx-modules
262-
DEPENDS cxx-modules
263-
COMMAND "${CMAKE_COMMAND}"
264-
-DCMAKE_INSTALL_COMPONENT=cxx-modules
265-
-P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
262+
DEPENDS cxx-modules
263+
COMMAND "${CMAKE_COMMAND}" --install "${CMAKE_BINARY_DIR}" --component cxx-modules)
266264
# Stripping is a no-op for modules
267265
add_custom_target(install-cxx-modules-stripped DEPENDS install-cxx-modules)
268266
endif()

libcxx/src/CMakeLists.txt

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,6 @@ if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
244244
)
245245
endif()
246246

247-
if (LIBCXX_ENABLE_SHARED)
248-
list(APPEND LIBCXX_BUILD_TARGETS "cxx_shared")
249-
endif()
250-
251247
if(WIN32 AND NOT MINGW AND NOT "${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
252248
# Since we most likely do not have a mt.exe replacement, disable the
253249
# manifest bundling. This allows a normal cmake invocation to pass which
@@ -295,17 +291,11 @@ if (LIBCXX_HERMETIC_STATIC_LIBRARY)
295291
target_compile_definitions(cxx_static PRIVATE _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS=)
296292
endif()
297293

298-
if (LIBCXX_ENABLE_STATIC)
299-
list(APPEND LIBCXX_BUILD_TARGETS "cxx_static")
300-
endif()
301294
# Attempt to merge the libc++.a archive and the ABI library archive into one.
302295
if (LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY)
303296
target_link_libraries(cxx_static PRIVATE libcxx-abi-static-objects)
304297
endif()
305298

306-
# Add a meta-target for both libraries.
307-
add_custom_target(cxx DEPENDS ${LIBCXX_BUILD_TARGETS})
308-
309299
# Build the experimental static library
310300
set(LIBCXX_EXPERIMENTAL_SOURCES
311301
experimental/keep.cpp
@@ -355,6 +345,15 @@ set_target_properties(cxx_experimental
355345
cxx_add_common_build_flags(cxx_experimental)
356346
target_compile_options(cxx_experimental PUBLIC -D_LIBCPP_ENABLE_EXPERIMENTAL)
357347

348+
# Add a meta-target for both libraries.
349+
add_custom_target(cxx)
350+
if (LIBCXX_ENABLE_SHARED)
351+
add_dependencies(cxx cxx_shared)
352+
endif()
353+
if (LIBCXX_ENABLE_STATIC)
354+
add_dependencies(cxx cxx_static)
355+
endif()
356+
358357
if (LIBCXX_INSTALL_SHARED_LIBRARY)
359358
install(TARGETS cxx_shared
360359
ARCHIVE DESTINATION ${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx
@@ -385,30 +384,26 @@ if (LIBCXX_ENABLE_SHARED AND LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
385384
endif()
386385

387386
if (NOT CMAKE_CONFIGURATION_TYPES)
388-
if(LIBCXX_INSTALL_LIBRARY)
389-
set(lib_install_target "cxx;cxx_experimental")
390-
endif()
391-
if(LIBCXX_INSTALL_HEADERS)
392-
set(header_install_target install-cxx-headers)
393-
endif()
394-
if(LIBCXX_INSTALL_MODULES)
395-
set(module_install_target install-cxx-modules)
396-
endif()
397-
add_custom_target(install-cxx
398-
DEPENDS ${lib_install_target}
399-
cxx_experimental
400-
${header_install_target}
401-
${module_install_target}
402-
COMMAND "${CMAKE_COMMAND}"
403-
-DCMAKE_INSTALL_COMPONENT=cxx
404-
-P "${LIBCXX_BINARY_DIR}/cmake_install.cmake")
405-
add_custom_target(install-cxx-stripped
406-
DEPENDS ${lib_install_target}
407-
cxx_experimental
408-
${header_install_target}
409-
${module_install_target}
410-
COMMAND "${CMAKE_COMMAND}"
411-
-DCMAKE_INSTALL_COMPONENT=cxx
412-
-DCMAKE_INSTALL_DO_STRIP=1
413-
-P "${LIBCXX_BINARY_DIR}/cmake_install.cmake")
387+
add_custom_target(install-cxx
388+
COMMAND "${CMAKE_COMMAND}" --install "${CMAKE_BINARY_DIR}" --component cxx)
389+
add_custom_target(install-cxx-stripped
390+
COMMAND "${CMAKE_COMMAND}" --install "${CMAKE_BINARY_DIR}" --component cxx --strip)
391+
392+
add_dependencies(install-cxx cxx_experimental)
393+
add_dependencies(install-cxx-stripped cxx_experimental)
394+
395+
if (LIBCXX_INSTALL_LIBRARY)
396+
add_dependencies(install-cxx cxx)
397+
add_dependencies(install-cxx-stripped cxx)
398+
endif()
399+
400+
if(LIBCXX_INSTALL_HEADERS)
401+
add_dependencies(install-cxx install-cxx-headers)
402+
add_dependencies(install-cxx-stripped install-cxx-headers-stripped)
403+
endif()
404+
405+
if(LIBCXX_INSTALL_MODULES)
406+
add_dependencies(install-cxx install-cxx-modules)
407+
add_dependencies(install-cxx-stripped install-cxx-modules-stripped)
408+
endif()
414409
endif()

libcxxabi/include/CMakeLists.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@ if (LIBCXXABI_INSTALL_HEADERS)
3030
endforeach()
3131

3232
add_custom_target(install-cxxabi-headers
33-
DEPENDS cxxabi-headers
34-
COMMAND "${CMAKE_COMMAND}"
35-
-DCMAKE_INSTALL_COMPONENT=cxxabi-headers
36-
-P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
33+
DEPENDS cxxabi-headers
34+
COMMAND "${CMAKE_COMMAND}" --install "${CMAKE_BINARY_DIR}" --component cxxabi-headers)
3735
# Stripping is a no-op for headers
3836
add_custom_target(install-cxxabi-headers-stripped DEPENDS install-cxxabi-headers)
3937
endif()

libcxxabi/src/CMakeLists.txt

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,6 @@ target_link_libraries(cxxabi_shared
219219
PUBLIC cxxabi_shared_objects runtimes-libc-shared
220220
PRIVATE ${LIBCXXABI_LIBRARIES})
221221

222-
if (LIBCXXABI_ENABLE_SHARED)
223-
list(APPEND LIBCXXABI_BUILD_TARGETS "cxxabi_shared")
224-
endif()
225-
if (LIBCXXABI_INSTALL_SHARED_LIBRARY)
226-
list(APPEND LIBCXXABI_INSTALL_TARGETS "cxxabi_shared")
227-
endif()
228-
229222
# TODO: Move this to libc++'s HandleLibCXXABI.cmake since this is effectively trying to control
230223
# what libc++ re-exports.
231224
add_library(cxxabi-reexports INTERFACE)
@@ -325,34 +318,42 @@ target_link_libraries(cxxabi_static
325318
PUBLIC cxxabi_static_objects
326319
PRIVATE ${LIBCXXABI_STATIC_LIBRARIES} ${LIBCXXABI_LIBRARIES})
327320

328-
if (LIBCXXABI_ENABLE_STATIC)
329-
list(APPEND LIBCXXABI_BUILD_TARGETS "cxxabi_static")
321+
# Add a meta-target for both libraries.
322+
add_custom_target(cxxabi)
323+
if (LIBCXXABI_ENABLE_SHARED)
324+
add_dependencies(cxxabi cxxabi_shared)
330325
endif()
331-
if (LIBCXXABI_INSTALL_STATIC_LIBRARY)
332-
list(APPEND LIBCXXABI_INSTALL_TARGETS "cxxabi_static")
326+
if (LIBCXXABI_ENABLE_STATIC)
327+
add_dependencies(cxxabi cxxabi_static)
333328
endif()
334329

335-
# Add a meta-target for both libraries.
336-
add_custom_target(cxxabi DEPENDS ${LIBCXXABI_BUILD_TARGETS})
337-
338-
if (LIBCXXABI_INSTALL_LIBRARY)
339-
install(TARGETS ${LIBCXXABI_INSTALL_TARGETS}
330+
if (LIBCXXABI_INSTALL_SHARED_LIBRARY)
331+
install(TARGETS cxxabi_shared
332+
ARCHIVE DESTINATION ${LIBCXXABI_INSTALL_LIBRARY_DIR} COMPONENT cxxabi
340333
LIBRARY DESTINATION ${LIBCXXABI_INSTALL_LIBRARY_DIR} COMPONENT cxxabi
334+
RUNTIME DESTINATION ${LIBCXXABI_INSTALL_RUNTIME_DIR} COMPONENT cxxabi)
335+
endif()
336+
337+
if (LIBCXXABI_INSTALL_STATIC_LIBRARY)
338+
install(TARGETS cxxabi_static
341339
ARCHIVE DESTINATION ${LIBCXXABI_INSTALL_LIBRARY_DIR} COMPONENT cxxabi
342-
RUNTIME DESTINATION ${LIBCXXABI_INSTALL_RUNTIME_DIR} COMPONENT cxxabi
343-
)
340+
LIBRARY DESTINATION ${LIBCXXABI_INSTALL_LIBRARY_DIR} COMPONENT cxxabi
341+
RUNTIME DESTINATION ${LIBCXXABI_INSTALL_RUNTIME_DIR} COMPONENT cxxabi)
344342
endif()
345343

346-
if (NOT CMAKE_CONFIGURATION_TYPES AND LIBCXXABI_INSTALL_LIBRARY)
344+
if (NOT CMAKE_CONFIGURATION_TYPES)
347345
add_custom_target(install-cxxabi
348-
DEPENDS cxxabi install-cxxabi-headers
349-
COMMAND "${CMAKE_COMMAND}"
350-
-DCMAKE_INSTALL_COMPONENT=cxxabi
351-
-P "${LIBCXXABI_BINARY_DIR}/cmake_install.cmake")
346+
COMMAND "${CMAKE_COMMAND}" --install "${CMAKE_BINARY_DIR}" --component cxxabi)
352347
add_custom_target(install-cxxabi-stripped
353-
DEPENDS cxxabi
354-
COMMAND "${CMAKE_COMMAND}"
355-
-DCMAKE_INSTALL_COMPONENT=cxxabi
356-
-DCMAKE_INSTALL_DO_STRIP=1
357-
-P "${LIBCXXABI_BINARY_DIR}/cmake_install.cmake")
348+
COMMAND "${CMAKE_COMMAND}" --install "${CMAKE_BINARY_DIR}" --component cxxabi --strip)
349+
350+
if (LIBCXXABI_INSTALL_LIBRARY)
351+
add_dependencies(install-cxxabi cxxabi)
352+
add_dependencies(install-cxxabi-stripped cxxabi)
353+
endif()
354+
355+
if(LIBCXXABI_INSTALL_HEADERS)
356+
add_dependencies(install-cxxabi install-cxxabi-headers)
357+
add_dependencies(install-cxxabi-stripped install-cxxabi-headers-stripped)
358+
endif()
358359
endif()

libunwind/include/CMakeLists.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,10 @@ if(LIBUNWIND_INSTALL_HEADERS)
2121
)
2222
endforeach()
2323

24-
if(NOT CMAKE_CONFIGURATION_TYPES)
24+
if (NOT CMAKE_CONFIGURATION_TYPES)
2525
add_custom_target(install-unwind-headers
2626
DEPENDS unwind-headers
27-
COMMAND "${CMAKE_COMMAND}"
28-
-DCMAKE_INSTALL_COMPONENT=unwind-headers
29-
-P "${LIBUNWIND_BINARY_DIR}/cmake_install.cmake")
27+
COMMAND "${CMAKE_COMMAND}" --install "${CMAKE_BINARY_DIR}" --component unwind-headers)
3028
add_custom_target(install-unwind-headers-stripped DEPENDS install-unwind-headers)
3129
endif()
3230
endif()

libunwind/src/CMakeLists.txt

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,6 @@ set_target_properties(unwind_shared
159159
SOVERSION "1"
160160
)
161161

162-
if (LIBUNWIND_ENABLE_SHARED)
163-
list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_shared")
164-
endif()
165-
if (LIBUNWIND_INSTALL_SHARED_LIBRARY)
166-
list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_shared")
167-
endif()
168-
169162
# Build the static library.
170163
add_library(unwind_static_objects OBJECT EXCLUDE_FROM_ALL ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS})
171164
cxx_add_warning_flags(unwind_static_objects ${LIBUNWIND_ENABLE_WERROR} ${LIBUNWIND_ENABLE_PEDANTIC})
@@ -205,35 +198,40 @@ set_target_properties(unwind_static
205198
OUTPUT_NAME "${LIBUNWIND_STATIC_OUTPUT_NAME}"
206199
)
207200

208-
if (LIBUNWIND_ENABLE_STATIC)
209-
list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_static")
201+
# Add a meta-target for both libraries.
202+
add_custom_target(unwind)
203+
if (LIBUNWIND_ENABLE_SHARED)
204+
add_dependencies(unwind unwind_shared)
210205
endif()
211-
if (LIBUNWIND_INSTALL_STATIC_LIBRARY)
212-
list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_static")
206+
if (LIBUNWIND_ENABLE_STATIC)
207+
add_dependencies(unwind unwind_static)
213208
endif()
214209

215-
# Add a meta-target for both libraries.
216-
add_custom_target(unwind DEPENDS ${LIBUNWIND_BUILD_TARGETS})
217-
218-
if (LIBUNWIND_INSTALL_LIBRARY)
219-
install(TARGETS ${LIBUNWIND_INSTALL_TARGETS}
210+
if (LIBUNWIND_INSTALL_SHARED_LIBRARY)
211+
install(TARGETS unwind_shared
212+
ARCHIVE DESTINATION ${LIBUNWIND_INSTALL_LIBRARY_DIR} COMPONENT unwind
220213
LIBRARY DESTINATION ${LIBUNWIND_INSTALL_LIBRARY_DIR} COMPONENT unwind
214+
RUNTIME DESTINATION ${LIBUNWIND_INSTALL_RUNTIME_DIR} COMPONENT unwind)
215+
endif()
216+
217+
if (LIBUNWIND_INSTALL_STATIC_LIBRARY)
218+
install(TARGETS unwind_static
221219
ARCHIVE DESTINATION ${LIBUNWIND_INSTALL_LIBRARY_DIR} COMPONENT unwind
220+
LIBRARY DESTINATION ${LIBUNWIND_INSTALL_LIBRARY_DIR} COMPONENT unwind
222221
RUNTIME DESTINATION ${LIBUNWIND_INSTALL_RUNTIME_DIR} COMPONENT unwind)
223222
endif()
224223

225-
if (NOT CMAKE_CONFIGURATION_TYPES AND LIBUNWIND_INSTALL_LIBRARY)
224+
if (NOT CMAKE_CONFIGURATION_TYPES)
226225
add_custom_target(install-unwind
227-
DEPENDS unwind
228-
COMMAND "${CMAKE_COMMAND}"
229-
-DCMAKE_INSTALL_COMPONENT=unwind
230-
-P "${LIBUNWIND_BINARY_DIR}/cmake_install.cmake")
226+
COMMAND "${CMAKE_COMMAND}" --install "${CMAKE_BINARY_DIR}" --component unwind)
231227
add_custom_target(install-unwind-stripped
232-
DEPENDS unwind
233-
COMMAND "${CMAKE_COMMAND}"
234-
-DCMAKE_INSTALL_COMPONENT=unwind
235-
-DCMAKE_INSTALL_DO_STRIP=1
236-
-P "${LIBUNWIND_BINARY_DIR}/cmake_install.cmake")
228+
COMMAND "${CMAKE_COMMAND}" --install "${CMAKE_BINARY_DIR}" --component unwind --strip)
229+
230+
if (LIBUNWIND_INSTALL_LIBRARY)
231+
add_dependencies(install-unwind unwind)
232+
add_dependencies(install-unwind-stripped unwind)
233+
endif()
234+
237235
if(LIBUNWIND_INSTALL_HEADERS)
238236
add_dependencies(install-unwind install-unwind-headers)
239237
add_dependencies(install-unwind-stripped install-unwind-headers-stripped)

0 commit comments

Comments
 (0)