Skip to content

Commit 8d26760

Browse files
committed
[CMake] Use -isystem flag to access libc++ headers
This is a partial revert of D62155. Rather than copying libc++ headers into the build directory to be later overwritten by the final headers, use -isystem flag to access libc++ headers during CMake checks. This should address the occasional flake we've seen, especially on Windows builders where CMake fails to overwrite __config with the final version. Differential Revision: https://reviews.llvm.org/D88454
1 parent 149f5b5 commit 8d26760

File tree

2 files changed

+26
-36
lines changed

2 files changed

+26
-36
lines changed

libcxx/include/CMakeLists.txt

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,6 @@ add_custom_command(OUTPUT ${LIBCXX_BINARY_DIR}/__generated_config
202202
add_custom_target(cxx-generated-config ALL
203203
DEPENDS ${LIBCXX_BINARY_DIR}/__generated_config)
204204

205-
# In some build configurations (like bootstrapping clang), we need to be able to
206-
# install the libcxx headers before the CMake configuration for libcxx runs. Making
207-
# the name of this target configurable allows LLVM/runtimes/CMakeLists.txt to
208-
# add this subdirectory to the LLVM build to put libcxx's headers in place
209-
# before libcxx's build configuration is run.
210-
if (NOT CXX_HEADER_TARGET)
211-
set(CXX_HEADER_TARGET cxx-headers)
212-
endif()
213205
if(LIBCXX_HEADER_DIR)
214206
set(output_dir ${LIBCXX_HEADER_DIR}/include/c++/v1)
215207

@@ -234,31 +226,31 @@ if(LIBCXX_HEADER_DIR)
234226
list(APPEND out_files ${dst})
235227
add_custom_target(generate-cxx-headers DEPENDS ${out_files})
236228

237-
add_library(${CXX_HEADER_TARGET} INTERFACE)
238-
add_dependencies(${CXX_HEADER_TARGET} generate-cxx-headers ${LIBCXX_CXX_ABI_HEADER_TARGET})
229+
add_library(cxx-headers INTERFACE)
230+
add_dependencies(cxx-headers generate-cxx-headers ${LIBCXX_CXX_ABI_HEADER_TARGET})
239231
# TODO: Use target_include_directories once we figure out why that breaks the runtimes build
240232
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" OR "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC")
241-
target_compile_options(${CXX_HEADER_TARGET} INTERFACE /I "${output_dir}")
233+
target_compile_options(cxx-headers INTERFACE /I "${output_dir}")
242234
else()
243-
target_compile_options(${CXX_HEADER_TARGET} INTERFACE -I "${output_dir}")
235+
target_compile_options(cxx-headers INTERFACE -I "${output_dir}")
244236
endif()
245237

246238
# Make sure the generated __config_site header is included when we build the library.
247239
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" OR "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC")
248-
target_compile_options(${CXX_HEADER_TARGET} INTERFACE /FI "${LIBCXX_BINARY_DIR}/__config_site")
240+
target_compile_options(cxx-headers INTERFACE /FI "${LIBCXX_BINARY_DIR}/__config_site")
249241
else()
250-
target_compile_options(${CXX_HEADER_TARGET} INTERFACE -include "${LIBCXX_BINARY_DIR}/__config_site")
242+
target_compile_options(cxx-headers INTERFACE -include "${LIBCXX_BINARY_DIR}/__config_site")
251243
endif()
252244
else()
253-
add_library(${CXX_HEADER_TARGET} INTERFACE)
245+
add_library(cxx-headers INTERFACE)
254246
endif()
255247

256248
if (LIBCXX_INSTALL_HEADERS)
257249
foreach(file ${files})
258250
get_filename_component(dir ${file} DIRECTORY)
259251
install(FILES ${file}
260252
DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}include/c++/v1/${dir}
261-
COMPONENT ${CXX_HEADER_TARGET}
253+
COMPONENT cxx-headers
262254
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
263255
)
264256
endforeach()
@@ -268,15 +260,15 @@ if (LIBCXX_INSTALL_HEADERS)
268260
DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}include/c++/v1
269261
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
270262
RENAME __config
271-
COMPONENT ${CXX_HEADER_TARGET})
263+
COMPONENT cxx-headers)
272264

273265
if (NOT CMAKE_CONFIGURATION_TYPES)
274-
add_custom_target(install-${CXX_HEADER_TARGET}
275-
DEPENDS ${CXX_HEADER_TARGET} cxx-generated-config
266+
add_custom_target(install-cxx-headers
267+
DEPENDS cxx-headers cxx-generated-config
276268
COMMAND "${CMAKE_COMMAND}"
277-
-DCMAKE_INSTALL_COMPONENT=${CXX_HEADER_TARGET}
269+
-DCMAKE_INSTALL_COMPONENT=cxx-headers
278270
-P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
279271
# Stripping is a no-op for headers
280-
add_custom_target(install-${CXX_HEADER_TARGET}-stripped DEPENDS install-${CXX_HEADER_TARGET})
272+
add_custom_target(install-cxx-headers-stripped DEPENDS install-cxx-headers)
281273
endif()
282274
endif()

llvm/runtimes/CMakeLists.txt

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,17 @@ if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
9898

9999
include(CheckLibraryExists)
100100
include(CheckCCompilerFlag)
101+
include(CMakePushCheckState)
101102

102-
# We don't have libc++ (yet).
103-
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdlib++")
103+
cmake_push_check_state()
104+
105+
# We don't have libc++ (yet)...
106+
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdinc++ -nostdlib++")
107+
108+
# ...but we need access to libc++ headers for CMake checks to succeed.
109+
if (LLVM_EXTERNAL_LIBCXX_SOURCE_DIR AND "libcxx" IN_LIST LLVM_ENABLE_RUNTIMES)
110+
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -isystem ${LLVM_EXTERNAL_LIBCXX_SOURCE_DIR}/include")
111+
endif()
104112

105113
# Avoid checking whether the compiler is working.
106114
set(LLVM_COMPILER_CHECKED ON)
@@ -110,8 +118,7 @@ if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
110118
include(HandleLLVMOptions)
111119
include(FindPythonInterp)
112120

113-
# Remove the -nostdlib++ option we've added earlier.
114-
string(REPLACE "-nostdlib++" "" CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
121+
cmake_pop_check_state()
115122

116123
# Use libtool instead of ar if you are both on an Apple host, and targeting Apple.
117124
if(CMAKE_HOST_APPLE AND APPLE)
@@ -215,15 +222,6 @@ if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
215222

216223
else() # if this is included from LLVM's CMake
217224
include(LLVMExternalProjectUtils)
218-
if (LLVM_EXTERNAL_LIBCXX_SOURCE_DIR AND "libcxx" IN_LIST LLVM_ENABLE_RUNTIMES)
219-
# This looks wrong, but libcxx's build actually wants the header dir to be
220-
# the root build dir, not the include directory.
221-
set(LIBCXX_BINARY_DIR ${LLVM_BINARY_DIR})
222-
set(LIBCXX_SOURCE_DIR ${LLVM_EXTERNAL_LIBCXX_SOURCE_DIR})
223-
set(LIBCXX_HEADER_DIR ${LLVM_BINARY_DIR})
224-
set(CXX_HEADER_TARGET runtime-libcxx-headers)
225-
add_subdirectory(${LLVM_EXTERNAL_LIBCXX_SOURCE_DIR}/include ${CXX_HEADER_TARGET})
226-
endif()
227225

228226
if(NOT LLVM_BUILD_RUNTIMES)
229227
set(EXTRA_ARGS EXCLUDE_FROM_ALL)
@@ -414,7 +412,7 @@ ${error} Set RUNTIMES_BUILD_ALLOW_DARWIN to allow a single darwin triple.")
414412

415413
llvm_ExternalProject_Add(runtimes
416414
${CMAKE_CURRENT_SOURCE_DIR}
417-
DEPENDS ${ARG_DEPENDS} ${CXX_HEADER_TARGET}
415+
DEPENDS ${ARG_DEPENDS}
418416
# Builtins were built separately above
419417
CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off
420418
-DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
@@ -520,7 +518,7 @@ ${error} Set RUNTIMES_BUILD_ALLOW_DARWIN to allow a single darwin triple.")
520518

521519
llvm_ExternalProject_Add(runtimes-${name}
522520
${CMAKE_CURRENT_SOURCE_DIR}
523-
DEPENDS ${${name}_deps} ${CXX_HEADER_TARGET}
521+
DEPENDS ${${name}_deps}
524522
# Builtins were built separately above
525523
CMAKE_ARGS -DCOMPILER_RT_BUILD_BUILTINS=Off
526524
-DLLVM_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}

0 commit comments

Comments
 (0)