From 7eb30deff17e6e137cad170b340fcc7cf5f70761 Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Wed, 29 Jul 2015 00:03:51 +0000 Subject: [PATCH] [libcxx] Cleanup CMake configuration and integrate with LLVM Summary: This patch contains the following changes: 1. Require that libc++ can find a LLVM source directory. This is done the same way as `libc++abi` currently does. 2. Cleanup ugly configuration code in CMakeLists.txt by using `add_flags`, `add_flags_if`, and `add_flags_if_supported` macros. The goals for this patch are: 1. Help libc++ be more consistent with how LLVM handles CMake options (see PR23670 PR23671). 2. Make it easier to use sanitizers using the `LLVM_USE_SANITIZER` option. 3. Make libc++'s CMakeLists.txt file easier to understand and change. 4. Move towards allowing libc++ to create Sphinx documentation (see http://efcs.ca/libcxx-docs). 5. Move towards allowing libc++ to use other LLVM utilities such as `not` and `FileCheck`. Reviewers: mclow.lists, jroelofs, danalbert Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D11308 llvm-svn: 243503 --- libcxx/CMakeLists.txt | 363 ++++++++++----------------- libcxx/cmake/Modules/FindLLVM.cmake | 79 ++++++ libcxx/cmake/Modules/HandleLibCXXABI.cmake | 15 ++ libcxx/cmake/Modules/HandleLibcxxFlags.cmake | 147 +++++++++++ libcxx/cmake/config-ix.cmake | 19 +- libcxx/lib/CMakeLists.txt | 68 ++--- libcxx/test/CMakeLists.txt | 121 ++++----- libcxx/test/lit.site.cfg.in | 1 - libcxx/www/index.html | 20 +- 9 files changed, 453 insertions(+), 380 deletions(-) create mode 100644 libcxx/cmake/Modules/FindLLVM.cmake create mode 100644 libcxx/cmake/Modules/HandleLibcxxFlags.cmake diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt index a7bc792..9e9e283 100644 --- a/libcxx/CMakeLists.txt +++ b/libcxx/CMakeLists.txt @@ -30,52 +30,92 @@ MACRO_ENSURE_OUT_OF_SOURCE_BUILD( build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there." ) -if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) - set(LIBCXX_LIBDIR_SUFFIX "" CACHE STRING - "Define suffix of library directory name (32/64)") - - set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX}) - set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX}) - - set(LIBCXX_BUILT_STANDALONE 1) -else() - set(LIBCXX_LIBDIR_SUFFIX ${LLVM_LIBDIR_SUFFIX}) -endif() +# Find the required bits of LLVM +include(FindLLVM) +# Include the LLVM CMake functions. +include(AddLLVM) #=============================================================================== # Setup CMake Options #=============================================================================== -# Define options. -option(LIBCXX_ENABLE_EXCEPTIONS "Use exceptions." ON) -option(LIBCXX_ENABLE_RTTI "Use run time type information." ON) +# Basic options --------------------------------------------------------------- option(LIBCXX_ENABLE_ASSERTIONS "Enable assertions independent of build mode." ON) -option(LIBCXX_ENABLE_PEDANTIC "Compile with pedantic enabled." ON) -option(LIBCXX_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF) -option(LIBCXX_ENABLE_CXX1Y "Enable -std=c++1y and use of c++1y language features if the compiler supports it." OFF) option(LIBCXX_ENABLE_SHARED "Build libc++ as a shared library." ON) + +set(LIBCXX_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING + "Define suffix of library directory name (32/64)") +option(LIBCXX_INSTALL_HEADERS "Install the libc++ headers." ON) +option(LIBCXX_INSTALL_SUPPORT_HEADERS "Install libc++ support headers." ON) + +# ABI Library options --------------------------------------------------------- +set(LIBCXX_CXX_ABI "${LIBCXX_CXX_ABI}" CACHE STRING + "Specify C++ ABI library to use." FORCE) +set(CXXABIS none libcxxabi libcxxrt libstdc++ libsupc++) +set_property(CACHE LIBCXX_CXX_ABI PROPERTY STRINGS ;${CXXABIS}) + +option(LIBCXX_ENABLE_STATIC_ABI_LIBRARY "Statically link the ABI library" OFF) + +# Build libc++abi with libunwind. We need this option to determine whether to +# link with libunwind or libgcc_s while running the test cases. +option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." OFF) + +# Target options -------------------------------------------------------------- +option(LIBCXX_BUILD_32_BITS "Build 32 bit libc++." OFF) +set(LIBCXX_SYSROOT "" CACHE STRING "Use alternate sysroot.") +set(LIBCXX_GCC_TOOLCHAIN "" CACHE STRING "Use alternate GCC toolchain.") + +# Feature options ------------------------------------------------------------- +option(LIBCXX_ENABLE_EXCEPTIONS "Use exceptions." ON) +option(LIBCXX_ENABLE_RTTI "Use run time type information." ON) option(LIBCXX_ENABLE_GLOBAL_FILESYSTEM_NAMESPACE "Build libc++ with support for the global filesystem namespace." ON) option(LIBCXX_ENABLE_STDIN "Build libc++ with support for stdin/std::cin." ON) option(LIBCXX_ENABLE_STDOUT "Build libc++ with support for stdout/std::cout." ON) option(LIBCXX_ENABLE_THREADS "Build libc++ with support for threads." ON) option(LIBCXX_ENABLE_THREAD_UNSAFE_C_FUNCTIONS "Build libc++ with support for thread-unsafe C functions" ON) -option(LIBCXX_BUILD_32_BITS "Build 32 bit libc++" OFF) option(LIBCXX_ENABLE_MONOTONIC_CLOCK "Build libc++ with support for a monotonic clock. This option may only be used when LIBCXX_ENABLE_THREADS=OFF." ON) -option(LIBCXX_INSTALL_HEADERS "Install the libc++ headers." ON) -option(LIBCXX_INSTALL_SUPPORT_HEADERS "Install libc++ support headers." ON) + +# Misc options ---------------------------------------------------------------- +option(LIBCXX_ENABLE_PEDANTIC "Compile with pedantic enabled." ON) +option(LIBCXX_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF) + option(LIBCXX_GENERATE_COVERAGE "Enable generating code coverage." OFF) set(LIBCXX_COVERAGE_LIBRARY "" CACHE STRING - "The Profile-rt library used to build with code coverage") -option(LIBCXX_ENABLE_STATIC_ABI_LIBRARY "Statically link the ABI library" OFF) -set(LIBCXX_SYSROOT "" CACHE STRING "Use alternate sysroot.") -set(LIBCXX_GCC_TOOLCHAIN "" CACHE STRING "Use alternate GCC toolchain.") -if (LIBCXX_BUILT_STANDALONE) - set(LLVM_USE_SANITIZER "" CACHE STRING - "Define the sanitizer used to build the library and tests") + "The Profile-rt library used to build with code coverage") + +#=============================================================================== +# Check option configurations +#=============================================================================== + +# Ensure LIBCXX_ENABLE_MONOTONIC_CLOCK is set to ON only when +# LIBCXX_ENABLE_THREADS is on. +if(LIBCXX_ENABLE_THREADS AND NOT LIBCXX_ENABLE_MONOTONIC_CLOCK) + message(FATAL_ERROR "LIBCXX_ENABLE_MONOTONIC_CLOCK can only be set to OFF" + " when LIBCXX_ENABLE_THREADS is also set to OFF.") +endif() + +# Ensure LLVM_USE_SANITIZER is not specified when LIBCXX_GENERATE_COVERAGE +# is ON. +if (LLVM_USE_SANITIZER AND LIBCXX_GENERATE_COVERAGE) + message(FATAL_ERROR "LLVM_USE_SANITIZER cannot be used with LIBCXX_GENERATE_COVERAGE") endif() +# Set LIBCXX_BUILD_32_BITS to (LIBCXX_BUILD_32_BITS OR LLVM_BUILD_32_BITS) +# and check that we can build with 32 bits if requested. +if (CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32) + if (LIBCXX_BUILD_32_BITS OR LLVM_BUILD_32_BITS) + if (NOT LLVM_BUILD_32_BITS) # Don't duplicate the output from LLVM + message(STATUS "Building 32 bits executables and libraries.") + endif() + set(LIBCXX_BUILD_32_BITS ON CACHE BOOL "" FORCE) + endif() +elseif(LIBCXX_BUILD_32_BITS) + message(FATAL_ERROR "LIBCXX_BUILD_32_BITS=ON is not supported on this platform.") +endif() + +# Check that this option is not enabled on Apple and emit a usage warning. if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY) if (APPLE) message(FATAL_ERROR "LIBCXX_ENABLE_STATIC_ABI_LIBRARY is not supported on OS X") @@ -84,27 +124,6 @@ if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY) endif() endif() -set(CXXABIS none libcxxabi libcxxrt libstdc++ libsupc++) -if (NOT LIBCXX_CXX_ABI) - if (NOT DEFINED LIBCXX_BUILT_STANDALONE AND - IS_DIRECTORY "${CMAKE_SOURCE_DIR}/projects/libcxxabi") - set(LIBCXX_CXX_ABI_LIBNAME "libcxxabi") - set(LIBCXX_CXX_ABI_INCLUDE_PATHS "${CMAKE_SOURCE_DIR}/projects/libcxxabi/include") - set(LIBCXX_CXX_ABI_INTREE 1) - else () - set(LIBCXX_CXX_ABI_LIBNAME "none") - endif () -else () - set(LIBCXX_CXX_ABI_LIBNAME "${LIBCXX_CXX_ABI}") -endif () -set(LIBCXX_CXX_ABI "${LIBCXX_CXX_ABI}" CACHE STRING - "Specify C++ ABI library to use." FORCE) -set_property(CACHE LIBCXX_CXX_ABI PROPERTY STRINGS ;${CXXABIS}) - -# Build libc++abi with libunwind. We need this option to determine whether to -# link with libunwind or libgcc_s while running the test cases. -option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." OFF) - #=============================================================================== # Configure System #=============================================================================== @@ -114,234 +133,114 @@ set(LIBCXX_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) set(LIBCXX_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX}) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR}) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR}) + # Declare libc++ configuration variables. # They are intended for use as follows: # LIBCXX_CXX_FLAGS: General flags for both the compiler and linker. # LIBCXX_COMPILE_FLAGS: Compile only flags. # LIBCXX_LINK_FLAGS: Linker only flags. -set(LIBCXX_CXX_FLAGS "") set(LIBCXX_COMPILE_FLAGS "") set(LIBCXX_LINK_FLAGS "") +set(LIBCXX_LIBRARIES "") # Configure compiler. include(config-ix) -# Configure ABI library -include(HandleLibCXXABI) + # Configure coverage options. if (LIBCXX_GENERATE_COVERAGE) include(CodeCoverage) set(CMAKE_BUILD_TYPE "COVERAGE" CACHE STRING "" FORCE) endif() +string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) + #=============================================================================== # Setup Compiler Flags #=============================================================================== +include(HandleLLVMOptions) # Setup LLVM flags -# Get required flags. -# On all systems the system c++ standard library headers need to be excluded. -if (MSVC) - # MSVC only has -X, which disables all default includes; including the crt. - # Thus, we do nothing and hope we don't accidentally include any of the C++ - # headers. -else() - if (LIBCXX_HAS_NOSTDINCXX_FLAG) - list(APPEND LIBCXX_COMPILE_FLAGS -nostdinc++) - string(REPLACE "-stdlib=libc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - string(REPLACE "-stdlib=libstdc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - endif() - # If c++1y has been enabled then attempt to use it. Fail if it is no supported - # by the compiler. Otherwise choose c++11 and ensure the compiler supports it. - if (LIBCXX_ENABLE_CXX1Y) - if (LIBCXX_HAS_STDCXX1Y_FLAG) - set(LIBCXX_STD_VERSION c++1y) - else() - message(FATAL_ERROR "c++1y was enabled but the compiler does not support it.") - endif() - else() - if (LIBCXX_HAS_STDCXX11_FLAG) - set(LIBCXX_STD_VERSION c++11) - else() - message(FATAL_ERROR "c++11 is required by libc++ but is not supported by the compiler") - endif() - endif() - # LIBCXX_STD_VERSION should always be set at this point. - list(APPEND LIBCXX_CXX_FLAGS "-std=${LIBCXX_STD_VERSION}") -endif() +include(HandleLibCXXABI) # Steup the ABI library flags -macro(append_if list condition var) - if (${condition}) - list(APPEND ${list} ${var}) - endif() -endmacro() +# Include macros for adding and removing libc++ flags. +include(HandleLibcxxFlags) -# Get warning flags -# Disable the system header pragma. -add_definitions(-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -if (NOT MSVC) - append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_WALL_FLAG -Wall) - list(APPEND LIBCXX_COMPILE_FLAGS -Werror=return-type) +# Remove flags that may have snuck in. +remove_flags(-DNDEBUG -UNDEBUG -D_DEBUG + -stdlib=libc++ -stdlib=libstdc++ -lc++abi -m32) + +# Required flags ============================================================== +add_compile_flags_if_supported(-std=c++11) +if (NOT MSVC AND NOT LIBCXX_SUPPORTS_STD_EQ_CXX11_FLAG) + message(FATAL_ERROR "C++11 is required but the compiler does not support -std=c++11") endif() -append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_W_FLAG -W) -append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_WNO_UNUSED_PARAMETER_FLAG -Wno-unused-parameter) -append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_WWRITE_STRINGS_FLAG -Wwrite-strings) -append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_WNO_LONG_LONG_FLAG -Wno-long-long) +# On all systems the system c++ standard library headers need to be excluded. +# MSVC only has -X, which disables all default includes; including the crt. +# Thus, we do nothing and hope we don't accidentally include any of the C++ +# headers +add_compile_flags_if_supported(-nostdinc++) + +# Target flags ================================================================ +add_flags_if(LIBCXX_BUILD_32_BITS -m32) +add_flags_if(LIBCXX_TARGET_TRIPLE "-target ${LIBCXX_TARGET_TRIPLE}") +add_flags_if(LIBCXX_SYSROOT "--sysroot ${LIBCXX_SYSROOT}") +add_flags_if(LIBCXX_GCC_TOOLCHAIN "-gcc-toolchain ${LIBCXX_GCC_TOOLCHAIN}") + +# Warning flags =============================================================== +add_definitions(-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +add_compile_flags_if_supported( + -Wall -W -Wwrite-strings + -Wno-unused-parameter -Wno-long-long + -Werror=return-type) if (LIBCXX_ENABLE_WERROR) - append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_WERROR_FLAG -Werror) - append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_WX_FLAG -WX) -else() - append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_WNO_ERROR_FLAG -Wno-error) - append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_NO_WX_FLAG -WX-) + add_compile_flags_if_supported(-Werror) + add_compile_flags_if_supported(-WX) endif() if (LIBCXX_ENABLE_PEDANTIC) - append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_PEDANTIC_FLAG -pedantic) + add_compile_flags_if_supported(-pedantic) endif() -# Get feature flags. -# Exceptions +# Exception flags ============================================================= if (LIBCXX_ENABLE_EXCEPTIONS) # Catches C++ exceptions only and tells the compiler to assume that extern C # functions never throw a C++ exception. - append_if(LIBCXX_CXX_FLAGS LIBCXX_HAS_EHSC_FLAG -EHsc) + add_compile_flags_if_supported(-EHsc) else() - list(APPEND LIBCXX_CXX_FLAGS -D_LIBCPP_NO_EXCEPTIONS) - append_if(LIBCXX_CXX_FLAGS LIBCXX_HAS_NO_EHS_FLAG -EHs-) - append_if(LIBCXX_CXX_FLAGS LIBCXX_HAS_NO_EHA_FLAG -EHa-) - append_if(LIBCXX_CXX_FLAGS LIBCXX_HAS_FNO_EXCEPTIONS_FLAG -fno-exceptions) + add_definitions(-D_LIBCPP_NO_EXCEPTIONS) + add_compile_flags_if_supported(-EHs- -EHa-) + add_compile_flags_if_supported(-fno-exceptions) endif() -# RTTI + +# RTTI flags ================================================================== if (NOT LIBCXX_ENABLE_RTTI) - list(APPEND LIBCXX_CXX_FLAGS -D_LIBCPP_NO_RTTI) - append_if(LIBCXX_CXX_FLAGS LIBCXX_HAS_NO_GR_FLAG -GR-) - append_if(LIBCXX_CXX_FLAGS LIBCXX_HAS_FNO_RTTI_FLAG -fno-rtti) + add_definitions(-D_LIBCPP_NO_RTTI) + add_compile_flags_if_supported(-GR-) + add_compile_flags_if_supported(-fno-rtti) endif() -# Assert -string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) + +# Assertion flags ============================================================= +define_if(LIBCXX_ENABLE_ASSERTIONS -UNDEBUG) +define_if_not(LIBCXX_ENABLE_ASSERTIONS -DNDEBUG) if (LIBCXX_ENABLE_ASSERTIONS) # MSVC doesn't like _DEBUG on release builds. See PR 4379. - if (NOT MSVC) - list(APPEND LIBCXX_COMPILE_FLAGS -D_DEBUG) - endif() - # On Release builds cmake automatically defines NDEBUG, so we - # explicitly undefine it: - if (uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE") - list(APPEND LIBCXX_COMPILE_FLAGS -UNDEBUG) - endif() -else() - if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE") - list(APPEND LIBCXX_COMPILE_FLAGS -DNDEBUG) - endif() -endif() -# Static library -if (NOT LIBCXX_ENABLE_SHARED) - list(APPEND LIBCXX_COMPILE_FLAGS -D_LIBCPP_BUILD_STATIC) + define_if_not(MSVC -D_DEBUG) endif() -if (CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32) - if (LIBCXX_BUILD_32_BITS) - message(STATUS "Building 32 bits executables and libraries.") - list(APPEND LIBCXX_CXX_FLAGS "-m32") - endif() -elseif(LIBCXX_BUILD_32_BITS) - message(FATAL_ERROR "LIBCXX_BUILD_32_BITS=ON is not supported on this platform.") -endif() -# This is the _ONLY_ place where add_definitions is called. -if (MSVC) - add_definitions(-D_CRT_SECURE_NO_WARNINGS) -endif() - -# LIBCXX_ENABLE_GLOBAL_FILESYSTEM_NAMESPACE configuration -if (NOT LIBCXX_ENABLE_GLOBAL_FILESYSTEM_NAMESPACE) - add_definitions(-D_LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE) -endif() - -# LIBCXX_ENABLE_STDIN configuration -if (NOT LIBCXX_ENABLE_STDIN) - add_definitions(-D_LIBCPP_HAS_NO_STDIN) -endif() - -# LIBCXX_ENABLE_STDOUT configuration -if (NOT LIBCXX_ENABLE_STDOUT) - add_definitions(-D_LIBCPP_HAS_NO_STDOUT) -endif() - -# LIBCXX_ENABLE_THREADS configuration -if (NOT LIBCXX_ENABLE_THREADS) - add_definitions(-D_LIBCPP_HAS_NO_THREADS) - if (NOT LIBCXX_ENABLE_MONOTONIC_CLOCK) - add_definitions(-D_LIBCPP_HAS_NO_MONOTONIC_CLOCK) - endif() -# Ensure LIBCXX_ENABLE_MONOTONIC_CLOCK is set to ON. -elseif(NOT LIBCXX_ENABLE_MONOTONIC_CLOCK) - message(FATAL_ERROR "LIBCXX_ENABLE_MONOTONIC_CLOCK can only be set to OFF" - " when LIBCXX_ENABLE_THREADS is also set to OFF.") -endif() - -# LIBCXX_ENABLE_THREAD_UNSAFE_C_FUNCTIONS configuration -if (NOT LIBCXX_ENABLE_THREAD_UNSAFE_C_FUNCTIONS) - add_definitions(-D_LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS) -endif() - -# Configure for sanitizers. If LIBCXX_BUILT_STANDALONE then we have to do -# the flag translation ourselves. Othewise LLVM's CMakeList.txt will handle it. -if (LIBCXX_BUILT_STANDALONE) - # NOTE: LLVM_USE_SANITIZER checks for a UNIX like system instead of MSVC. - # But we don't have LLVM_ON_UNIX so checking for MSVC is the best we can do. - if (LLVM_USE_SANITIZER AND NOT MSVC) - append_if(LIBCXX_CXX_FLAGS LIBCXX_HAS_FNO_OMIT_FRAME_POINTER_FLAG - "-fno-omit-frame-pointer") - if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND - NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO") - append_if(LIBCXX_CXX_FLAGS LIBCXX_HAS_GLINE_TABLES_ONLY_FLAG - "-gline-tables-only") - endif() - if (LLVM_USE_SANITIZER STREQUAL "Address") - list(APPEND LIBCXX_CXX_FLAGS "-fsanitize=address") - elseif (LLVM_USE_SANITIZER MATCHES "Memory(WithOrigins)?") - list(APPEND LIBCXX_CXX_FLAGS "-fsanitize=memory") - if (LLVM_USE_SANITIZER STREQUAL "MemoryWithOrigins") - list(APPEND LIBCXX_CXX_FLAGS "-fsanitize-memory-track-origins") - endif() - elseif (LLVM_USE_SANITIZER STREQUAL "Undefined") - list(APPEND LIBCXX_CXX_FLAGS - "-fsanitize=undefined -fno-sanitize=vptr,function -fno-sanitize-recover") - elseif (LLVM_USE_SANITIZER STREQUAL "Thread") - list(APPEND LIBCXX_CXX_FLAGS "-fsanitize=thread") - else() - message(WARNING "Unsupported value of LLVM_USE_SANITIZER: ${LLVM_USE_SANITIZER}") - endif() - elseif(MSVC) - message(WARNING "LLVM_USE_SANITIZER is not supported with MSVC") - endif() -endif() - -append_if(LIBCXX_CXX_FLAGS LIBCXX_TARGET_TRIPLE - "-target ${LIBCXX_TARGET_TRIPLE}") - -append_if(LIBCXX_CXX_FLAGS LIBCXX_SYSROOT "--sysroot ${LIBCXX_SYSROOT}") -append_if(LIBCXX_CXX_FLAGS LIBCXX_GCC_TOOLCHAIN - "-gcc-toolchain ${LIBCXX_GCC_TOOLCHAIN}") - -if (LLVM_USE_SANITIZER AND LIBCXX_GENERATE_COVERAGE) - message(FATAL_ERROR "LLVM_USE_SANITIZER cannot be used with LIBCXX_GENERATE_COVERAGE") -endif() - -string(REPLACE ";" " " LIBCXX_CXX_FLAGS "${LIBCXX_CXX_FLAGS}") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LIBCXX_CXX_FLAGS}") +# Feature flags =============================================================== +define_if(MSVC -D_CRT_SECURE_NO_WARNINGS) +define_if_not(LIBCXX_ENABLE_GLOBAL_FILESYSTEM_NAMESPACE -D_LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE) +define_if_not(LIBCXX_ENABLE_STDIN -D_LIBCPP_HAS_NO_STDIN) +define_if_not(LIBCXX_ENABLE_STDOUT -D_LIBCPP_HAS_NO_STDOUT) +define_if_not(LIBCXX_ENABLE_THREADS -D_LIBCPP_HAS_NO_THREADS) +define_if_not(LIBCXX_ENABLE_MONOTONIC_CLOCK -D_LIBCPP_HAS_NO_MONOTONIC_CLOCK) +define_if_not(LIBCXX_ENABLE_THREAD_UNSAFE_C_FUNCTIONS -D_LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS) #=============================================================================== -# Setup Source Code +# Setup Source Code And Tests #=============================================================================== - include_directories(include) add_subdirectory(include) - -# Add source code. This also contains all of the logic for deciding linker flags -# soname, etc... add_subdirectory(lib) - -#=============================================================================== -# Setup Tests -#=============================================================================== - add_subdirectory(test) diff --git a/libcxx/cmake/Modules/FindLLVM.cmake b/libcxx/cmake/Modules/FindLLVM.cmake new file mode 100644 index 0000000..35105c8 --- /dev/null +++ b/libcxx/cmake/Modules/FindLLVM.cmake @@ -0,0 +1,79 @@ + +if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + # Rely on llvm-config. + set(CONFIG_OUTPUT) + find_program(LLVM_CONFIG "llvm-config") + if(DEFINED LLVM_PATH) + set(LLVM_INCLUDE_DIR ${LLVM_INCLUDE_DIR} CACHE PATH "Path to llvm/include") + set(LLVM_PATH ${LLVM_PATH} CACHE PATH "Path to LLVM source tree") + set(LLVM_MAIN_SRC_DIR ${LLVM_PATH}) + set(LLVM_CMAKE_PATH "${LLVM_PATH}/cmake/modules") + elseif(LLVM_CONFIG) + message(STATUS "Found LLVM_CONFIG as ${LLVM_CONFIG}") + set(CONFIG_COMMAND ${LLVM_CONFIG} + "--includedir" + "--prefix" + "--src-root") + execute_process( + COMMAND ${CONFIG_COMMAND} + RESULT_VARIABLE HAD_ERROR + OUTPUT_VARIABLE CONFIG_OUTPUT + ) + if(NOT HAD_ERROR) + string(REGEX REPLACE + "[ \t]*[\r\n]+[ \t]*" ";" + CONFIG_OUTPUT ${CONFIG_OUTPUT}) + else() + string(REPLACE ";" " " CONFIG_COMMAND_STR "${CONFIG_COMMAND}") + message(STATUS "${CONFIG_COMMAND_STR}") + message(FATAL_ERROR "llvm-config failed with status ${HAD_ERROR}") + endif() + + list(GET CONFIG_OUTPUT 0 INCLUDE_DIR) + list(GET CONFIG_OUTPUT 1 LLVM_OBJ_ROOT) + list(GET CONFIG_OUTPUT 2 MAIN_SRC_DIR) + + set(LLVM_INCLUDE_DIR ${INCLUDE_DIR} CACHE PATH "Path to llvm/include") + set(LLVM_BINARY_DIR ${LLVM_OBJ_ROOT} CACHE PATH "Path to LLVM build tree") + set(LLVM_MAIN_SRC_DIR ${MAIN_SRC_DIR} CACHE PATH "Path to LLVM source tree") + set(LLVM_CMAKE_PATH "${LLVM_BINARY_DIR}/share/llvm/cmake") + else() + message(FATAL_ERROR "llvm-config not found and LLVM_MAIN_SRC_DIR not defined. " + "Reconfigure with -DLLVM_CONFIG=path/to/llvm-config " + "or -DLLVM_PATH=path/to/llvm-source-root.") + endif() + + if (NOT EXISTS ${LLVM_MAIN_SRC_DIR}) + message(FATAL_ERROR "Not found: ${LLVM_MAIN_SRC_DIR}") + endif() + + if(NOT EXISTS ${LLVM_CMAKE_PATH}) + message(FATAL_ERROR "Not found: ${LLVM_CMAKE_PATH}") + endif() + + list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_PATH}") + list(APPEND CMAKE_MODULE_PATH "${LLVM_MAIN_SRC_DIR}/cmake/modules") + + + if(LLVM_LIT) + # Define the default arguments to use with 'lit', and an option for the user + # to override. + set(LIT_ARGS_DEFAULT "-sv --show-xfail --show-unsupported") + if (MSVC OR XCODE) + set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar") + endif() + set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit") + + # On Win32 hosts, provide an option to specify the path to the GnuWin32 tools. + if( WIN32 AND NOT CYGWIN ) + set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools") + endif() + else() + set(LLVM_INCLUDE_TESTS OFF) + endif() + + set(LIBCXX_BUILT_STANDALONE 1) +else() + set(LLVM_MAIN_SRC_DIR "${CMAKE_SOURCE_DIR}" CACHE PATH "Path to LLVM source tree") + set(LLVM_LIT "${CMAKE_SOURCE_DIR}/utils/lit/lit.py") +endif() diff --git a/libcxx/cmake/Modules/HandleLibCXXABI.cmake b/libcxx/cmake/Modules/HandleLibCXXABI.cmake index 73723e3..4224882 100644 --- a/libcxx/cmake/Modules/HandleLibCXXABI.cmake +++ b/libcxx/cmake/Modules/HandleLibCXXABI.cmake @@ -58,6 +58,21 @@ macro(setup_abi_lib abidefines abilib abifiles abidirs) endmacro() +# Setup the default options if LIBCXX_CXX_ABI is not specified. +if (NOT LIBCXX_CXX_ABI) + if (NOT DEFINED LIBCXX_BUILT_STANDALONE AND + IS_DIRECTORY "${CMAKE_SOURCE_DIR}/projects/libcxxabi") + set(LIBCXX_CXX_ABI_LIBNAME "libcxxabi") + set(LIBCXX_CXX_ABI_INCLUDE_PATHS "${CMAKE_SOURCE_DIR}/projects/libcxxabi/include") + set(LIBCXX_CXX_ABI_INTREE 1) + else () + set(LIBCXX_CXX_ABI_LIBNAME "none") + endif () +else () + set(LIBCXX_CXX_ABI_LIBNAME "${LIBCXX_CXX_ABI}") +endif () + +# Configure based on the selected ABI library. if ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libstdc++" OR "${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libsupc++") set(_LIBSUPCXX_INCLUDE_FILES diff --git a/libcxx/cmake/Modules/HandleLibcxxFlags.cmake b/libcxx/cmake/Modules/HandleLibcxxFlags.cmake new file mode 100644 index 0000000..2a450da --- /dev/null +++ b/libcxx/cmake/Modules/HandleLibcxxFlags.cmake @@ -0,0 +1,147 @@ +# HandleLibcxxFlags - A set of macros used to setup the flags used to compile +# and link libc++. These macros add flags to the following CMake variables. +# - LIBCXX_COMPILE_FLAGS: flags used to compile libc++ +# - LIBCXX_LINK_FLAGS: flags used to link libc++ +# - LIBCXX_LIBRARIES: libraries to link libc++ to. + +include(CheckCXXCompilerFlag) + +unset(add_flag_if_supported) + +# Mangle the name of a compiler flag into a valid CMake identifier. +# Ex: --std=c++11 -> STD_EQ_CXX11 +macro(mangle_name str output) + string(STRIP "${str}" strippedStr) + string(REGEX REPLACE "^/" "" strippedStr "${strippedStr}") + string(REGEX REPLACE "^-+" "" strippedStr "${strippedStr}") + string(REGEX REPLACE "-+$" "" strippedStr "${strippedStr}") + string(REPLACE "-" "_" strippedStr "${strippedStr}") + string(REPLACE "=" "_EQ_" strippedStr "${strippedStr}") + string(REPLACE "+" "X" strippedStr "${strippedStr}") + string(TOUPPER "${strippedStr}" ${output}) +endmacro() + +# Remove a list of flags from all CMake variables that affect compile flags. +# This can be used to remove unwanted flags specified on the command line +# or added in other parts of LLVM's cmake configuration. +macro(remove_flags) + foreach(var ${ARGN}) + string(REPLACE "${var}" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + string(REPLACE "${var}" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") + string(REPLACE "${var}" "" CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}") + string(REPLACE "${var}" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}") + string(REPLACE "${var}" "" CMAKE_SHARED_MODULE_FLAGS "${CMAKE_SHARED_MODULE_FLAGS}") + remove_definitions(${var}) + endforeach() +endmacro(remove_flags) + +# Add a macro definition if condition is true. +macro(define_if condition def) + if (${condition}) + add_definitions(${def}) + endif() +endmacro() + +# Add a macro definition if condition is not true. +macro(define_if_not condition def) + if (NOT ${condition}) + add_definitions(${def}) + endif() +endmacro() + +# Add a specified list of flags to both 'LIBCXX_COMPILE_FLAGS' and +# 'LIBCXX_LINK_FLAGS'. +macro(add_flags) + foreach(value ${ARGN}) + list(APPEND LIBCXX_COMPILE_FLAGS ${value}) + list(APPEND LIBCXX_LINK_FLAGS ${value}) + endforeach() +endmacro() + +# If the specified 'condition' is true then add a list of flags to both +# 'LIBCXX_COMPILE_FLAGS' and 'LIBCXX_LINK_FLAGS'. +macro(add_flags_if condition) + if (${condition}) + add_flags(${ARGN}) + endif() +endmacro() + +# Add each flag in the list to LIBCXX_COMPILE_FLAGS and LIBCXX_LINK_FLAGS +# if that flag is supported by the current compiler. +macro(add_flags_if_supported) + foreach(flag ${ARGN}) + mangle_name("${flag}" flagname) + check_cxx_compiler_flag("${flag}" "LIBCXX_SUPPORTS_${flagname}_FLAG") + add_flags_if(LIBCXX_SUPPORTS_${flagname}_FLAG ${flag}) + endforeach() +endmacro() + +# Add a list of flags to 'LIBCXX_COMPILE_FLAGS'. +macro(add_compile_flags) + foreach(f ${ARGN}) + list(APPEND LIBCXX_COMPILE_FLAGS ${f}) + endforeach() +endmacro() + +# If 'condition' is true then add the specified list of flags to +# 'LIBCXX_COMPILE_FLAGS' +macro(add_compile_flags_if condition) + if (${condition}) + add_compile_flags(${ARGN}) + endif() +endmacro() + +# For each specified flag, add that flag to 'LIBCXX_COMPILE_FLAGS' if the +# flag is supported by the C++ compiler. +macro(add_compile_flags_if_supported) + foreach(flag ${ARGN}) + mangle_name("${flag}" flagname) + check_cxx_compiler_flag("-Werror ${flag}" "LIBCXX_SUPPORTS_${flagname}_FLAG") + add_compile_flags_if(LIBCXX_SUPPORTS_${flagname}_FLAG ${flag}) + endforeach() +endmacro() + +# Add a list of flags to 'LIBCXX_LINK_FLAGS'. +macro(add_link_flags) + foreach(f ${ARGN}) + list(APPEND LIBCXX_LINK_FLAGS ${f}) + endforeach() +endmacro() + +# If 'condition' is true then add the specified list of flags to +# 'LIBCXX_LINK_FLAGS' +macro(add_link_flags_if condition) + if (${condition}) + add_link_flags(${ARGN}) + endif() +endmacro() + +# For each specified flag, add that flag to 'LIBCXX_LINK_FLAGS' if the +# flag is supported by the C++ compiler. +macro(add_link_flags_if_supported) + foreach(flag ${ARGN}) + mangle_name("${flag}" flagname) + check_cxx_compiler_flag("${flag}" "LIBCXX_SUPPORTS_${flagname}_FLAG") + add_link_flags_if(LIBCXX_SUPPORTS_${flagname}_FLAG ${flag}) + endforeach() +endmacro() + +# Add a list of libraries or link flags to 'LIBCXX_LIBRARIES'. +macro(add_library_flags) + foreach(lib ${ARGN}) + list(APPEND LIBCXX_LIBRARIES ${lib}) + endforeach() +endmacro() + +# if 'condition' is true then add the specified list of libraries and flags +# to 'LIBCXX_LIBRARIES'. +macro(add_library_flags_if condition) + if(${condition}) + add_library_flags(${ARGN}) + endif() +endmacro() + +# Turn a comma separated CMake list into a space separated string. +macro(split_list listname) + string(REPLACE ";" " " ${listname} "${${listname}}") +endmacro() diff --git a/libcxx/cmake/config-ix.cmake b/libcxx/cmake/config-ix.cmake index 428d737..ace7aca 100644 --- a/libcxx/cmake/config-ix.cmake +++ b/libcxx/cmake/config-ix.cmake @@ -2,23 +2,7 @@ include(CheckLibraryExists) include(CheckCXXCompilerFlag) # Check compiler flags -check_cxx_compiler_flag(-std=c++11 LIBCXX_HAS_STDCXX11_FLAG) -check_cxx_compiler_flag(-std=c++1y LIBCXX_HAS_STDCXX1Y_FLAG) -check_cxx_compiler_flag(-fPIC LIBCXX_HAS_FPIC_FLAG) -check_cxx_compiler_flag(-fno-omit-frame-pointer LIBCXX_HAS_FNO_OMIT_FRAME_POINTER_FLAG) -check_cxx_compiler_flag(-nodefaultlibs LIBCXX_HAS_NODEFAULTLIBS_FLAG) -check_cxx_compiler_flag(-nostdinc++ LIBCXX_HAS_NOSTDINCXX_FLAG) -check_cxx_compiler_flag(-Wall LIBCXX_HAS_WALL_FLAG) -check_cxx_compiler_flag(-W LIBCXX_HAS_W_FLAG) -check_cxx_compiler_flag(-Wno-unused-parameter LIBCXX_HAS_WNO_UNUSED_PARAMETER_FLAG) -check_cxx_compiler_flag(-Wwrite-strings LIBCXX_HAS_WWRITE_STRINGS_FLAG) -check_cxx_compiler_flag(-Wno-long-long LIBCXX_HAS_WNO_LONG_LONG_FLAG) -check_cxx_compiler_flag(-pedantic LIBCXX_HAS_PEDANTIC_FLAG) -check_cxx_compiler_flag(-Werror LIBCXX_HAS_WERROR_FLAG) -check_cxx_compiler_flag(-Wno-error LIBCXX_HAS_WNO_ERROR_FLAG) -check_cxx_compiler_flag(-fno-exceptions LIBCXX_HAS_FNO_EXCEPTIONS_FLAG) -check_cxx_compiler_flag(-fno-rtti LIBCXX_HAS_FNO_RTTI_FLAG) -check_cxx_compiler_flag(-gline-tables-only LIBCXX_HAS_GLINE_TABLES_ONLY_FLAG) + check_cxx_compiler_flag(/WX LIBCXX_HAS_WX_FLAG) check_cxx_compiler_flag(/WX- LIBCXX_HAS_NO_WX_FLAG) check_cxx_compiler_flag(/EHsc LIBCXX_HAS_EHSC_FLAG) @@ -26,6 +10,7 @@ check_cxx_compiler_flag(/EHs- LIBCXX_HAS_NO_EHS_FLAG) check_cxx_compiler_flag(/EHa- LIBCXX_HAS_NO_EHA_FLAG) check_cxx_compiler_flag(/GR- LIBCXX_HAS_NO_GR_FLAG) + # Check libraries check_library_exists(pthread pthread_create "" LIBCXX_HAS_PTHREAD_LIB) check_library_exists(c printf "" LIBCXX_HAS_C_LIB) diff --git a/libcxx/lib/CMakeLists.txt b/libcxx/lib/CMakeLists.txt index a32f293..26dee67 100644 --- a/libcxx/lib/CMakeLists.txt +++ b/libcxx/lib/CMakeLists.txt @@ -25,48 +25,23 @@ if (MSVC_IDE OR XCODE) endif() if (LIBCXX_ENABLE_SHARED) - add_library(cxx SHARED - ${LIBCXX_SOURCES} - ${LIBCXX_HEADERS} - ) + add_library(cxx SHARED ${LIBCXX_SOURCES} ${LIBCXX_HEADERS}) else() - add_library(cxx STATIC - ${LIBCXX_SOURCES} - ${LIBCXX_HEADERS} - ) -endif() - -#if LIBCXX_CXX_ABI_LIBRARY_PATH is defined we want to add it to the search path. -if (DEFINED LIBCXX_CXX_ABI_LIBRARY_PATH) - target_link_libraries(cxx "-L${LIBCXX_CXX_ABI_LIBRARY_PATH}") + add_library(cxx STATIC ${LIBCXX_SOURCES} ${LIBCXX_HEADERS}) endif() if (DEFINED LIBCXX_CXX_ABI_DEPS) add_dependencies(cxx LIBCXX_CXX_ABI_DEPS) endif() -set(libraries "") -if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY) - # TODO(ericwf): Remove these GNU specific linker flags and let CMake do the - # configuration. This will be more portable. - list(APPEND libraries "-Wl,--whole-archive" "-Wl,-Bstatic") - list(APPEND libraries "${LIBCXX_CXX_ABI_LIBRARY}") - list(APPEND libraries "-Wl,-Bdynamic" "-Wl,--no-whole-archive") -else() - list(APPEND libraries "${LIBCXX_CXX_ABI_LIBRARY}") -endif() +#if LIBCXX_CXX_ABI_LIBRARY_PATH is defined we want to add it to the search path. +add_link_flags_if(LIBCXX_CXX_ABI_LIBRARY_PATH "-L${LIBCXX_CXX_ABI_LIBRARY_PATH}") -# Generate library list. -append_if(libraries LIBCXX_HAS_PTHREAD_LIB pthread) -append_if(libraries LIBCXX_HAS_C_LIB c) -append_if(libraries LIBCXX_HAS_M_LIB m) -append_if(libraries LIBCXX_HAS_RT_LIB rt) -append_if(libraries LIBCXX_HAS_GCC_S_LIB gcc_s) - -if (LIBCXX_COVERAGE_LIBRARY) - target_link_libraries(cxx ${LIBCXX_COVERAGE_LIBRARY}) -endif() -target_link_libraries(cxx ${libraries}) +add_library_flags_if(LIBCXX_COVERAGE_LIBRARY "${LIBCXX_COVERAGE_LIBRARY}") + +add_library_flags_if(LIBCXX_ENABLE_STATIC_ABI_LIBRARY "-Wl,--whole-archive" "-Wl,-Bstatic") +add_library_flags("${LIBCXX_CXX_ABI_LIBRARY}") +add_library_flags_if(LIBCXX_ENABLE_STATIC_ABI_LIBRARY "-Wl,-Bdynamic" "-Wl,--no-whole-archive") if (APPLE AND LLVM_USE_SANITIZER) if ("${LLVM_USE_SANITIZER}" STREQUAL "Address") @@ -89,15 +64,21 @@ if (APPLE AND LLVM_USE_SANITIZER) set(LIBCXX_SANITIZER_LIBRARY "${LIBDIR}/${LIBFILE}") set(LIBCXX_SANITIZER_LIBRARY "${LIBCXX_SANITIZER_LIBRARY}" PARENT_SCOPE) message(STATUS "Manually linking compiler-rt library: ${LIBCXX_SANITIZER_LIBRARY}") - target_link_libraries(cxx "${LIBCXX_SANITIZER_LIBRARY}") - target_link_libraries(cxx "-Wl,-rpath,${LIBDIR}") + add_library_flags("${LIBCXX_SANITIZER_LIBRARY}") + add_link_flags("-Wl,-rpath,${LIBDIR}") endif() endif() +# Generate library list. +add_library_flags_if(LIBCXX_HAS_PTHREAD_LIB pthread) +add_library_flags_if(LIBCXX_HAS_C_LIB c) +add_library_flags_if(LIBCXX_HAS_M_LIB m) +add_library_flags_if(LIBCXX_HAS_RT_LIB rt) +add_library_flags_if(LIBCXX_HAS_GCC_S_LIB gcc_s) # Setup flags. -append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_FPIC_FLAG -fPIC) -append_if(LIBCXX_LINK_FLAGS LIBCXX_HAS_NODEFAULTLIBS_FLAG -nodefaultlibs) +add_flags_if_supported(-fPIC) +add_link_flags_if_supported(-nodefaultlibs) if ( APPLE AND (LIBCXX_CXX_ABI_LIBNAME STREQUAL "libcxxabi" OR LIBCXX_CXX_ABI_LIBNAME STREQUAL "none")) @@ -106,8 +87,8 @@ if ( APPLE AND (LIBCXX_CXX_ABI_LIBNAME STREQUAL "libcxxabi" OR endif() if ( CMAKE_OSX_DEPLOYMENT_TARGET STREQUAL "10.6" ) - list(APPEND LIBCXX_COMPILE_FLAGS "-U__STRICT_ANSI__") - list(APPEND LIBCXX_LINK_FLAGS + add_definitions(-D__STRICT_ANSI__) + add_link_flags( "-compatibility_version 1" "-current_version 1" "-install_name /usr/lib/libc++.1.dylib" @@ -129,7 +110,7 @@ if ( APPLE AND (LIBCXX_CXX_ABI_LIBNAME STREQUAL "libcxxabi" OR set (OSX_RE_EXPORT_LINE "/usr/lib/libc++abi.dylib -Wl,-reexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/libc++abi${LIBCXX_LIBCPPABI_VERSION}.exp") endif() - list(APPEND LIBCXX_LINK_FLAGS + add_link_flags( "-compatibility_version 1" "-install_name /usr/lib/libc++.1.dylib" "-Wl,-unexported_symbols_list,${CMAKE_CURRENT_SOURCE_DIR}/libc++unexp.exp" @@ -139,8 +120,9 @@ if ( APPLE AND (LIBCXX_CXX_ABI_LIBNAME STREQUAL "libcxxabi" OR endif() endif() -string(REPLACE ";" " " LIBCXX_COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}") -string(REPLACE ";" " " LIBCXX_LINK_FLAGS "${LIBCXX_LINK_FLAGS}") +target_link_libraries(cxx ${LIBCXX_LIBRARIES}) +split_list(LIBCXX_COMPILE_FLAGS) +split_list(LIBCXX_LINK_FLAGS) set_target_properties(cxx PROPERTIES diff --git a/libcxx/test/CMakeLists.txt b/libcxx/test/CMakeLists.txt index ca937a8..178e6d9 100644 --- a/libcxx/test/CMakeLists.txt +++ b/libcxx/test/CMakeLists.txt @@ -6,84 +6,47 @@ macro(pythonize_bool var) endif() endmacro() -set(LIT_EXECUTABLE "" CACHE FILEPATH "Path to LLVM's llvm-lit.") - -if(LIBCXX_BUILT_STANDALONE) - # Make sure we can use the console pool for recent cmake and ninja > 1.5 - if(CMAKE_VERSION VERSION_LESS 3.1.20141117) - set(cmake_3_2_USES_TERMINAL) - else() - set(cmake_3_2_USES_TERMINAL USES_TERMINAL) - endif() -else() - include(FindPythonInterp) - if(PYTHONINTERP_FOUND) - set(LIT_EXECUTABLE - ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/utils/lit/lit.py) - else() - message(WARNING "Could not find Python, cannot set LIT_EXECUTABLE.") - endif() +set(LIBCXX_LIT_VARIANT "libcxx" CACHE STRING + "Configuration variant to use for LIT.") + +pythonize_bool(LIBCXX_ENABLE_EXCEPTIONS) +pythonize_bool(LIBCXX_ENABLE_RTTI) +pythonize_bool(LIBCXX_ENABLE_SHARED) +pythonize_bool(LIBCXX_BUILD_32_BITS) +pythonize_bool(LIBCXX_ENABLE_GLOBAL_FILESYSTEM_NAMESPACE) +pythonize_bool(LIBCXX_ENABLE_STDIN) +pythonize_bool(LIBCXX_ENABLE_STDOUT) +pythonize_bool(LIBCXX_ENABLE_THREADS) +pythonize_bool(LIBCXX_ENABLE_THREAD_UNSAFE_C_FUNCTIONS) +pythonize_bool(LIBCXX_ENABLE_MONOTONIC_CLOCK) +pythonize_bool(LIBCXX_GENERATE_COVERAGE) +pythonize_bool(LIBCXXABI_USE_LLVM_UNWINDER) + +# The tests shouldn't link to any ABI library when it has been linked into +# libc++ statically. +if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY) + set(LIBCXX_CXX_ABI_LIBNAME "none") endif() - -if (LIT_EXECUTABLE) - set(LIT_ARGS_DEFAULT "-sv --show-unsupported --show-xfail") - if (MSVC OR XCODE) - set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar") - endif() - set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" - CACHE STRING "Default options for lit") - set(LIT_ARGS "${LLVM_LIT_ARGS}") - separate_arguments(LIT_ARGS) - - set(LIBCXX_LIT_VARIANT "libcxx" CACHE STRING - "Configuration variant to use for LIT.") - - pythonize_bool(LIBCXX_ENABLE_EXCEPTIONS) - pythonize_bool(LIBCXX_ENABLE_RTTI) - pythonize_bool(LIBCXX_ENABLE_SHARED) - pythonize_bool(LIBCXX_BUILD_32_BITS) - pythonize_bool(LIBCXX_ENABLE_GLOBAL_FILESYSTEM_NAMESPACE) - pythonize_bool(LIBCXX_ENABLE_STDIN) - pythonize_bool(LIBCXX_ENABLE_STDOUT) - pythonize_bool(LIBCXX_ENABLE_THREADS) - pythonize_bool(LIBCXX_ENABLE_THREAD_UNSAFE_C_FUNCTIONS) - pythonize_bool(LIBCXX_ENABLE_MONOTONIC_CLOCK) - pythonize_bool(LIBCXX_GENERATE_COVERAGE) - pythonize_bool(LIBCXXABI_USE_LLVM_UNWINDER) - - # The tests shouldn't link to any ABI library when it has been linked into - # libc++ statically. - if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY) - set(LIBCXX_CXX_ABI_LIBNAME "none") - endif() - set(LIBCXX_TARGET_INFO "libcxx.test.target_info.LocalTI" CACHE STRING - "TargetInfo to use when setting up test environment.") - set(LIBCXX_EXECUTOR "None" CACHE STRING - "Executor to use when running tests.") - - set(AUTO_GEN_COMMENT "## Autogenerated by libcxx configuration.\n# Do not edit!") - - configure_file( - ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in - ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg - @ONLY) - - add_custom_target(check-libcxx - COMMAND ${LIT_EXECUTABLE} - ${LIT_ARGS} - ${CMAKE_CURRENT_BINARY_DIR} - DEPENDS cxx - COMMENT "Running libcxx tests" - ${cmake_3_2_USES_TERMINAL}) - - if (LIBCXX_GENERATE_COVERAGE) - include(CodeCoverage) - set(output_dir "${CMAKE_CURRENT_BINARY_DIR}/coverage") - set(capture_dirs "${LIBCXX_LIB_CMAKEFILES_DIR}/cxx.dir/;${CMAKE_CURRENT_BINARY_DIR}") - set(extract_dirs "${LIBCXX_SOURCE_DIR}/include;${LIBCXX_SOURCE_DIR}/src") - setup_lcov_test_target_coverage("cxx" "${output_dir}" "${capture_dirs}" "${extract_dirs}") - endif() -else() - message(WARNING - "LIT_EXECUTABLE not set, no check-libcxx target will be available!") +set(LIBCXX_TARGET_INFO "libcxx.test.target_info.LocalTI" CACHE STRING + "TargetInfo to use when setting up test environment.") +set(LIBCXX_EXECUTOR "None" CACHE STRING + "Executor to use when running tests.") + +set(AUTO_GEN_COMMENT "## Autogenerated by libcxx configuration.\n# Do not edit!") + +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in + ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg + @ONLY) + +add_lit_testsuite(check-libcxx "Running libcxx tests" + ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS cxx) + +if (LIBCXX_GENERATE_COVERAGE) + include(CodeCoverage) + set(output_dir "${CMAKE_CURRENT_BINARY_DIR}/coverage") + set(capture_dirs "${LIBCXX_LIB_CMAKEFILES_DIR}/cxx.dir/;${CMAKE_CURRENT_BINARY_DIR}") + set(extract_dirs "${LIBCXX_SOURCE_DIR}/include;${LIBCXX_SOURCE_DIR}/src") + setup_lcov_test_target_coverage("cxx" "${output_dir}" "${capture_dirs}" "${extract_dirs}") endif() diff --git a/libcxx/test/lit.site.cfg.in b/libcxx/test/lit.site.cfg.in index bac8ba9..765ee7c 100644 --- a/libcxx/test/lit.site.cfg.in +++ b/libcxx/test/lit.site.cfg.in @@ -1,6 +1,5 @@ @AUTO_GEN_COMMENT@ config.cxx_under_test = "@LIBCXX_COMPILER@" -config.std = "@LIBCXX_STD_VERSION@" config.libcxx_src_root = "@LIBCXX_SOURCE_DIR@" config.libcxx_obj_root = "@LIBCXX_BINARY_DIR@" config.cxx_library_root = "@LIBCXX_LIBRARY_DIR@" diff --git a/libcxx/www/index.html b/libcxx/www/index.html index 7308e8a..e3961b1 100644 --- a/libcxx/www/index.html +++ b/libcxx/www/index.html @@ -184,26 +184,30 @@

In-tree build:

-

Out-of-tree build:

+

Out-of-tree buildc:

-- 2.7.4