[libc++] Add a per-target flag to include the generated config_site
This allows propagating the include automatically to targets that
depend on one of the libc++ targets such as the benchmarks. Note
that the GoogleBenchmark build itself still needs to manually specify
the -include, since I don't know of any way to have an external project
link against one of the libc++ targets (which would propagate the -include
automatically).
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@373631 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5426563..1f7dd57 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -809,21 +809,21 @@
configure_file("include/__config_site.in"
"${site_config_path}"
@ONLY)
-
- # Provide the config definitions by included the generated __config_site
- # file at compile time.
- if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" OR "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC")
- add_compile_flags("/FI\"${LIBCXX_BINARY_DIR}/__config_site\"")
- else()
- add_compile_flags("-include ${LIBCXX_BINARY_DIR}/__config_site")
- endif()
-else()
- if (EXISTS "${site_config_path}")
- message(STATUS "Removing stale site configuration ${site_config_path}")
- file(REMOVE "${site_config_path}")
- endif()
+elseif(EXISTS "${site_config_path}")
+ message(STATUS "Removing stale site configuration ${site_config_path}")
+ file(REMOVE "${site_config_path}")
endif()
+function(cxx_add_config_site target)
+ if (LIBCXX_NEEDS_SITE_CONFIG)
+ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" OR "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC")
+ target_compile_options(${target} PUBLIC "/FI\"${site_config_path}\"")
+ else()
+ target_compile_options(${target} PUBLIC "-include${site_config_path}")
+ endif()
+ endif()
+endfunction()
+
#===============================================================================
# Setup Source Code And Tests
#===============================================================================
diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt
index d80cb1a..56fadff 100644
--- a/benchmarks/CMakeLists.txt
+++ b/benchmarks/CMakeLists.txt
@@ -95,10 +95,6 @@
${SANITIZER_FLAGS}
-Wno-user-defined-literals
)
-if (LIBCXX_NEEDS_SITE_CONFIG)
- list(APPEND BENCHMARK_TEST_LIBCXX_COMPILE_FLAGS
- -include "${LIBCXX_BINARY_DIR}/__config_site")
-endif()
set(BENCHMARK_TEST_LIBCXX_LINK_FLAGS
-nodefaultlibs
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index c9c3f18..93d48f1 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -234,6 +234,7 @@
cxx_set_common_defines(cxx_shared)
cxx_add_warning_flags(cxx_shared)
cxx_add_windows_flags(cxx_shared)
+ cxx_add_config_site(cxx_shared)
# Link against LLVM libunwind
if (LIBCXXABI_USE_LLVM_UNWINDER)
@@ -337,6 +338,7 @@
cxx_set_common_defines(cxx_static)
cxx_add_warning_flags(cxx_static)
cxx_add_windows_flags(cxx_static)
+ cxx_add_config_site(cxx_static)
if (LIBCXX_HERMETIC_STATIC_LIBRARY)
# If the hermetic library doesn't define the operator new/delete functions