Skip to content

Commit 01ff9da

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 7565ae6 commit 01ff9da

File tree

4 files changed

+37
-32
lines changed

4 files changed

+37
-32
lines changed

libcxx/cmake/caches/AIX.cmake

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

libcxx/src/CMakeLists.txt

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,6 @@ if (LIBCXX_CONFIGURE_IDE)
155155
endif()
156156
endif()
157157

158-
if(NOT LIBCXX_INSTALL_LIBRARY)
159-
set(exclude_from_all EXCLUDE_FROM_ALL)
160-
endif()
161-
162158
if (LIBCXX_GENERATE_COVERAGE AND NOT LIBCXX_COVERAGE_LIBRARY)
163159
find_compiler_rt_library(profile LIBCXX_COVERAGE_LIBRARY)
164160
endif()
@@ -194,8 +190,7 @@ split_list(LIBCXX_COMPILE_FLAGS)
194190
split_list(LIBCXX_LINK_FLAGS)
195191

196192
# Build the shared library.
197-
if (LIBCXX_ENABLE_SHARED)
198-
add_library(cxx_shared SHARED ${exclude_from_all} ${LIBCXX_SOURCES} ${LIBCXX_HEADERS})
193+
add_library(cxx_shared SHARED $<$<NOT:$<BOOL:LIBCXX_ENABLE_SHARED>>:EXCLUDE_FROM_ALL> ${LIBCXX_SOURCES} ${LIBCXX_HEADERS})
199194
target_include_directories(cxx_shared PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
200195
target_link_libraries(cxx_shared PUBLIC cxx-headers
201196
PRIVATE ${LIBCXX_LIBRARIES})
@@ -274,21 +269,22 @@ if (LIBCXX_ENABLE_SHARED)
274269
)
275270
endif()
276271

272+
if (LIBCXX_ENABLE_SHARED)
277273
list(APPEND LIBCXX_BUILD_TARGETS "cxx_shared")
274+
endif()
275+
278276
if(WIN32 AND NOT MINGW AND NOT "${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows")
279277
# Since we most likely do not have a mt.exe replacement, disable the
280278
# manifest bundling. This allows a normal cmake invocation to pass which
281279
# will attempt to use the manifest tool to generate the bundled manifest
282280
set_target_properties(cxx_shared PROPERTIES
283281
APPEND_STRING PROPERTY LINK_FLAGS " /MANIFEST:NO")
284282
endif()
285-
endif()
286283

287284
set(CMAKE_STATIC_LIBRARY_PREFIX "lib")
288285

289286
# Build the static library.
290-
if (LIBCXX_ENABLE_STATIC)
291-
add_library(cxx_static STATIC ${exclude_from_all} ${LIBCXX_SOURCES} ${LIBCXX_HEADERS})
287+
add_library(cxx_static STATIC $<$<NOT:$<BOOL:LIBCXX_ENABLE_STATIC>>:EXCLUDE_FROM_ALL> ${LIBCXX_SOURCES} ${LIBCXX_HEADERS})
292288
target_include_directories(cxx_static PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
293289
target_link_libraries(cxx_static PUBLIC cxx-headers
294290
PRIVATE ${LIBCXX_LIBRARIES}
@@ -314,16 +310,18 @@ if (LIBCXX_ENABLE_STATIC)
314310
target_compile_definitions(cxx_static PRIVATE _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS=)
315311
endif()
316312

317-
list(APPEND LIBCXX_BUILD_TARGETS "cxx_static")
313+
if (LIBCXX_ENABLE_STATIC)
314+
list(APPEND LIBCXX_BUILD_TARGETS "cxx_static")
315+
endif()
318316
# Attempt to merge the libc++.a archive and the ABI library archive into one.
319317
if (LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY)
320318
target_link_libraries(cxx_static PRIVATE libcxx-abi-static-objects)
321319
endif()
322-
endif()
323320

324321
# Add a meta-target for both libraries.
325322
add_custom_target(cxx DEPENDS ${LIBCXX_BUILD_TARGETS})
326323

324+
# Build the experimental static library
327325
set(LIBCXX_EXPERIMENTAL_SOURCES
328326
experimental/keep.cpp
329327
)

libcxxabi/src/CMakeLists.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,7 @@ if (CMAKE_POSITION_INDEPENDENT_CODE OR NOT DEFINED CMAKE_POSITION_INDEPENDENT_CO
183183
set_target_properties(cxxabi_shared_objects PROPERTIES POSITION_INDEPENDENT_CODE ON) # must set manually because it's an object library
184184
endif()
185185

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

209+
if (LIBCXXABI_ENABLE_SHARED)
210210
list(APPEND LIBCXXABI_BUILD_TARGETS "cxxabi_shared")
211-
if (LIBCXXABI_INSTALL_SHARED_LIBRARY)
212-
list(APPEND LIBCXXABI_INSTALL_TARGETS "cxxabi_shared")
213-
endif()
211+
endif()
212+
if (LIBCXXABI_INSTALL_SHARED_LIBRARY)
213+
list(APPEND LIBCXXABI_INSTALL_TARGETS "cxxabi_shared")
214+
endif()
214215

215216
add_library(cxxabi-reexports INTERFACE)
216217

@@ -240,7 +241,6 @@ if (LIBCXXABI_ENABLE_SHARED)
240241
endif()
241242
endif()
242243
endif()
243-
endif()
244244

245245
# Build the static library.
246246
add_library(cxxabi_static_objects OBJECT EXCLUDE_FROM_ALL ${LIBCXXABI_SOURCES} ${LIBCXXABI_HEADERS})
@@ -276,8 +276,7 @@ if(LIBCXXABI_HERMETIC_STATIC_LIBRARY)
276276
_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS=)
277277
endif()
278278

279-
if (LIBCXXABI_ENABLE_STATIC)
280-
add_library(cxxabi_static STATIC)
279+
add_library(cxxabi_static STATIC $<$<NOT:$<BOOL:LIBCXXABI_ENABLE_STATIC>>:EXCLUDE_FROM_ALL>)
281280
if (LIBCXXABI_USE_LLVM_UNWINDER AND NOT LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY)
282281
target_link_libraries(cxxabi_static PUBLIC unwind_static)
283282
endif()
@@ -290,10 +289,11 @@ if (LIBCXXABI_ENABLE_STATIC)
290289
PUBLIC cxxabi_static_objects
291290
PRIVATE ${LIBCXXABI_STATIC_LIBRARIES} ${LIBCXXABI_LIBRARIES})
292291

292+
if (LIBCXXABI_ENABLE_STATIC)
293293
list(APPEND LIBCXXABI_BUILD_TARGETS "cxxabi_static")
294-
if (LIBCXXABI_INSTALL_STATIC_LIBRARY)
295-
list(APPEND LIBCXXABI_INSTALL_TARGETS "cxxabi_static")
296-
endif()
294+
endif()
295+
if (LIBCXXABI_INSTALL_STATIC_LIBRARY)
296+
list(APPEND LIBCXXABI_INSTALL_TARGETS "cxxabi_static")
297297
endif()
298298

299299
# 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.
@@ -205,8 +205,7 @@ if(LIBUNWIND_HIDE_SYMBOLS)
205205
target_compile_definitions(unwind_static_objects PRIVATE _LIBUNWIND_HIDE_SYMBOLS)
206206
endif()
207207

208-
if (LIBUNWIND_ENABLE_STATIC)
209-
add_library(unwind_static STATIC)
208+
add_library(unwind_static STATIC $<$<NOT:$<BOOL:LIBUNWIND_ENABLE_STATIC>>:EXCLUDE_FROM_ALL>)
210209
target_link_libraries(unwind_static PUBLIC unwind_static_objects)
211210
set_target_properties(unwind_static
212211
PROPERTIES
@@ -215,10 +214,11 @@ if (LIBUNWIND_ENABLE_STATIC)
215214
OUTPUT_NAME "${LIBUNWIND_STATIC_OUTPUT_NAME}"
216215
)
217216

217+
if (LIBUNWIND_ENABLE_STATIC)
218218
list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_static")
219-
if (LIBUNWIND_INSTALL_STATIC_LIBRARY)
220-
list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_static")
221-
endif()
219+
endif()
220+
if (LIBUNWIND_INSTALL_STATIC_LIBRARY)
221+
list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_static")
222222
endif()
223223

224224
# Add a meta-target for both libraries.

0 commit comments

Comments
 (0)