Skip to content

Commit ad17e28

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 6bb5a0b commit ad17e28

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})
@@ -252,7 +247,10 @@ if (LIBCXX_ENABLE_SHARED)
252247
)
253248
endif()
254249

250+
if (LIBCXX_ENABLE_SHARED)
255251
list(APPEND LIBCXX_BUILD_TARGETS "cxx_shared")
252+
endif()
253+
256254
if(WIN32 AND NOT MINGW AND NOT "${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
257255
# Since we most likely do not have a mt.exe replacement, disable the
258256
# manifest bundling. This allows a normal cmake invocation to pass which
@@ -265,13 +263,11 @@ if (LIBCXX_ENABLE_SHARED)
265263
APPEND_STRING PROPERTY LINK_FLAGS " -Xlinker /MANIFEST:NO")
266264
endif()
267265
endif()
268-
endif()
269266

270267
set(CMAKE_STATIC_LIBRARY_PREFIX "lib")
271268

272269
# Build the static library.
273-
if (LIBCXX_ENABLE_STATIC)
274-
add_library(cxx_static STATIC ${exclude_from_all} ${LIBCXX_SOURCES} ${LIBCXX_HEADERS})
270+
add_library(cxx_static STATIC $<$<NOT:$<BOOL:LIBCXX_ENABLE_STATIC>>:EXCLUDE_FROM_ALL> ${LIBCXX_SOURCES} ${LIBCXX_HEADERS})
275271
target_include_directories(cxx_static PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
276272
target_link_libraries(cxx_static PUBLIC cxx-headers libcxx-libc-static
277273
PRIVATE ${LIBCXX_LIBRARIES}
@@ -300,17 +296,19 @@ if (LIBCXX_ENABLE_STATIC)
300296
target_compile_definitions(cxx_static PRIVATE _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS=)
301297
endif()
302298

303-
list(APPEND LIBCXX_BUILD_TARGETS "cxx_static")
299+
if (LIBCXX_ENABLE_STATIC)
300+
list(APPEND LIBCXX_BUILD_TARGETS "cxx_static")
301+
endif()
304302
# Attempt to merge the libc++.a archive and the ABI library archive into one.
305303
if (LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY)
306304
target_link_libraries(cxx_static PRIVATE libcxx-abi-static-objects)
307305
endif()
308-
endif()
309306

310307
# Add a meta-target for both libraries.
311308
add_custom_target(cxx DEPENDS ${LIBCXX_BUILD_TARGETS})
312309
add_dependencies(cxx-test-depends cxx)
313310

311+
# Build the experimental static library
314312
set(LIBCXX_EXPERIMENTAL_SOURCES
315313
experimental/keep.cpp
316314
)

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(reexport_symbols file)
@@ -244,7 +245,6 @@ if (LIBCXXABI_ENABLE_SHARED)
244245
reexport_symbols("${CMAKE_CURRENT_SOURCE_DIR}/../lib/personality-v0.exp")
245246
endif()
246247
endif()
247-
endif()
248248

249249
# Build the static library.
250250
add_library(cxxabi_static_objects OBJECT EXCLUDE_FROM_ALL ${LIBCXXABI_SOURCES} ${LIBCXXABI_HEADERS})
@@ -284,8 +284,7 @@ if(LIBCXXABI_HERMETIC_STATIC_LIBRARY)
284284
_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS=)
285285
endif()
286286

287-
if (LIBCXXABI_ENABLE_STATIC)
288-
add_library(cxxabi_static STATIC)
287+
add_library(cxxabi_static STATIC $<$<NOT:$<BOOL:LIBCXXABI_ENABLE_STATIC>>:EXCLUDE_FROM_ALL>)
289288
if (LIBCXXABI_USE_LLVM_UNWINDER AND NOT LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY)
290289
target_link_libraries(cxxabi_static PUBLIC unwind_static)
291290
endif()
@@ -298,10 +297,11 @@ if (LIBCXXABI_ENABLE_STATIC)
298297
PUBLIC cxxabi_static_objects
299298
PRIVATE ${LIBCXXABI_STATIC_LIBRARIES} ${LIBCXXABI_LIBRARIES})
300299

300+
if (LIBCXXABI_ENABLE_STATIC)
301301
list(APPEND LIBCXXABI_BUILD_TARGETS "cxxabi_static")
302-
if (LIBCXXABI_INSTALL_STATIC_LIBRARY)
303-
list(APPEND LIBCXXABI_INSTALL_TARGETS "cxxabi_static")
304-
endif()
302+
endif()
303+
if (LIBCXXABI_INSTALL_STATIC_LIBRARY)
304+
list(APPEND LIBCXXABI_INSTALL_TARGETS "cxxabi_static")
305305
endif()
306306

307307
# 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
@@ -162,8 +162,7 @@ if (CMAKE_POSITION_INDEPENDENT_CODE OR NOT DEFINED CMAKE_POSITION_INDEPENDENT_CO
162162
set_target_properties(unwind_shared_objects PROPERTIES POSITION_INDEPENDENT_CODE ON) # must set manually because it's an object library
163163
endif()
164164

165-
if (LIBUNWIND_ENABLE_SHARED)
166-
add_library(unwind_shared SHARED)
165+
add_library(unwind_shared SHARED $<$<NOT:$<BOOL:LIBUNWIND_ENABLE_SHARED>>:EXCLUDE_FROM_ALL>)
167166
target_link_libraries(unwind_shared PUBLIC unwind_shared_objects)
168167
set_target_properties(unwind_shared
169168
PROPERTIES
@@ -174,10 +173,11 @@ if (LIBUNWIND_ENABLE_SHARED)
174173
SOVERSION "1"
175174
)
176175

176+
if (LIBUNWIND_ENABLE_SHARED)
177177
list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_shared")
178-
if (LIBUNWIND_INSTALL_SHARED_LIBRARY)
179-
list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_shared")
180-
endif()
178+
endif()
179+
if (LIBUNWIND_INSTALL_SHARED_LIBRARY)
180+
list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_shared")
181181
endif()
182182

183183
# Build the static library.
@@ -208,8 +208,7 @@ if(LIBUNWIND_HIDE_SYMBOLS)
208208
target_compile_definitions(unwind_static_objects PRIVATE _LIBUNWIND_HIDE_SYMBOLS)
209209
endif()
210210

211-
if (LIBUNWIND_ENABLE_STATIC)
212-
add_library(unwind_static STATIC)
211+
add_library(unwind_static STATIC $<$<NOT:$<BOOL:LIBUNWIND_ENABLE_STATIC>>:EXCLUDE_FROM_ALL>)
213212
target_link_libraries(unwind_static PUBLIC unwind_static_objects)
214213
set_target_properties(unwind_static
215214
PROPERTIES
@@ -218,10 +217,11 @@ if (LIBUNWIND_ENABLE_STATIC)
218217
OUTPUT_NAME "${LIBUNWIND_STATIC_OUTPUT_NAME}"
219218
)
220219

220+
if (LIBUNWIND_ENABLE_STATIC)
221221
list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_static")
222-
if (LIBUNWIND_INSTALL_STATIC_LIBRARY)
223-
list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_static")
224-
endif()
222+
endif()
223+
if (LIBUNWIND_INSTALL_STATIC_LIBRARY)
224+
list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_static")
225225
endif()
226226

227227
# Add a meta-target for both libraries.

0 commit comments

Comments
 (0)