diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt --- a/libcxx/include/CMakeLists.txt +++ b/libcxx/include/CMakeLists.txt @@ -202,14 +202,6 @@ add_custom_target(cxx-generated-config ALL DEPENDS ${LIBCXX_BINARY_DIR}/__generated_config) -# In some build configurations (like bootstrapping clang), we need to be able to -# install the libcxx headers before the CMake configuration for libcxx runs. Making -# the name of this target configurable allows LLVM/runtimes/CMakeLists.txt to -# add this subdirectory to the LLVM build to put libcxx's headers in place -# before libcxx's build configuration is run. -if (NOT CXX_HEADER_TARGET) - set(CXX_HEADER_TARGET cxx-headers) -endif() if(LIBCXX_HEADER_DIR) set(output_dir ${LIBCXX_HEADER_DIR}/include/c++/v1) @@ -234,23 +226,23 @@ list(APPEND out_files ${dst}) add_custom_target(generate-cxx-headers DEPENDS ${out_files}) - add_library(${CXX_HEADER_TARGET} INTERFACE) - add_dependencies(${CXX_HEADER_TARGET} generate-cxx-headers ${LIBCXX_CXX_ABI_HEADER_TARGET}) + add_library(cxx-headers INTERFACE) + add_dependencies(cxx-headers generate-cxx-headers ${LIBCXX_CXX_ABI_HEADER_TARGET}) # TODO: Use target_include_directories once we figure out why that breaks the runtimes build if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" OR "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC") - target_compile_options(${CXX_HEADER_TARGET} INTERFACE /I "${output_dir}") + target_compile_options(cxx-headers INTERFACE /I "${output_dir}") else() - target_compile_options(${CXX_HEADER_TARGET} INTERFACE -I "${output_dir}") + target_compile_options(cxx-headers INTERFACE -I "${output_dir}") endif() # Make sure the generated __config_site header is included when we build the library. if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" OR "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC") - target_compile_options(${CXX_HEADER_TARGET} INTERFACE /FI "${LIBCXX_BINARY_DIR}/__config_site") + target_compile_options(cxx-headers INTERFACE /FI "${LIBCXX_BINARY_DIR}/__config_site") else() - target_compile_options(${CXX_HEADER_TARGET} INTERFACE -include "${LIBCXX_BINARY_DIR}/__config_site") + target_compile_options(cxx-headers INTERFACE -include "${LIBCXX_BINARY_DIR}/__config_site") endif() else() - add_library(${CXX_HEADER_TARGET} INTERFACE) + add_library(cxx-headers INTERFACE) endif() if (LIBCXX_INSTALL_HEADERS) @@ -258,7 +250,7 @@ get_filename_component(dir ${file} DIRECTORY) install(FILES ${file} DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}include/c++/v1/${dir} - COMPONENT ${CXX_HEADER_TARGET} + COMPONENT cxx-headers PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ ) endforeach() @@ -268,15 +260,15 @@ DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}include/c++/v1 PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ RENAME __config - COMPONENT ${CXX_HEADER_TARGET}) + COMPONENT cxx-headers) if (NOT CMAKE_CONFIGURATION_TYPES) - add_custom_target(install-${CXX_HEADER_TARGET} - DEPENDS ${CXX_HEADER_TARGET} cxx-generated-config + add_custom_target(install-cxx-headers + DEPENDS cxx-headers cxx-generated-config COMMAND "${CMAKE_COMMAND}" - -DCMAKE_INSTALL_COMPONENT=${CXX_HEADER_TARGET} + -DCMAKE_INSTALL_COMPONENT=cxx-headers -P "${CMAKE_BINARY_DIR}/cmake_install.cmake") # Stripping is a no-op for headers - add_custom_target(install-${CXX_HEADER_TARGET}-stripped DEPENDS install-${CXX_HEADER_TARGET}) + add_custom_target(install-cxx-headers-stripped DEPENDS install-cxx-headers) endif() endif() diff --git a/llvm/runtimes/CMakeLists.txt b/llvm/runtimes/CMakeLists.txt --- a/llvm/runtimes/CMakeLists.txt +++ b/llvm/runtimes/CMakeLists.txt @@ -98,9 +98,17 @@ include(CheckLibraryExists) include(CheckCCompilerFlag) + include(CMakePushCheckState) - # We don't have libc++ (yet). - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdlib++") + cmake_push_check_state() + + # We don't have libc++ (yet)... + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdinc++ -nostdlib++") + + # ...but we need access to libc++ headers for CMake checks to succeed. + if (LLVM_EXTERNAL_LIBCXX_SOURCE_DIR AND "libcxx" IN_LIST LLVM_ENABLE_RUNTIMES) + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -isystem ${LLVM_EXTERNAL_LIBCXX_SOURCE_DIR}/include") + endif() # Avoid checking whether the compiler is working. set(LLVM_COMPILER_CHECKED ON) @@ -110,8 +118,7 @@ include(HandleLLVMOptions) include(FindPythonInterp) - # Remove the -nostdlib++ option we've added earlier. - string(REPLACE "-nostdlib++" "" CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") + cmake_pop_check_state() # Use libtool instead of ar if you are both on an Apple host, and targeting Apple. if(CMAKE_HOST_APPLE AND APPLE) @@ -215,15 +222,6 @@ else() # if this is included from LLVM's CMake include(LLVMExternalProjectUtils) - if (LLVM_EXTERNAL_LIBCXX_SOURCE_DIR AND "libcxx" IN_LIST LLVM_ENABLE_RUNTIMES) - # This looks wrong, but libcxx's build actually wants the header dir to be - # the root build dir, not the include directory. - set(LIBCXX_BINARY_DIR ${LLVM_BINARY_DIR}) - set(LIBCXX_SOURCE_DIR ${LLVM_EXTERNAL_LIBCXX_SOURCE_DIR}) - set(LIBCXX_HEADER_DIR ${LLVM_BINARY_DIR}) - set(CXX_HEADER_TARGET runtime-libcxx-headers) - add_subdirectory(${LLVM_EXTERNAL_LIBCXX_SOURCE_DIR}/include ${CXX_HEADER_TARGET}) - endif() if(NOT LLVM_BUILD_RUNTIMES) set(EXTRA_ARGS EXCLUDE_FROM_ALL) @@ -414,7 +412,7 @@ llvm_ExternalProject_Add(runtimes ${CMAKE_CURRENT_SOURCE_DIR} - DEPENDS ${ARG_DEPENDS} ${CXX_HEADER_TARGET} + DEPENDS ${ARG_DEPENDS} # Builtins were built separately above CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off -DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS} @@ -520,7 +518,7 @@ llvm_ExternalProject_Add(runtimes-${name} ${CMAKE_CURRENT_SOURCE_DIR} - DEPENDS ${${name}_deps} ${CXX_HEADER_TARGET} + DEPENDS ${${name}_deps} # Builtins were built separately above CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off -DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}