Skip to content

Commit

Permalink
[libcxxabi] Allow tests to link with static libc++abi/libc++ even if …
Browse files Browse the repository at this point in the history
…the shared version is present

Summary:
Right now the only way to force libc++abi tests to link with the static version of libc++abi is to set `LIBCXXABI_ENABLE_SHARED` to `OFF`. However, this doesn't work when libc++abi is built as standalone project because of [this](https://github.com/llvm/llvm-project/blob/54c522420347e58aa7bae1892cf5c5672b57c875/libcxxabi/CMakeLists.txt#L503-L519).

This change allows specifying the version of the library for tests to link with.

This is useful for remote testing, for example, with `SSHExecutor`, where we _have_ to link with libc++abi statically.

Two new CMake options are introduced here: `LIBCXXABI_LINK_TESTS_WITH_SHARED_LIBCXXABI` and `LIBCXXABI_LINK_TESTS_WITH_SHARED_LIBCXX`. They can be set to `OFF` to tell the test utility to link tests with the static libraries.

It shouldn't break anything, because the default values of these options are set such that the test utility will behave the same way.

Reviewers: EricWF, mclow.lists, phosek, mehdi_amini, ldionne, jroelofs, bcraig

Subscribers: mgorny, christof, ldionne, libcxx-commits

Tags: #libc

Differential Revision: https://reviews.llvm.org/D71894
  • Loading branch information
broadwaylamb committed Jan 9, 2020
1 parent 6c04ef4 commit fb76c79
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
30 changes: 29 additions & 1 deletion libcxxabi/CMakeLists.txt
Expand Up @@ -92,6 +92,14 @@ usual symlinks pointing to that.")
option(LIBCXXABI_ENABLE_SHARED "Build libc++abi as a shared library." ON)
option(LIBCXXABI_ENABLE_STATIC "Build libc++abi as a static library." ON)

option(LIBCXXABI_LINK_TESTS_WITH_SHARED_LIBCXXABI
"Whether the libc++abi tests should link with the shared libc++abi library"
${LIBCXXABI_ENABLE_SHARED})

option(LIBCXXABI_LINK_TESTS_WITH_SHARED_LIBCXX
"Whether the libc++abi tests should link with the shared libc++ library"
${LIBCXX_ENABLE_SHARED})

cmake_dependent_option(LIBCXXABI_INSTALL_STATIC_LIBRARY
"Install the static libc++abi library." ON
"LIBCXXABI_ENABLE_STATIC;LIBCXXABI_INSTALL_LIBRARY" OFF)
Expand All @@ -115,6 +123,26 @@ if (NOT LIBCXXABI_ENABLE_SHARED AND NOT LIBCXXABI_ENABLE_STATIC)
message(FATAL_ERROR "libc++abi must be built as either a shared or static library.")
endif()

if(LIBCXXABI_LINK_TESTS_WITH_SHARED_LIBCXXABI AND NOT LIBCXXABI_ENABLE_SHARED)
message(FATAL_ERROR "LIBCXXABI_LINK_TESTS_WITH_SHARED_LIBCXXABI being ON requires LIBCXXABI_ENABLE_SHARED to be ON")
endif()

if(NOT LIBCXXABI_LINK_TESTS_WITH_SHARED_LIBCXXABI AND NOT LIBCXXABI_ENABLE_STATIC)
message(FATAL_ERROR "LIBCXXABI_LINK_TESTS_WITH_SHARED_LIBCXXABI being OFF requires LIBCXXABI_ENABLE_STATIC to be ON")
endif()

if(DEFINED LIBCXX_ENABLE_SHARED
AND LIBCXXABI_LINK_TESTS_WITH_SHARED_LIBCXX
AND NOT LIBCXX_ENABLE_SHARED)
message(FATAL_ERROR "LIBCXXABI_LINK_TESTS_WITH_SHARED_LIBCXX being ON requires LIBCXX_ENABLE_SHARED to be ON")
endif()

if(DEFINED LIBCXX_ENABLE_STATIC
AND NOT LIBCXXABI_LINK_TESTS_WITH_SHARED_LIBCXX
AND NOT LIBCXX_ENABLE_STATIC)
message(FATAL_ERROR "LIBCXXABI_LINK_TESTS_WITH_SHARED_LIBCXX being OFF requires LIBCXX_ENABLE_STATIC to be ON")
endif()

if (LLVM_EXTERNAL_LIBCXX_SOURCE_DIR)
set(LIBCXXABI_LIBCXX_SRC_DIRS ${LLVM_EXTERNAL_LIBCXX_SOURCE_DIR})
else()
Expand Down Expand Up @@ -209,7 +237,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LIBCXXABI_LIBRARY_DIR})
# directory.
if (NOT LIBCXXABI_LIBCXX_LIBRARY_PATH)
set(LIBCXXABI_LIBCXX_LIBRARY_PATH "${LIBCXXABI_LIBRARY_DIR}" CACHE PATH
"The path to libc++ library.")
"The path to libc++ library." FORCE)
endif()

# Check that we can build with 32 bits if requested.
Expand Down
2 changes: 2 additions & 0 deletions libcxxabi/test/CMakeLists.txt
Expand Up @@ -20,6 +20,8 @@ pythonize_bool(LIBCXXABI_USE_LLVM_UNWINDER)
pythonize_bool(LIBCXXABI_USE_COMPILER_RT)
pythonize_bool(LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY)
pythonize_bool(LIBCXX_ENABLE_PARALLEL_ALGORITHMS)
pythonize_bool(LIBCXXABI_LINK_TESTS_WITH_SHARED_LIBCXX)
pythonize_bool(LIBCXXABI_LINK_TESTS_WITH_SHARED_LIBCXXABI)
set(LIBCXXABI_TARGET_INFO "libcxx.test.target_info.LocalTI" CACHE STRING
"TargetInfo to use when setting up test environment.")
set(LIBCXXABI_EXECUTOR "None" CACHE STRING
Expand Down
4 changes: 2 additions & 2 deletions libcxxabi/test/lit.site.cfg.in
Expand Up @@ -16,8 +16,8 @@ config.sanitizer_library = "@LIBCXXABI_SANITIZER_LIBRARY@"
config.enable_32bit = @LIBCXXABI_BUILD_32_BITS@
config.target_info = "@LIBCXXABI_TARGET_INFO@"
config.executor = "@LIBCXXABI_EXECUTOR@"
config.libcxxabi_shared = @LIBCXXABI_ENABLE_SHARED@
config.enable_shared = @LIBCXX_ENABLE_SHARED@
config.libcxxabi_shared = @LIBCXXABI_LINK_TESTS_WITH_SHARED_LIBCXXABI@
config.enable_shared = @LIBCXXABI_LINK_TESTS_WITH_SHARED_LIBCXX@
config.enable_exceptions = @LIBCXXABI_ENABLE_EXCEPTIONS@
config.host_triple = "@LLVM_HOST_TRIPLE@"
config.target_triple = "@TARGET_TRIPLE@"
Expand Down

0 comments on commit fb76c79

Please sign in to comment.