Skip to content

Commit 33a4c25

Browse files
committed
[runtimes] Always define cxx_shared, cxx_static & other targets
However, mark them as EXCLUDE_FROM_ALL when we don't want to build them. Simply declaring the targets should be of no harm, and it allows other projects to mention these targets regardless of whether they end up being built or not. This patch basically moves the definition of e.g. cxx_shared out of the `if (LIBCXX_ENABLE_SHARED)` and instead marks it as EXCLUDE_FROM_ALL conditionally on whether LIBCXX_ENABLE_SHARED is passed. It then does the same for libunwind and libc++abi targets. This is a reapplication of 79ee034, which was reverted in a353909 because it broke the TSAN and the Fuchsia builds. Resolves #77654 Differential Revision: https://reviews.llvm.org/D134221
1 parent 34d0c99 commit 33a4c25

File tree

5 files changed

+48
-32
lines changed

5 files changed

+48
-32
lines changed

libcxx/cmake/caches/AIX.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,10 @@ set(LIBCXX_CXX_ABI libcxxabi CACHE STRING "")
1616
set(LIBUNWIND_ENABLE_SHARED ON CACHE BOOL "")
1717
set(LIBUNWIND_ENABLE_STATIC OFF CACHE BOOL "")
1818
set(LIBCXX_ABI_DEFINES "_LIBCPP_ABI_IOS_ALLOW_ARBITRARY_FILL_VALUE" CACHE STRING "")
19+
20+
# On AIX, both shared and static libraries are archived. As a result, both the static and the shared targets end
21+
# up with a `.a` suffix, which conflict. To workaround that, we set a different output name for the static
22+
# libraries, which we never actually build anyway. For more information, see https://gitlab.kitware.com/cmake/cmake/-/issues/19494.
23+
set(LIBCXX_STATIC_OUTPUT_NAME "c++-static" CACHE STRING "")
24+
set(LIBCXXABI_STATIC_OUTPUT_NAME "c++abi-static" CACHE STRING "")
25+
set(LIBUNWIND_STATIC_OUTPUT_NAME "unwind-static" CACHE STRING "")

libcxx/cmake/caches/Armv7M-picolibc.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,14 @@ set(LIBUNWIND_IS_BAREMETAL ON CACHE BOOL "")
3939
set(LIBUNWIND_REMEMBER_HEAP_ALLOC ON CACHE BOOL "")
4040
set(LIBUNWIND_USE_COMPILER_RT ON CACHE BOOL "")
4141
find_program(QEMU_SYSTEM_ARM qemu-system-arm REQUIRED)
42+
43+
# On embedded platforms that don't support shared library targets, CMake implicitly changes shared
44+
# library targets to be static library targets. This results in duplicate definitions of the static
45+
# library targets even though we might not ever build the shared library target, which breaks the
46+
# build. To work around this, we change the output name of the shared library target so that it
47+
# can't conflict with the static library target.
48+
#
49+
# This is tracked by https://gitlab.kitware.com/cmake/cmake/-/issues/25759.
50+
set(LIBCXX_SHARED_OUTPUT_NAME "c++-shared" CACHE STRING "")
51+
set(LIBCXXABI_SHARED_OUTPUT_NAME "c++abi-shared" CACHE STRING "")
52+
set(LIBUNWIND_SHARED_OUTPUT_NAME "unwind-shared" CACHE STRING "")

libcxx/src/CMakeLists.txt

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,6 @@ if (LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS)
143143
)
144144
endif()
145145

146-
if(NOT LIBCXX_INSTALL_LIBRARY)
147-
set(exclude_from_all EXCLUDE_FROM_ALL)
148-
endif()
149-
150146
if (APPLE AND LLVM_USE_SANITIZER)
151147
if (("${LLVM_USE_SANITIZER}" STREQUAL "Address") OR
152148
("${LLVM_USE_SANITIZER}" STREQUAL "Address;Undefined") OR
@@ -177,8 +173,7 @@ split_list(LIBCXX_COMPILE_FLAGS)
177173
split_list(LIBCXX_LINK_FLAGS)
178174

179175
# Build the shared library.
180-
if (LIBCXX_ENABLE_SHARED)
181-
add_library(cxx_shared SHARED ${exclude_from_all} ${LIBCXX_SOURCES} ${LIBCXX_HEADERS})
176+
add_library(cxx_shared SHARED $<$<NOT:$<BOOL:LIBCXX_ENABLE_SHARED>>:EXCLUDE_FROM_ALL> ${LIBCXX_SOURCES} ${LIBCXX_HEADERS})
182177
target_include_directories(cxx_shared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
183178
target_link_libraries(cxx_shared PUBLIC cxx-headers libcxx-libc-shared
184179
PRIVATE ${LIBCXX_LIBRARIES})
@@ -251,7 +246,10 @@ if (LIBCXX_ENABLE_SHARED)
251246
)
252247
endif()
253248

249+
if (LIBCXX_ENABLE_SHARED)
254250
list(APPEND LIBCXX_BUILD_TARGETS "cxx_shared")
251+
endif()
252+
255253
if(WIN32 AND NOT MINGW AND NOT "${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
256254
# Since we most likely do not have a mt.exe replacement, disable the
257255
# manifest bundling. This allows a normal cmake invocation to pass which
@@ -264,13 +262,11 @@ if (LIBCXX_ENABLE_SHARED)
264262
APPEND_STRING PROPERTY LINK_FLAGS " -Xlinker /MANIFEST:NO")
265263
endif()
266264
endif()
267-
endif()
268265

269266
set(CMAKE_STATIC_LIBRARY_PREFIX "lib")
270267

271268
# Build the static library.
272-
if (LIBCXX_ENABLE_STATIC)
273-
add_library(cxx_static STATIC ${exclude_from_all} ${LIBCXX_SOURCES} ${LIBCXX_HEADERS})
269+
add_library(cxx_static STATIC $<$<NOT:$<BOOL:LIBCXX_ENABLE_STATIC>>:EXCLUDE_FROM_ALL> ${LIBCXX_SOURCES} ${LIBCXX_HEADERS})
274270
target_include_directories(cxx_static PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
275271
target_link_libraries(cxx_static PUBLIC cxx-headers libcxx-libc-static
276272
PRIVATE ${LIBCXX_LIBRARIES}
@@ -299,16 +295,18 @@ if (LIBCXX_ENABLE_STATIC)
299295
target_compile_definitions(cxx_static PRIVATE _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS=)
300296
endif()
301297

302-
list(APPEND LIBCXX_BUILD_TARGETS "cxx_static")
298+
if (LIBCXX_ENABLE_STATIC)
299+
list(APPEND LIBCXX_BUILD_TARGETS "cxx_static")
300+
endif()
303301
# Attempt to merge the libc++.a archive and the ABI library archive into one.
304302
if (LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY)
305303
target_link_libraries(cxx_static PRIVATE libcxx-abi-static-objects)
306304
endif()
307-
endif()
308305

309306
# Add a meta-target for both libraries.
310307
add_custom_target(cxx DEPENDS ${LIBCXX_BUILD_TARGETS})
311308

309+
# Build the experimental static library
312310
set(LIBCXX_EXPERIMENTAL_SOURCES
313311
experimental/keep.cpp
314312
)

libcxxabi/src/CMakeLists.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,7 @@ if (CMAKE_POSITION_INDEPENDENT_CODE OR NOT DEFINED CMAKE_POSITION_INDEPENDENT_CO
184184
endif()
185185
target_compile_options(cxxabi_shared_objects PRIVATE "${LIBCXXABI_ADDITIONAL_COMPILE_FLAGS}")
186186

187-
if (LIBCXXABI_ENABLE_SHARED)
188-
add_library(cxxabi_shared SHARED)
187+
add_library(cxxabi_shared SHARED $<$<NOT:$<BOOL:LIBCXXABI_ENABLE_SHARED>>:EXCLUDE_FROM_ALL>)
189188
set_target_properties(cxxabi_shared
190189
PROPERTIES
191190
LINK_FLAGS "${LIBCXXABI_LINK_FLAGS}"
@@ -208,10 +207,12 @@ if (LIBCXXABI_ENABLE_SHARED)
208207
PUBLIC cxxabi_shared_objects
209208
PRIVATE ${LIBCXXABI_LIBRARIES})
210209

210+
if (LIBCXXABI_ENABLE_SHARED)
211211
list(APPEND LIBCXXABI_BUILD_TARGETS "cxxabi_shared")
212-
if (LIBCXXABI_INSTALL_SHARED_LIBRARY)
213-
list(APPEND LIBCXXABI_INSTALL_TARGETS "cxxabi_shared")
214-
endif()
212+
endif()
213+
if (LIBCXXABI_INSTALL_SHARED_LIBRARY)
214+
list(APPEND LIBCXXABI_INSTALL_TARGETS "cxxabi_shared")
215+
endif()
215216

216217
add_library(cxxabi-reexports INTERFACE)
217218
function(export_symbols file)
@@ -252,7 +253,6 @@ if (LIBCXXABI_ENABLE_SHARED)
252253
reexport_symbols("${CMAKE_CURRENT_SOURCE_DIR}/../lib/personality-v0.exp")
253254
endif()
254255
endif()
255-
endif()
256256

257257
# Build the static library.
258258
add_library(cxxabi_static_objects OBJECT EXCLUDE_FROM_ALL ${LIBCXXABI_SOURCES} ${LIBCXXABI_HEADERS})
@@ -292,8 +292,7 @@ if(LIBCXXABI_HERMETIC_STATIC_LIBRARY)
292292
_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS=)
293293
endif()
294294

295-
if (LIBCXXABI_ENABLE_STATIC)
296-
add_library(cxxabi_static STATIC)
295+
add_library(cxxabi_static STATIC $<$<NOT:$<BOOL:LIBCXXABI_ENABLE_STATIC>>:EXCLUDE_FROM_ALL>)
297296
if (LIBCXXABI_USE_LLVM_UNWINDER AND NOT LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY)
298297
target_link_libraries(cxxabi_static PUBLIC unwind_static)
299298
endif()
@@ -306,10 +305,11 @@ if (LIBCXXABI_ENABLE_STATIC)
306305
PUBLIC cxxabi_static_objects
307306
PRIVATE ${LIBCXXABI_STATIC_LIBRARIES} ${LIBCXXABI_LIBRARIES})
308307

308+
if (LIBCXXABI_ENABLE_STATIC)
309309
list(APPEND LIBCXXABI_BUILD_TARGETS "cxxabi_static")
310-
if (LIBCXXABI_INSTALL_STATIC_LIBRARY)
311-
list(APPEND LIBCXXABI_INSTALL_TARGETS "cxxabi_static")
312-
endif()
310+
endif()
311+
if (LIBCXXABI_INSTALL_STATIC_LIBRARY)
312+
list(APPEND LIBCXXABI_INSTALL_TARGETS "cxxabi_static")
313313
endif()
314314

315315
# Add a meta-target for both libraries.

libunwind/src/CMakeLists.txt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,7 @@ if (CMAKE_POSITION_INDEPENDENT_CODE OR NOT DEFINED CMAKE_POSITION_INDEPENDENT_CO
153153
set_target_properties(unwind_shared_objects PROPERTIES POSITION_INDEPENDENT_CODE ON) # must set manually because it's an object library
154154
endif()
155155

156-
if (LIBUNWIND_ENABLE_SHARED)
157-
add_library(unwind_shared SHARED)
156+
add_library(unwind_shared SHARED $<$<NOT:$<BOOL:LIBUNWIND_ENABLE_SHARED>>:EXCLUDE_FROM_ALL>)
158157
target_link_libraries(unwind_shared PUBLIC unwind_shared_objects)
159158
set_target_properties(unwind_shared
160159
PROPERTIES
@@ -165,10 +164,11 @@ if (LIBUNWIND_ENABLE_SHARED)
165164
SOVERSION "1"
166165
)
167166

167+
if (LIBUNWIND_ENABLE_SHARED)
168168
list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_shared")
169-
if (LIBUNWIND_INSTALL_SHARED_LIBRARY)
170-
list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_shared")
171-
endif()
169+
endif()
170+
if (LIBUNWIND_INSTALL_SHARED_LIBRARY)
171+
list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_shared")
172172
endif()
173173

174174
# Build the static library.
@@ -199,8 +199,7 @@ if(LIBUNWIND_HIDE_SYMBOLS)
199199
target_compile_definitions(unwind_static_objects PRIVATE _LIBUNWIND_HIDE_SYMBOLS)
200200
endif()
201201

202-
if (LIBUNWIND_ENABLE_STATIC)
203-
add_library(unwind_static STATIC)
202+
add_library(unwind_static STATIC $<$<NOT:$<BOOL:LIBUNWIND_ENABLE_STATIC>>:EXCLUDE_FROM_ALL>)
204203
target_link_libraries(unwind_static PUBLIC unwind_static_objects)
205204
set_target_properties(unwind_static
206205
PROPERTIES
@@ -209,10 +208,11 @@ if (LIBUNWIND_ENABLE_STATIC)
209208
OUTPUT_NAME "${LIBUNWIND_STATIC_OUTPUT_NAME}"
210209
)
211210

211+
if (LIBUNWIND_ENABLE_STATIC)
212212
list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_static")
213-
if (LIBUNWIND_INSTALL_STATIC_LIBRARY)
214-
list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_static")
215-
endif()
213+
endif()
214+
if (LIBUNWIND_INSTALL_STATIC_LIBRARY)
215+
list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_static")
216216
endif()
217217

218218
# Add a meta-target for both libraries.

0 commit comments

Comments
 (0)