[runtimes] Always define cxx_shared, cxx_static & other targets (#80007)
This patch always defines the cxx_shared, cxx_static & other top-level
targets. However, they are marked 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. I purposefully avoided to
reformat the files (which now has inconsistent indentation) because I
wanted to keep the diff minimal, and I know this is an area of the code
where folks may have downstream diffs. I will re-indent the code
separately once this patch lands.
This is a reapplication of 79ee0342dbf0, which was reverted in
a3539090884c because it broke the TSAN and the Fuchsia builds.
Resolves #77654
Differential Revision: https://reviews.llvm.org/D134221
GitOrigin-RevId: 917ada35cd937ad4104dff89c48398bd796ba6b7
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 125cf4f..3065bfc 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -153,11 +153,11 @@
set_target_properties(unwind_shared_objects PROPERTIES POSITION_INDEPENDENT_CODE ON) # must set manually because it's an object library
endif()
-if (LIBUNWIND_ENABLE_SHARED)
add_library(unwind_shared SHARED)
target_link_libraries(unwind_shared PUBLIC unwind_shared_objects)
set_target_properties(unwind_shared
PROPERTIES
+ EXCLUDE_FROM_ALL "$<IF:$<BOOL:${LIBUNWIND_ENABLE_SHARED}>,FALSE,TRUE>"
LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}"
LINKER_LANGUAGE C
OUTPUT_NAME "${LIBUNWIND_SHARED_OUTPUT_NAME}"
@@ -165,10 +165,11 @@
SOVERSION "1"
)
+if (LIBUNWIND_ENABLE_SHARED)
list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_shared")
- if (LIBUNWIND_INSTALL_SHARED_LIBRARY)
- list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_shared")
- endif()
+endif()
+if (LIBUNWIND_INSTALL_SHARED_LIBRARY)
+ list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_shared")
endif()
# Build the static library.
@@ -199,20 +200,21 @@
target_compile_definitions(unwind_static_objects PRIVATE _LIBUNWIND_HIDE_SYMBOLS)
endif()
-if (LIBUNWIND_ENABLE_STATIC)
add_library(unwind_static STATIC)
target_link_libraries(unwind_static PUBLIC unwind_static_objects)
set_target_properties(unwind_static
PROPERTIES
+ EXCLUDE_FROM_ALL "$<IF:$<BOOL:${LIBUNWIND_ENABLE_STATIC}>,FALSE,TRUE>"
LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}"
LINKER_LANGUAGE C
OUTPUT_NAME "${LIBUNWIND_STATIC_OUTPUT_NAME}"
)
+if (LIBUNWIND_ENABLE_STATIC)
list(APPEND LIBUNWIND_BUILD_TARGETS "unwind_static")
- if (LIBUNWIND_INSTALL_STATIC_LIBRARY)
- list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_static")
- endif()
+endif()
+if (LIBUNWIND_INSTALL_STATIC_LIBRARY)
+ list(APPEND LIBUNWIND_INSTALL_TARGETS "unwind_static")
endif()
# Add a meta-target for both libraries.