16021
|
1 |
# This option is currently used to prevent recursion
|
|
2 |
option(CORROSION_TESTS "Enable Corrosion tests" ON)
|
|
3 |
mark_as_advanced(CORROSION_TESTS)
|
|
4 |
if(NOT CORROSION_TESTS)
|
|
5 |
return()
|
|
6 |
endif()
|
|
7 |
|
|
8 |
option(CORROSION_TESTS_CXXBRIDGE
|
|
9 |
"Build cxxbridge tests which requires cxxbridge executable being available"
|
|
10 |
OFF)
|
|
11 |
option(CORROSION_TESTS_KEEP_BUILDDIRS
|
|
12 |
"By default corrosion tests will cleanup after themselves. This option limits the cleaning up to the
|
|
13 |
target directories and will keep the build directories, which may be useful for caching."
|
|
14 |
OFF)
|
|
15 |
mark_as_advanced(CORROSION_TESTS_NO_CLEANUP)
|
|
16 |
|
|
17 |
set(test_install_path "${CMAKE_CURRENT_BINARY_DIR}/test-install-corrosion")
|
|
18 |
|
|
19 |
set(test_header_contents
|
|
20 |
"option(CORROSION_TESTS_FIND_CORROSION \"Use Corrosion as a subdirectory\" OFF)"
|
|
21 |
"if (CORROSION_TESTS_FIND_CORROSION)"
|
|
22 |
" set(CMAKE_PREFIX_PATH \"${test_install_path}\" CACHE INTERNAL \"\" FORCE)"
|
|
23 |
" find_package(Corrosion REQUIRED PATHS \"${test_install_path}\" NO_CMAKE_SYSTEM_PATH)"
|
|
24 |
"else()"
|
|
25 |
" add_subdirectory(\"${CMAKE_CURRENT_SOURCE_DIR}/..\" corrosion)"
|
|
26 |
"endif()"
|
|
27 |
)
|
|
28 |
|
|
29 |
string(REPLACE ";" "\n" test_header_contents "${test_header_contents}")
|
|
30 |
|
|
31 |
file(WRITE test_header.cmake "${test_header_contents}")
|
|
32 |
|
|
33 |
option(CORROSION_TESTS_INSTALL_CORROSION
|
|
34 |
"Install Corrosion to a test directory and let tests use the installed Corrosion"
|
|
35 |
OFF)
|
|
36 |
if(CORROSION_TESTS_INSTALL_CORROSION)
|
|
37 |
add_test(NAME "install_corrosion_configure"
|
|
38 |
COMMAND
|
|
39 |
${CMAKE_COMMAND}
|
|
40 |
-S "${CMAKE_CURRENT_SOURCE_DIR}/.."
|
|
41 |
-B "${CMAKE_CURRENT_BINARY_DIR}/build-corrosion"
|
|
42 |
-DCORROSION_VERBOSE_OUTPUT=ON
|
|
43 |
-DCORROSION_TESTS=OFF
|
|
44 |
-DCMAKE_BUILD_TYPE=Release
|
|
45 |
-G${CMAKE_GENERATOR}
|
|
46 |
"-DCMAKE_INSTALL_PREFIX=${test_install_path}"
|
|
47 |
)
|
|
48 |
add_test(NAME "install_corrosion_build"
|
|
49 |
COMMAND
|
|
50 |
${CMAKE_COMMAND} --build "${CMAKE_CURRENT_BINARY_DIR}/build-corrosion" --config Release
|
|
51 |
)
|
|
52 |
add_test(NAME "install_corrosion_install"
|
|
53 |
COMMAND
|
|
54 |
${CMAKE_COMMAND} --install "${CMAKE_CURRENT_BINARY_DIR}/build-corrosion" --config Release
|
|
55 |
)
|
|
56 |
set_tests_properties("install_corrosion_configure" PROPERTIES FIXTURES_SETUP "fixture_corrosion_configure")
|
|
57 |
set_tests_properties("install_corrosion_build" PROPERTIES FIXTURES_SETUP "fixture_corrosion_build")
|
|
58 |
set_tests_properties("install_corrosion_build" PROPERTIES FIXTURES_REQUIRED "fixture_corrosion_configure")
|
|
59 |
set_tests_properties("install_corrosion_install" PROPERTIES FIXTURES_REQUIRED "fixture_corrosion_build")
|
|
60 |
set_tests_properties("install_corrosion_install" PROPERTIES FIXTURES_SETUP "fixture_corrosion_install")
|
|
61 |
|
|
62 |
add_test(NAME "install_corrosion_build_cleanup" COMMAND "${CMAKE_COMMAND}" -E remove_directory "${CMAKE_CURRENT_BINARY_DIR}/build-corrosion")
|
|
63 |
set_tests_properties("install_corrosion_build_cleanup" PROPERTIES
|
|
64 |
FIXTURES_CLEANUP
|
|
65 |
"fixture_corrosion_configure;fixture_corrosion_build"
|
|
66 |
)
|
|
67 |
|
|
68 |
add_test(NAME "install_corrosion_cleanup" COMMAND "${CMAKE_COMMAND}" -E remove_directory "${test_install_path}")
|
|
69 |
set_tests_properties("install_corrosion_cleanup" PROPERTIES
|
|
70 |
FIXTURES_CLEANUP
|
|
71 |
"fixture_corrosion_configure;fixture_corrosion_build;fixture_corrosion_install"
|
|
72 |
)
|
|
73 |
endif()
|
|
74 |
|
|
75 |
function(corrosion_tests_add_test test_name bin_names)
|
|
76 |
set(options "")
|
|
77 |
set(one_value_kewords "TEST_SRC_DIR")
|
|
78 |
set(multi_value_keywords "")
|
|
79 |
cmake_parse_arguments(PARSE_ARGV 2 TST "${options}" "${one_value_kewords}" "${multi_value_keywords}")
|
|
80 |
set(pass_through_arguments "${TST_UNPARSED_ARGUMENTS}")
|
|
81 |
|
|
82 |
# In the future we could add multiple tests here for different configurations (generator, build mode, rust version ...)
|
|
83 |
# which would allow us to simplify the github job matrix
|
|
84 |
if(TST_TEST_SRC_DIR)
|
|
85 |
set(test_dir "${TST_TEST_SRC_DIR}")
|
|
86 |
else()
|
|
87 |
set(test_dir "${test_name}")
|
|
88 |
endif()
|
|
89 |
|
|
90 |
|
|
91 |
if(CMAKE_C_COMPILER)
|
|
92 |
set(TEST_C_COMPILER "C_COMPILER" "${CMAKE_C_COMPILER}")
|
|
93 |
endif()
|
|
94 |
if(CMAKE_CXX_COMPILER)
|
|
95 |
set(TEST_CXX_COMPILER "CXX_COMPILER" "${CMAKE_CXX_COMPILER}")
|
|
96 |
endif()
|
|
97 |
if(CMAKE_GENERATOR_PLATFORM)
|
|
98 |
set(TEST_GENERATOR_PLATFORM "GENERATOR_PLATFORM" "${CMAKE_GENERATOR_PLATFORM}")
|
|
99 |
endif()
|
|
100 |
if(CORROSION_GENERATOR_EXECUTABLE)
|
|
101 |
# Mainly used in CI to build the native generator once and then reuse it for all tests
|
|
102 |
set(TEST_GENERATOR_BIN EXTERNAL_CORROSION_GENERATOR "${CORROSION_GENERATOR_EXECUTABLE}")
|
|
103 |
endif()
|
|
104 |
if(CMAKE_CROSSCOMPILING)
|
|
105 |
set(TEST_SYSTEM_NAME SYSTEM_NAME "${CMAKE_SYSTEM_NAME}")
|
|
106 |
endif()
|
|
107 |
|
|
108 |
add_test(NAME "${test_name}_build"
|
|
109 |
COMMAND
|
|
110 |
${CMAKE_COMMAND}
|
|
111 |
-P "${CMAKE_SOURCE_DIR}/test/ConfigureAndBuild.cmake"
|
|
112 |
SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/${test_dir}"
|
|
113 |
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/build-${test_name}"
|
|
114 |
GENERATOR "${CMAKE_GENERATOR}"
|
|
115 |
RUST_TOOLCHAIN "${Rust_TOOLCHAIN}"
|
|
116 |
CARGO_TARGET "${Rust_CARGO_TARGET}"
|
|
117 |
"${TEST_SYSTEM_NAME}"
|
|
118 |
"${TEST_C_COMPILER}"
|
|
119 |
"${TEST_CXX_COMPILER}"
|
|
120 |
"${TEST_GENERATOR_PLATFORM}"
|
|
121 |
"${TEST_GENERATOR_BIN}"
|
|
122 |
${pass_through_arguments}
|
|
123 |
|
|
124 |
COMMAND_EXPAND_LISTS
|
|
125 |
)
|
|
126 |
set_tests_properties("${test_name}_build" PROPERTIES FIXTURES_SETUP "build_fixture_${test_name}")
|
|
127 |
if(CORROSION_TESTS_INSTALL_CORROSION)
|
|
128 |
set_tests_properties("${test_name}_build" PROPERTIES FIXTURES_REQUIRED "fixture_corrosion_install")
|
|
129 |
endif()
|
|
130 |
foreach(bin ${bin_names})
|
|
131 |
if(WIN32)
|
|
132 |
set(bin_filename "${bin}.exe")
|
|
133 |
else()
|
|
134 |
set(bin_filename "${bin}")
|
|
135 |
endif()
|
|
136 |
add_test(NAME "${test_name}_run_${bin}" COMMAND "${CMAKE_CURRENT_BINARY_DIR}/build-${test_name}/${bin_filename}")
|
|
137 |
set_tests_properties("${test_name}_run_${bin}" PROPERTIES FIXTURES_REQUIRED "build_fixture_${test_name}")
|
|
138 |
# CMAKE_CROSSCOMPILING is not set when cross-compiling with VS (via -A flag).
|
|
139 |
# Todo: We could run x86 binaries on x64 hosts.
|
|
140 |
if(CMAKE_CROSSCOMPILING OR CMAKE_VS_PLATFORM_NAME)
|
|
141 |
# Todo: In the future we could potentially run some tests with qemu.
|
|
142 |
set_tests_properties("${test_name}_run_${bin}" PROPERTIES DISABLED TRUE)
|
|
143 |
endif()
|
|
144 |
endforeach()
|
|
145 |
|
|
146 |
if(CORROSION_TESTS_KEEP_BUILDDIRS)
|
|
147 |
add_test(NAME "${test_name}_cleanup_artifacts"
|
|
148 |
COMMAND "${CMAKE_COMMAND}" --build "${CMAKE_CURRENT_BINARY_DIR}/build-${test_name}" --target clean
|
|
149 |
)
|
|
150 |
add_test(NAME "${test_name}_cleanup_cargo"
|
|
151 |
COMMAND "${CMAKE_COMMAND}" -E remove_directory "${CMAKE_CURRENT_BINARY_DIR}/build-${test_name}/cargo"
|
|
152 |
)
|
|
153 |
set_tests_properties("${test_name}_cleanup_artifacts" PROPERTIES FIXTURES_CLEANUP "build_fixture_${test_name}")
|
|
154 |
set_tests_properties("${test_name}_cleanup_cargo" PROPERTIES FIXTURES_CLEANUP "build_fixture_${test_name}")
|
|
155 |
else()
|
|
156 |
add_test(NAME "${test_name}_cleanup" COMMAND "${CMAKE_COMMAND}" -E remove_directory "${CMAKE_CURRENT_BINARY_DIR}/build-${test_name}")
|
|
157 |
set_tests_properties("${test_name}_cleanup" PROPERTIES FIXTURES_CLEANUP "build_fixture_${test_name}")
|
|
158 |
endif()
|
|
159 |
endfunction()
|
|
160 |
|
|
161 |
# Please keep this in alphabetical order.
|
|
162 |
add_subdirectory(cargo_flags)
|
|
163 |
add_subdirectory(cpp2rust)
|
|
164 |
if(Rust_VERSION VERSION_GREATER_EQUAL "1.64.0")
|
|
165 |
# Flag `--crate-type` is only supported since Rust 1.64.0
|
|
166 |
add_subdirectory(crate_type)
|
|
167 |
endif()
|
|
168 |
add_subdirectory(custom_profiles)
|
|
169 |
add_subdirectory(cbindgen)
|
|
170 |
add_subdirectory(cxxbridge)
|
|
171 |
add_subdirectory(envvar)
|
|
172 |
add_subdirectory(external_corrosion_generator)
|
|
173 |
add_subdirectory(features)
|
|
174 |
add_subdirectory(find_rust)
|
|
175 |
add_subdirectory(gensource)
|
|
176 |
add_subdirectory(hostbuild)
|
|
177 |
add_subdirectory(multitarget)
|
|
178 |
add_subdirectory(nostd)
|
|
179 |
add_subdirectory("output directory")
|
|
180 |
add_subdirectory(parse_target_triple)
|
|
181 |
add_subdirectory(rust2cpp)
|
|
182 |
add_subdirectory(rustflags)
|
|
183 |
add_subdirectory(workspace)
|