Skip to content

Commit 1687f2b

Browse files
committed
[libcxxabi] Use cxx-headers target to consume libcxx headers
Rather than including libc++ include dir, use the cxx-headers target. Differential Revision: https://reviews.llvm.org/D98367
1 parent 86a2fa4 commit 1687f2b

File tree

4 files changed

+28
-9
lines changed

4 files changed

+28
-9
lines changed

libcxxabi/CMakeLists.txt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,23 @@ if (NOT LIBCXXABI_ENABLE_SHARED AND NOT LIBCXXABI_ENABLE_STATIC)
156156
message(FATAL_ERROR "libc++abi must be built as either a shared or static library.")
157157
endif()
158158

159-
set(LIBCXXABI_LIBCXX_INCLUDES "${LIBCXXABI_LIBCXX_PATH}/include" CACHE PATH
159+
# TODO: This is a workaround for the fact that Standalone builds can't use
160+
# targets from the other runtimes (so the cxx-headers target doesn't exist).
161+
set(LIBCXXABI_LIBCXX_INCLUDES "" CACHE PATH
160162
"Specify path to libc++ includes.")
161-
message(STATUS "Libc++abi will be using libc++ includes from ${LIBCXXABI_LIBCXX_INCLUDES}")
163+
if (LIBCXXABI_STANDALONE_BUILD)
164+
if (NOT IS_DIRECTORY ${LIBCXXABI_LIBCXX_INCLUDES})
165+
message(FATAL_ERROR
166+
"LIBCXXABI_LIBCXX_INCLUDES=${LIBCXXABI_LIBCXX_INCLUDES} is not a valid directory. "
167+
"Please provide the path to where the libc++ headers have been installed.")
168+
endif()
169+
add_library(cxx-headers INTERFACE)
170+
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" OR "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC")
171+
target_compile_options(cxx-headers INTERFACE /I "${LIBCXXABI_LIBCXX_INCLUDES}")
172+
else()
173+
target_compile_options(cxx-headers INTERFACE -I "${LIBCXXABI_LIBCXX_INCLUDES}")
174+
endif()
175+
endif()
162176

163177
option(LIBCXXABI_HERMETIC_STATIC_LIBRARY
164178
"Do not export any symbols from the static library." OFF)
@@ -180,16 +194,19 @@ set(CMAKE_MODULE_PATH
180194
)
181195

182196
if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
197+
set(LIBCXXABI_HEADER_DIR ${LLVM_BINARY_DIR})
183198
set(LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++)
184199
set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++)
185200
if(LIBCXX_LIBDIR_SUBDIR)
186201
string(APPEND LIBCXXABI_LIBRARY_DIR /${LIBCXXABI_LIBDIR_SUBDIR})
187202
string(APPEND LIBCXXABI_INSTALL_LIBRARY_DIR /${LIBCXXABI_LIBDIR_SUBDIR})
188203
endif()
189204
elseif(LLVM_LIBRARY_OUTPUT_INTDIR)
205+
set(LIBCXXABI_HEADER_DIR ${LLVM_BINARY_DIR})
190206
set(LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
191207
set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LIBCXXABI_LIBDIR_SUFFIX})
192208
else()
209+
set(LIBCXXABI_HEADER_DIR ${CMAKE_BINARY_DIR})
193210
set(LIBCXXABI_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXXABI_LIBDIR_SUFFIX})
194211
set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LIBCXXABI_LIBDIR_SUFFIX})
195212
endif()

libcxxabi/src/CMakeLists.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ if (MSVC_IDE OR XCODE)
5656
endif()
5757
endif()
5858

59-
include_directories("${LIBCXXABI_LIBCXX_INCLUDES}")
60-
6159
# stdlib_stdexcept.cpp depends on libc++ internals.
6260
include_directories("${LIBCXXABI_LIBCXX_PATH}")
6361

@@ -178,7 +176,7 @@ endif()
178176
# Build the shared library.
179177
if (LIBCXXABI_ENABLE_SHARED)
180178
add_library(cxxabi_shared SHARED ${LIBCXXABI_SOURCES} ${LIBCXXABI_HEADERS})
181-
target_link_libraries(cxxabi_shared PRIVATE ${LIBCXXABI_SHARED_LIBRARIES} ${LIBCXXABI_LIBRARIES})
179+
target_link_libraries(cxxabi_shared PRIVATE cxx-headers ${LIBCXXABI_SHARED_LIBRARIES} ${LIBCXXABI_LIBRARIES})
182180
if (TARGET pstl::ParallelSTL)
183181
target_link_libraries(cxxabi_shared PUBLIC pstl::ParallelSTL)
184182
endif()
@@ -245,7 +243,7 @@ endif()
245243
# Build the static library.
246244
if (LIBCXXABI_ENABLE_STATIC)
247245
add_library(cxxabi_static STATIC ${LIBCXXABI_SOURCES} ${LIBCXXABI_HEADERS})
248-
target_link_libraries(cxxabi_static PRIVATE ${LIBCXXABI_STATIC_LIBRARIES} ${LIBCXXABI_LIBRARIES})
246+
target_link_libraries(cxxabi_static PRIVATE cxx-headers ${LIBCXXABI_STATIC_LIBRARIES} ${LIBCXXABI_LIBRARIES})
249247
if (TARGET pstl::ParallelSTL)
250248
target_link_libraries(cxxabi_static PUBLIC pstl::ParallelSTL)
251249
endif()

libcxxabi/test/libcxxabi/test/config.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@ class Configuration(LibcxxConfiguration):
1616
# pylint: disable=redefined-outer-name
1717
def __init__(self, lit_config, config):
1818
super(Configuration, self).__init__(lit_config, config)
19+
self.libcxxabi_hdr_root = None
1920
self.libcxxabi_src_root = None
2021
self.libcxxabi_obj_root = None
2122
self.abi_library_root = None
2223
self.libcxx_src_root = None
2324

2425
def configure_src_root(self):
26+
self.libcxxabi_hdr_root = self.get_lit_conf(
27+
'libcxxabi_hdr_root',
28+
self.project_obj_root)
2529
self.libcxxabi_src_root = self.get_lit_conf(
2630
'libcxxabi_src_root',
2731
os.path.dirname(self.config.test_source_root))
@@ -57,9 +61,8 @@ def configure_compile_flags(self):
5761

5862
def configure_compile_flags_header_includes(self):
5963
self.configure_config_site_header()
60-
cxx_headers = self.get_lit_conf(
61-
'cxx_headers',
62-
os.path.join(self.libcxx_src_root, '/include'))
64+
cxx_headers = self.get_lit_conf('cxx_headers', None) or \
65+
os.path.join(self.libcxxabi_hdr_root, 'include', 'c++', 'v1')
6366
if cxx_headers == '':
6467
self.lit_config.note('using the systems c++ headers')
6568
else:

libcxxabi/test/lit.site.cfg.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import site
55

66
config.cxx_under_test = "@CMAKE_CXX_COMPILER@"
77
config.project_obj_root = "@CMAKE_BINARY_DIR@"
8+
config.libcxxabi_hdr_root = "@LIBCXXABI_HEADER_DIR@"
89
config.libcxxabi_src_root = "@LIBCXXABI_SOURCE_DIR@"
910
config.libcxxabi_obj_root = "@LIBCXXABI_BINARY_DIR@"
1011
config.abi_library_root = "@LIBCXXABI_LIBRARY_DIR@"

0 commit comments

Comments
 (0)