1 include(HandleLitArguments)
2 add_subdirectory(tools)
4 # By default, libcxx and libcxxabi share a library directory.
5 if (NOT LIBCXX_CXX_ABI_LIBRARY_PATH)
6 set(LIBCXX_CXX_ABI_LIBRARY_PATH "${LIBCXX_LIBRARY_DIR}" CACHE PATH
7 "The path to libc++abi library.")
10 set(AUTO_GEN_COMMENT "## Autogenerated by libcxx configuration.\n# Do not edit!")
11 set(SERIALIZED_LIT_PARAMS "# Lit parameters serialized here for llvm-lit to pick them up\n")
14 message(DEPRECATION "LIBCXX_EXECUTOR is deprecated, please add executor=... to LIBCXX_TEST_PARAMS")
15 serialize_lit_string_param(SERIALIZED_LIT_PARAMS executor "${LIBCXX_EXECUTOR}")
18 if (NOT LIBCXX_ENABLE_EXCEPTIONS)
19 serialize_lit_param(SERIALIZED_LIT_PARAMS enable_exceptions False)
22 if (NOT LIBCXX_ENABLE_RTTI)
23 serialize_lit_param(SERIALIZED_LIT_PARAMS enable_rtti False)
26 serialize_lit_string_param(SERIALIZED_LIT_PARAMS hardening_mode "${LIBCXX_HARDENING_MODE}")
28 if (CMAKE_CXX_COMPILER_TARGET)
29 serialize_lit_string_param(SERIALIZED_LIT_PARAMS target_triple "${CMAKE_CXX_COMPILER_TARGET}")
31 serialize_lit_string_param(SERIALIZED_LIT_PARAMS target_triple "${LLVM_DEFAULT_TARGET_TRIPLE}")
34 if (LLVM_USE_SANITIZER)
35 serialize_lit_string_param(SERIALIZED_LIT_PARAMS use_sanitizer "${LLVM_USE_SANITIZER}")
38 serialize_lit_params_list(SERIALIZED_LIT_PARAMS LIBCXX_TEST_PARAMS)
40 if (NOT DEFINED LIBCXX_TEST_DEPS)
41 message(FATAL_ERROR "Expected LIBCXX_TEST_DEPS to be defined")
45 # Shared code for initializing some parameters used by all
46 # llvm-libc++-*-clangcl.cfg.in test configs.
49 if (NOT CMAKE_MSVC_RUNTIME_LIBRARY OR CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "DLL$")
50 set(fms_runtime_lib "dll")
51 set(cxx_lib "msvcprt")
53 set(fms_runtime_lib "static")
54 set(cxx_lib "libcpmt")
57 if ((NOT CMAKE_MSVC_RUNTIME_LIBRARY AND uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
58 OR (CMAKE_MSVC_RUNTIME_LIBRARY MATCHES "Debug"))
59 set(dbg_include " -include set_windows_crt_report_mode.h")
60 set(fms_runtime_lib "${fms_runtime_lib}_dbg")
61 set(cxx_lib "${cxx_lib}d")
64 serialize_lit_string_param(SERIALIZED_LIT_PARAMS dbg_include "${dbg_include}")
65 serialize_lit_string_param(SERIALIZED_LIT_PARAMS fms_runtime_lib "${fms_runtime_lib}")
66 serialize_lit_string_param(SERIALIZED_LIT_PARAMS cxx_lib "${cxx_lib}")
69 if (LIBCXX_INCLUDE_TESTS)
70 include(AddLLVM) # for configure_lit_site_cfg and add_lit_testsuite
72 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/configs/cmake-bridge.cfg.in"
73 "${CMAKE_CURRENT_BINARY_DIR}/cmake-bridge.cfg"
76 configure_lit_site_cfg(
77 "${LIBCXX_TEST_CONFIG}"
78 ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
79 MAIN_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py")
81 add_custom_target(cxx-test-depends
82 DEPENDS cxx ${LIBCXX_TEST_DEPS}
83 COMMENT "Builds dependencies required to run the test suite.")
85 add_lit_testsuite(check-cxx
86 "Running libcxx tests"
87 ${CMAKE_CURRENT_BINARY_DIR}
88 DEPENDS cxx-test-depends)
90 if(LIBCXX_ENABLE_STD_MODULES)
91 # Generates the modules used in the test.
92 # Note the test will regenerate this with the proper setting
93 # - the right DCMAKE_CXX_STANDARD
94 # - the right test compilation flags
95 # Since modules depend on these flags there currently is no way to
96 # avoid generating these for the tests. The advantage of the
97 # pre generation is that less build information needs to be shared
100 OUTPUT "${CMAKE_BINARY_DIR}/test/__config_module__/CMakeCache.txt"
103 "-G${CMAKE_GENERATOR}"
104 "-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}"
105 "-B${CMAKE_BINARY_DIR}/test/__config_module__"
106 "-H${LIBCXX_GENERATED_MODULE_DIR}"
107 "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
108 "-DCMAKE_CXX_STANDARD=23"
109 "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
111 add_custom_target(generate-test-module-std
112 DEPENDS "${CMAKE_BINARY_DIR}/test/__config_module__/CMakeCache.txt"
113 COMMENT "Builds generic module std.")
117 if (LIBCXX_GENERATE_COVERAGE)
118 include(CodeCoverage)
119 set(output_dir "${CMAKE_CURRENT_BINARY_DIR}/coverage")
121 "${LIBCXX_LIB_CMAKEFILES_DIR}/cxx_objects.dir/"
122 "${LIBCXX_LIB_CMAKEFILES_DIR}/cxx.dir/"
123 "${LIBCXX_LIB_CMAKEFILES_DIR}/cxx_experimental.dir/"
124 "${CMAKE_CURRENT_BINARY_DIR}")
125 set(extract_dirs "${LIBCXX_SOURCE_DIR}/include;${LIBCXX_SOURCE_DIR}/src")
126 setup_lcov_test_target_coverage("cxx" "${output_dir}" "${capture_dirs}" "${extract_dirs}")
129 if (LIBCXX_CONFIGURE_IDE)
130 # Create dummy targets for each of the tests in the test suite, this allows
131 # IDE's such as CLion to correctly highlight the tests because it knows
132 # roughly what include paths/compile flags/macro definitions are needed.
133 include_directories(support)
134 file(GLOB_RECURSE LIBCXX_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/*.pass.cpp)
135 file(GLOB LIBCXX_TEST_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/support/*)
136 file(GLOB_RECURSE LIBCXX_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../include/*)
137 add_executable(libcxx_test_objects EXCLUDE_FROM_ALL
138 ${LIBCXX_TESTS} ${LIBCXX_TEST_HEADERS} ${LIBCXX_HEADERS})
139 add_dependencies(libcxx_test_objects cxx)
141 split_list(LIBCXX_COMPILE_FLAGS)
142 split_list(LIBCXX_LINK_FLAGS)
144 set_target_properties(libcxx_test_objects
146 COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}"
147 LINK_FLAGS "${LIBCXX_LINK_FLAGS}"