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 if (LIBCXX_ENABLE_ASSERTIONS)
28 serialize_lit_param(enable_assertions True)
31 if (CMAKE_CXX_COMPILER_TARGET)
32 serialize_lit_param(target_triple "\"${CMAKE_CXX_COMPILER_TARGET}\"")
34 serialize_lit_param(target_triple "\"${LLVM_DEFAULT_TARGET_TRIPLE}\"")
37 if (LLVM_USE_SANITIZER)
38 serialize_lit_param(use_sanitizer "\"${LLVM_USE_SANITIZER}\"")
41 foreach(param IN LISTS LIBCXX_TEST_PARAMS)
42 string(REGEX REPLACE "(.+)=(.+)" "\\1" name "${param}")
43 string(REGEX REPLACE "(.+)=(.+)" "\\2" value "${param}")
44 serialize_lit_param("${name}" "\"${value}\"")
47 if (NOT DEFINED LIBCXX_TEST_DEPS)
48 message(FATAL_ERROR "Expected LIBCXX_TEST_DEPS to be defined")
51 if (LIBCXX_INCLUDE_TESTS)
52 include(AddLLVM) # for configure_lit_site_cfg and add_lit_testsuite
54 configure_file("${CMAKE_CURRENT_SOURCE_DIR}/configs/cmake-bridge.cfg.in"
55 "${CMAKE_CURRENT_BINARY_DIR}/cmake-bridge.cfg"
58 configure_lit_site_cfg(
59 "${LIBCXX_TEST_CONFIG}"
60 ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
61 MAIN_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py")
63 add_custom_target(cxx-test-depends
64 DEPENDS cxx ${LIBCXX_TEST_DEPS}
65 COMMENT "Builds dependencies required to run the test suite.")
67 add_lit_testsuite(check-cxx
68 "Running libcxx tests"
69 ${CMAKE_CURRENT_BINARY_DIR}
70 DEPENDS cxx-test-depends)
72 if(LIBCXX_ENABLE_STD_MODULES)
73 # Generates the modules used in the test.
74 # Note the test will regenerate this with the proper setting
75 # - the right DCMAKE_CXX_STANDARD
76 # - the right test compilation flags
77 # Since modules depend on these flags there currently is no way to
78 # avoid generating these for the tests. The advantage of the
79 # pre generation is that less build information needs to be shared
82 OUTPUT "${CMAKE_BINARY_DIR}/test/__config_module__/CMakeCache.txt"
85 "-G${CMAKE_GENERATOR}"
86 "-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}"
87 "-B${CMAKE_BINARY_DIR}/test/__config_module__"
88 "-H${LIBCXX_GENERATED_MODULE_DIR}"
89 "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
90 "-DCMAKE_CXX_STANDARD=23"
91 "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
93 add_custom_target(generate-test-module-std
94 DEPENDS "${CMAKE_BINARY_DIR}/test/__config_module__/CMakeCache.txt"
95 COMMENT "Builds generic module std.")
99 if (LIBCXX_GENERATE_COVERAGE)
100 include(CodeCoverage)
101 set(output_dir "${CMAKE_CURRENT_BINARY_DIR}/coverage")
103 "${LIBCXX_LIB_CMAKEFILES_DIR}/cxx_objects.dir/"
104 "${LIBCXX_LIB_CMAKEFILES_DIR}/cxx.dir/"
105 "${LIBCXX_LIB_CMAKEFILES_DIR}/cxx_experimental.dir/"
106 "${CMAKE_CURRENT_BINARY_DIR}")
107 set(extract_dirs "${LIBCXX_SOURCE_DIR}/include;${LIBCXX_SOURCE_DIR}/src")
108 setup_lcov_test_target_coverage("cxx" "${output_dir}" "${capture_dirs}" "${extract_dirs}")
111 if (LIBCXX_CONFIGURE_IDE)
112 # Create dummy targets for each of the tests in the test suite, this allows
113 # IDE's such as CLion to correctly highlight the tests because it knows
114 # roughly what include paths/compile flags/macro definitions are needed.
115 include_directories(support)
116 file(GLOB_RECURSE LIBCXX_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/*.pass.cpp)
117 file(GLOB LIBCXX_TEST_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/support/*)
118 file(GLOB_RECURSE LIBCXX_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../include/*)
119 add_executable(libcxx_test_objects EXCLUDE_FROM_ALL
120 ${LIBCXX_TESTS} ${LIBCXX_TEST_HEADERS} ${LIBCXX_HEADERS})
121 add_dependencies(libcxx_test_objects cxx)
123 split_list(LIBCXX_COMPILE_FLAGS)
124 split_list(LIBCXX_LINK_FLAGS)
126 set_target_properties(libcxx_test_objects
128 COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}"
129 LINK_FLAGS "${LIBCXX_LINK_FLAGS}"