xref: /aosp_15_r20/external/libcxx/test/CMakeLists.txt (revision 58b9f456b02922dfdb1fad8a988d5fd8765ecb80)
1*58b9f456SAndroid Build Coastguard Workermacro(pythonize_bool var)
2*58b9f456SAndroid Build Coastguard Worker  if (${var})
3*58b9f456SAndroid Build Coastguard Worker    set(${var} True)
4*58b9f456SAndroid Build Coastguard Worker  else()
5*58b9f456SAndroid Build Coastguard Worker    set(${var} False)
6*58b9f456SAndroid Build Coastguard Worker  endif()
7*58b9f456SAndroid Build Coastguard Workerendmacro()
8*58b9f456SAndroid Build Coastguard Worker
9*58b9f456SAndroid Build Coastguard Workerset(LIBCXX_LIT_VARIANT "libcxx" CACHE STRING
10*58b9f456SAndroid Build Coastguard Worker    "Configuration variant to use for LIT.")
11*58b9f456SAndroid Build Coastguard Worker
12*58b9f456SAndroid Build Coastguard Workerset(LIBCXX_TEST_LINKER_FLAGS "" CACHE STRING
13*58b9f456SAndroid Build Coastguard Worker    "Additonal linker flags to pass when compiling the tests")
14*58b9f456SAndroid Build Coastguard Workerset(LIBCXX_TEST_COMPILER_FLAGS "" CACHE STRING
15*58b9f456SAndroid Build Coastguard Worker    "Additonal linker flags to pass when compiling the tests")
16*58b9f456SAndroid Build Coastguard Worker
17*58b9f456SAndroid Build Coastguard Worker# The tests shouldn't link to any ABI library when it has been linked into
18*58b9f456SAndroid Build Coastguard Worker# libc++ statically or via a linker script.
19*58b9f456SAndroid Build Coastguard Workerif (LIBCXX_ENABLE_STATIC_ABI_LIBRARY OR LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
20*58b9f456SAndroid Build Coastguard Worker  set(LIBCXX_CXX_ABI_LIBNAME "none")
21*58b9f456SAndroid Build Coastguard Workerendif()
22*58b9f456SAndroid Build Coastguard Worker
23*58b9f456SAndroid Build Coastguard Worker# The tests shouldn't link to libunwind if we have a linker script which
24*58b9f456SAndroid Build Coastguard Worker# already does so.
25*58b9f456SAndroid Build Coastguard Workerif (LIBCXX_ENABLE_ABI_LINKER_SCRIPT)
26*58b9f456SAndroid Build Coastguard Worker  set(LIBCXXABI_USE_LLVM_UNWINDER OFF)
27*58b9f456SAndroid Build Coastguard Workerendif()
28*58b9f456SAndroid Build Coastguard Worker
29*58b9f456SAndroid Build Coastguard Workerpythonize_bool(LIBCXX_ENABLE_EXCEPTIONS)
30*58b9f456SAndroid Build Coastguard Workerpythonize_bool(LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY)
31*58b9f456SAndroid Build Coastguard Workerpythonize_bool(LIBCXX_ENABLE_FILESYSTEM)
32*58b9f456SAndroid Build Coastguard Workerpythonize_bool(LIBCXX_ENABLE_RTTI)
33*58b9f456SAndroid Build Coastguard Workerpythonize_bool(LIBCXX_ENABLE_SHARED)
34*58b9f456SAndroid Build Coastguard Workerpythonize_bool(LIBCXX_BUILD_32_BITS)
35*58b9f456SAndroid Build Coastguard Workerpythonize_bool(LIBCXX_GENERATE_COVERAGE)
36*58b9f456SAndroid Build Coastguard Workerpythonize_bool(LIBCXXABI_ENABLE_SHARED)
37*58b9f456SAndroid Build Coastguard Workerpythonize_bool(LIBCXXABI_USE_LLVM_UNWINDER)
38*58b9f456SAndroid Build Coastguard Workerpythonize_bool(LIBCXX_USE_COMPILER_RT)
39*58b9f456SAndroid Build Coastguard Workerpythonize_bool(LIBCXX_HAS_ATOMIC_LIB)
40*58b9f456SAndroid Build Coastguard Workerpythonize_bool(LIBCXX_HAVE_CXX_ATOMICS_WITH_LIB)
41*58b9f456SAndroid Build Coastguard Workerpythonize_bool(LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY)
42*58b9f456SAndroid Build Coastguard Workerpythonize_bool(LIBCXX_DEBUG_BUILD)
43*58b9f456SAndroid Build Coastguard Worker
44*58b9f456SAndroid Build Coastguard Worker# By default, for non-standalone builds, libcxx and libcxxabi share a library
45*58b9f456SAndroid Build Coastguard Worker# directory.
46*58b9f456SAndroid Build Coastguard Workerif (NOT LIBCXX_CXX_ABI_LIBRARY_PATH)
47*58b9f456SAndroid Build Coastguard Worker  set(LIBCXX_CXX_ABI_LIBRARY_PATH "${LIBCXX_LIBRARY_DIR}" CACHE PATH
48*58b9f456SAndroid Build Coastguard Worker      "The path to libc++abi library.")
49*58b9f456SAndroid Build Coastguard Workerendif()
50*58b9f456SAndroid Build Coastguard Worker
51*58b9f456SAndroid Build Coastguard Workerset(LIBCXX_TARGET_INFO "libcxx.test.target_info.LocalTI" CACHE STRING
52*58b9f456SAndroid Build Coastguard Worker    "TargetInfo to use when setting up test environment.")
53*58b9f456SAndroid Build Coastguard Workerset(LIBCXX_EXECUTOR "None" CACHE STRING
54*58b9f456SAndroid Build Coastguard Worker    "Executor to use when running tests.")
55*58b9f456SAndroid Build Coastguard Worker
56*58b9f456SAndroid Build Coastguard Workerset(AUTO_GEN_COMMENT "## Autogenerated by libcxx configuration.\n# Do not edit!")
57*58b9f456SAndroid Build Coastguard Worker
58*58b9f456SAndroid Build Coastguard Workerif (NOT DEFINED LIBCXX_TEST_DEPS)
59*58b9f456SAndroid Build Coastguard Worker  message(FATAL_ERROR "Expected LIBCXX_TEST_DEPS to be defined")
60*58b9f456SAndroid Build Coastguard Workerendif()
61*58b9f456SAndroid Build Coastguard Worker
62*58b9f456SAndroid Build Coastguard Workerif (LIBCXX_INCLUDE_TESTS)
63*58b9f456SAndroid Build Coastguard Worker  include(AddLLVM) # for configure_lit_site_cfg and add_lit_testsuit
64*58b9f456SAndroid Build Coastguard Worker
65*58b9f456SAndroid Build Coastguard Worker  configure_lit_site_cfg(
66*58b9f456SAndroid Build Coastguard Worker    ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
67*58b9f456SAndroid Build Coastguard Worker    ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg)
68*58b9f456SAndroid Build Coastguard Worker
69*58b9f456SAndroid Build Coastguard Worker  add_lit_testsuite(check-cxx
70*58b9f456SAndroid Build Coastguard Worker    "Running libcxx tests"
71*58b9f456SAndroid Build Coastguard Worker    ${CMAKE_CURRENT_BINARY_DIR}
72*58b9f456SAndroid Build Coastguard Worker    DEPENDS cxx ${LIBCXX_TEST_DEPS})
73*58b9f456SAndroid Build Coastguard Worker
74*58b9f456SAndroid Build Coastguard Worker  add_custom_target(check-libcxx DEPENDS check-cxx)
75*58b9f456SAndroid Build Coastguard Workerendif()
76*58b9f456SAndroid Build Coastguard Worker
77*58b9f456SAndroid Build Coastguard Workerif (LIBCXX_GENERATE_COVERAGE)
78*58b9f456SAndroid Build Coastguard Worker  include(CodeCoverage)
79*58b9f456SAndroid Build Coastguard Worker  set(output_dir "${CMAKE_CURRENT_BINARY_DIR}/coverage")
80*58b9f456SAndroid Build Coastguard Worker  set(capture_dirs
81*58b9f456SAndroid Build Coastguard Worker      "${LIBCXX_LIB_CMAKEFILES_DIR}/cxx_objects.dir/"
82*58b9f456SAndroid Build Coastguard Worker      "${LIBCXX_LIB_CMAKEFILES_DIR}/cxx.dir/"
83*58b9f456SAndroid Build Coastguard Worker      "${LIBCXX_LIB_CMAKEFILES_DIR}/cxx_experimental.dir/"
84*58b9f456SAndroid Build Coastguard Worker      "${CMAKE_CURRENT_BINARY_DIR}")
85*58b9f456SAndroid Build Coastguard Worker  set(extract_dirs "${LIBCXX_SOURCE_DIR}/include;${LIBCXX_SOURCE_DIR}/src")
86*58b9f456SAndroid Build Coastguard Worker  setup_lcov_test_target_coverage("cxx" "${output_dir}" "${capture_dirs}" "${extract_dirs}")
87*58b9f456SAndroid Build Coastguard Workerendif()
88*58b9f456SAndroid Build Coastguard Worker
89*58b9f456SAndroid Build Coastguard Worker
90*58b9f456SAndroid Build Coastguard Workerif (LIBCXX_CONFIGURE_IDE)
91*58b9f456SAndroid Build Coastguard Worker  # Create dummy targets for each of the tests in the test suite, this allows
92*58b9f456SAndroid Build Coastguard Worker  # IDE's such as CLion to correctly highlight the tests because it knows
93*58b9f456SAndroid Build Coastguard Worker  # roughly what include paths/compile flags/macro definitions are needed.
94*58b9f456SAndroid Build Coastguard Worker  include_directories(support)
95*58b9f456SAndroid Build Coastguard Worker  file(GLOB_RECURSE LIBCXX_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/*.pass.cpp)
96*58b9f456SAndroid Build Coastguard Worker  file(GLOB LIBCXX_TEST_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/support/*)
97*58b9f456SAndroid Build Coastguard Worker  file(GLOB_RECURSE LIBCXX_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../include/*)
98*58b9f456SAndroid Build Coastguard Worker  add_executable(libcxx_test_objects EXCLUDE_FROM_ALL
99*58b9f456SAndroid Build Coastguard Worker          ${LIBCXX_TESTS} ${LIBCXX_TEST_HEADERS} ${LIBCXX_HEADERS})
100*58b9f456SAndroid Build Coastguard Worker  add_dependencies(libcxx_test_objects cxx)
101*58b9f456SAndroid Build Coastguard Worker
102*58b9f456SAndroid Build Coastguard Worker  set(STATIC_ROOT ${LIBCXX_SOURCE_DIR}/test/std/input.output/filesystems/Inputs/static_test_env)
103*58b9f456SAndroid Build Coastguard Worker  add_definitions(-DLIBCXX_FILESYSTEM_STATIC_TEST_ROOT="${STATIC_ROOT}")
104*58b9f456SAndroid Build Coastguard Worker
105*58b9f456SAndroid Build Coastguard Worker  set(DYNAMIC_ROOT ${LIBCXX_BINARY_DIR}/test/filesystem/Output/dynamic_env)
106*58b9f456SAndroid Build Coastguard Worker  add_definitions(-DLIBCXX_FILESYSTEM_DYNAMIC_TEST_ROOT="${DYNAMIC_ROOT}")
107*58b9f456SAndroid Build Coastguard Worker
108*58b9f456SAndroid Build Coastguard Worker  set(DYNAMIC_HELPER "python ${LIBCXX_SOURCE_DIR}/test/support/filesystem_dynamic_test_helper.py ")
109*58b9f456SAndroid Build Coastguard Worker  add_definitions(-DLIBCXX_FILESYSTEM_DYNAMIC_TEST_HELPER="${DYNAMIC_HELPER}")
110*58b9f456SAndroid Build Coastguard Worker
111*58b9f456SAndroid Build Coastguard Worker  split_list(LIBCXX_COMPILE_FLAGS)
112*58b9f456SAndroid Build Coastguard Worker  split_list(LIBCXX_LINK_FLAGS)
113*58b9f456SAndroid Build Coastguard Worker
114*58b9f456SAndroid Build Coastguard Worker  set_target_properties(libcxx_test_objects
115*58b9f456SAndroid Build Coastguard Worker          PROPERTIES
116*58b9f456SAndroid Build Coastguard Worker            COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}"
117*58b9f456SAndroid Build Coastguard Worker            LINK_FLAGS "${LIBCXX_LINK_FLAGS}"
118*58b9f456SAndroid Build Coastguard Worker            EXCLUDE_FROM_ALL ON
119*58b9f456SAndroid Build Coastguard Worker  )
120*58b9f456SAndroid Build Coastguard Workerendif()
121