1 add_subdirectory(tools)
3 # By default, libcxx and libcxxabi share a library directory.
4 if (NOT LIBCXX_CXX_ABI_LIBRARY_PATH)
5 set(LIBCXX_CXX_ABI_LIBRARY_PATH "${LIBCXX_LIBRARY_DIR}" CACHE PATH
6 "The path to libc++abi library.")
9 set(LIBCXX_EXECUTOR "\\\"${Python3_EXECUTABLE}\\\" ${CMAKE_CURRENT_LIST_DIR}/../utils/run.py" CACHE STRING
10 "Executor to use when running tests.")
12 set(AUTO_GEN_COMMENT "## Autogenerated by libcxx configuration.\n# Do not edit!")
13 set(SERIALIZED_LIT_PARAMS "# Lit parameters serialized here for llvm-lit to pick them up\n")
15 macro(serialize_lit_param param value)
16 string(APPEND SERIALIZED_LIT_PARAMS "config.${param} = ${value}\n")
19 if (NOT LIBCXX_ENABLE_EXCEPTIONS)
20 serialize_lit_param(enable_exceptions False)
23 if (NOT LIBCXX_ENABLE_RTTI)
24 serialize_lit_param(enable_rtti False)
27 serialize_lit_param(hardening_mode "\"${LIBCXX_HARDENING_MODE}\"")
29 if (CMAKE_CXX_COMPILER_TARGET)
30 serialize_lit_param(target_triple "\"${CMAKE_CXX_COMPILER_TARGET}\"")
32 serialize_lit_param(target_triple "\"${LLVM_DEFAULT_TARGET_TRIPLE}\"")
35 if (LLVM_USE_SANITIZER)
36 serialize_lit_param(use_sanitizer "\"${LLVM_USE_SANITIZER}\"")
39 foreach(param IN LISTS LIBCXX_TEST_PARAMS)
40 string(REGEX REPLACE "(.+)=(.+)" "\\1" name "${param}")
41 string(REGEX REPLACE "(.+)=(.+)" "\\2" value "${param}")
42 serialize_lit_param("${name}" "\"${value}\"")
45 if (NOT DEFINED LIBCXX_TEST_DEPS)
46 message(FATAL_ERROR "Expected LIBCXX_TEST_DEPS to be defined")
50 # Shared code for initializing some parameters used by all
51 # llvm-libc++-*-clangcl.cfg.in test configs.
54 if (NOT CMAKE_MSVC_RUNTIME_LIBRARY OR CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "DLL$")
56 set(cxx_lib "msvcprt")
59 set(cxx_lib "libcpmt")
62 if ((NOT CMAKE_MSVC_RUNTIME_LIBRARY AND uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
63 OR (CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "Debug"))
64 set(dbg_include " -D_DEBUG -include set_windows_crt_report_mode.h")
65 set(crt_lib "${crt_lib}d")
66 set(cxx_lib "${cxx_lib}d")
69 serialize_lit_param(dbg_include "\"${dbg_include}\"")
70 serialize_lit_param(crt_lib "\"${crt_lib}\"")
71 serialize_lit_param(cxx_lib "\"${cxx_lib}\"")
74 if (LIBCXX_INCLUDE_TESTS)
75 include(AddLLVM) # for configure_lit_site_cfg and add_lit_testsuite
77 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/configs/cmake-bridge.cfg.in"
78 "${CMAKE_CURRENT_BINARY_DIR}/cmake-bridge.cfg"
81 configure_lit_site_cfg(
82 "${LIBCXX_TEST_CONFIG}"
83 ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
84 MAIN_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py")
86 add_custom_target(cxx-test-depends
87 DEPENDS cxx ${LIBCXX_TEST_DEPS}
88 COMMENT "Builds dependencies required to run the test suite.")
90 add_lit_testsuite(check-cxx
91 "Running libcxx tests"
92 ${CMAKE_CURRENT_BINARY_DIR}
93 DEPENDS cxx-test-depends)
95 if(LIBCXX_ENABLE_STD_MODULES)
96 # Generates the modules used in the test.
97 # Note the test will regenerate this with the proper setting
98 # - the right DCMAKE_CXX_STANDARD
99 # - the right test compilation flags
100 # Since modules depend on these flags there currently is no way to
101 # avoid generating these for the tests. The advantage of the
102 # pre generation is that less build information needs to be shared
105 OUTPUT "${CMAKE_BINARY_DIR}/test/__config_module__/CMakeCache.txt"
108 "-G${CMAKE_GENERATOR}"
109 "-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}"
110 "-B${CMAKE_BINARY_DIR}/test/__config_module__"
111 "-H${LIBCXX_GENERATED_MODULE_DIR}"
112 "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
113 "-DCMAKE_CXX_STANDARD=23"
114 "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
116 add_custom_target(generate-test-module-std
117 DEPENDS "${CMAKE_BINARY_DIR}/test/__config_module__/CMakeCache.txt"
118 COMMENT "Builds generic module std.")
122 if (LIBCXX_GENERATE_COVERAGE)
123 include(CodeCoverage)
124 set(output_dir "${CMAKE_CURRENT_BINARY_DIR}/coverage")
126 "${LIBCXX_LIB_CMAKEFILES_DIR}/cxx_objects.dir/"
127 "${LIBCXX_LIB_CMAKEFILES_DIR}/cxx.dir/"
128 "${LIBCXX_LIB_CMAKEFILES_DIR}/cxx_experimental.dir/"
129 "${CMAKE_CURRENT_BINARY_DIR}")
130 set(extract_dirs "${LIBCXX_SOURCE_DIR}/include;${LIBCXX_SOURCE_DIR}/src")
131 setup_lcov_test_target_coverage("cxx" "${output_dir}" "${capture_dirs}" "${extract_dirs}")
134 if (LIBCXX_CONFIGURE_IDE)
135 # Create dummy targets for each of the tests in the test suite, this allows
136 # IDE's such as CLion to correctly highlight the tests because it knows
137 # roughly what include paths/compile flags/macro definitions are needed.
138 include_directories(support)
139 file(GLOB_RECURSE LIBCXX_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/*.pass.cpp)
140 file(GLOB LIBCXX_TEST_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/support/*)
141 file(GLOB_RECURSE LIBCXX_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../include/*)
142 add_executable(libcxx_test_objects EXCLUDE_FROM_ALL
143 ${LIBCXX_TESTS} ${LIBCXX_TEST_HEADERS} ${LIBCXX_HEADERS})
144 add_dependencies(libcxx_test_objects cxx)
146 split_list(LIBCXX_COMPILE_FLAGS)
147 split_list(LIBCXX_LINK_FLAGS)
149 set_target_properties(libcxx_test_objects
151 COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}"
152 LINK_FLAGS "${LIBCXX_LINK_FLAGS}"