16050
|
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")
|
16067
|
18 |
file(REAL_PATH "${CMAKE_CURRENT_SOURCE_DIR}/.." corrosion_source_dir)
|
16050
|
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()"
|
16067
|
25 |
" add_subdirectory(\"${corrosion_source_dir}\" corrosion)"
|
16050
|
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)
|
16067
|
76 |
set(options "IS_HOSTBUILD")
|
16050
|
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 |
|
16067
|
90 |
set(configure_cmake_args)
|
16050
|
91 |
if(CMAKE_C_COMPILER)
|
16067
|
92 |
list(APPEND configure_cmake_args "C_COMPILER" "${CMAKE_C_COMPILER}")
|
16050
|
93 |
endif()
|
|
94 |
if(CMAKE_CXX_COMPILER)
|
16067
|
95 |
list(APPEND configure_cmake_args "CXX_COMPILER" "${CMAKE_CXX_COMPILER}")
|
|
96 |
endif()
|
|
97 |
if(CMAKE_C_COMPILER_TARGET)
|
|
98 |
list(APPEND configure_cmake_args "C_COMPILER_TARGET" "${CMAKE_C_COMPILER_TARGET}")
|
|
99 |
endif()
|
|
100 |
if(CMAKE_CXX_COMPILER_TARGET)
|
|
101 |
list(APPEND configure_cmake_args "CXX_COMPILER_TARGET" "${CMAKE_CXX_COMPILER_TARGET}")
|
16050
|
102 |
endif()
|
|
103 |
if(CMAKE_GENERATOR_PLATFORM)
|
16067
|
104 |
list(APPEND configure_cmake_args "GENERATOR_PLATFORM" "${CMAKE_GENERATOR_PLATFORM}")
|
16050
|
105 |
endif()
|
|
106 |
if(CMAKE_CROSSCOMPILING)
|
16067
|
107 |
list(APPEND configure_cmake_args SYSTEM_NAME "${CMAKE_SYSTEM_NAME}")
|
|
108 |
endif()
|
|
109 |
if(CMAKE_OSX_ARCHITECTURES)
|
|
110 |
list(APPEND configure_cmake_args OSX_ARCHITECTURES "${CMAKE_OSX_ARCHITECTURES}")
|
|
111 |
endif()
|
|
112 |
if(CMAKE_TOOLCHAIN_FILE)
|
|
113 |
list(APPEND configure_cmake_args TOOLCHAIN_FILE "${CMAKE_TOOLCHAIN_FILE}")
|
16050
|
114 |
endif()
|
|
115 |
|
|
116 |
add_test(NAME "${test_name}_build"
|
|
117 |
COMMAND
|
|
118 |
${CMAKE_COMMAND}
|
|
119 |
-P "${CMAKE_SOURCE_DIR}/test/ConfigureAndBuild.cmake"
|
|
120 |
SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/${test_dir}"
|
|
121 |
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/build-${test_name}"
|
|
122 |
GENERATOR "${CMAKE_GENERATOR}"
|
|
123 |
RUST_TOOLCHAIN "${Rust_TOOLCHAIN}"
|
|
124 |
CARGO_TARGET "${Rust_CARGO_TARGET}"
|
16067
|
125 |
${configure_cmake_args}
|
16050
|
126 |
${pass_through_arguments}
|
|
127 |
|
|
128 |
COMMAND_EXPAND_LISTS
|
|
129 |
)
|
|
130 |
set_tests_properties("${test_name}_build" PROPERTIES FIXTURES_SETUP "build_fixture_${test_name}")
|
|
131 |
if(CORROSION_TESTS_INSTALL_CORROSION)
|
|
132 |
set_tests_properties("${test_name}_build" PROPERTIES FIXTURES_REQUIRED "fixture_corrosion_install")
|
|
133 |
endif()
|
|
134 |
foreach(bin ${bin_names})
|
|
135 |
if(WIN32)
|
|
136 |
set(bin_filename "${bin}.exe")
|
|
137 |
else()
|
|
138 |
set(bin_filename "${bin}")
|
|
139 |
endif()
|
|
140 |
add_test(NAME "${test_name}_run_${bin}" COMMAND "${CMAKE_CURRENT_BINARY_DIR}/build-${test_name}/${bin_filename}")
|
|
141 |
set_tests_properties("${test_name}_run_${bin}" PROPERTIES FIXTURES_REQUIRED "build_fixture_${test_name}")
|
|
142 |
# CMAKE_CROSSCOMPILING is not set when cross-compiling with VS (via -A flag).
|
|
143 |
# Todo: We could run x86 binaries on x64 hosts.
|
16067
|
144 |
if((CMAKE_CROSSCOMPILING OR CMAKE_VS_PLATFORM_NAME) AND NOT "${TST_IS_HOSTBUILD}")
|
16050
|
145 |
# Todo: In the future we could potentially run some tests with qemu.
|
|
146 |
set_tests_properties("${test_name}_run_${bin}" PROPERTIES DISABLED TRUE)
|
|
147 |
endif()
|
|
148 |
endforeach()
|
|
149 |
|
|
150 |
if(CORROSION_TESTS_KEEP_BUILDDIRS)
|
|
151 |
add_test(NAME "${test_name}_cleanup_artifacts"
|
|
152 |
COMMAND "${CMAKE_COMMAND}" --build "${CMAKE_CURRENT_BINARY_DIR}/build-${test_name}" --target clean
|
|
153 |
)
|
|
154 |
add_test(NAME "${test_name}_cleanup_cargo"
|
|
155 |
COMMAND "${CMAKE_COMMAND}" -E remove_directory "${CMAKE_CURRENT_BINARY_DIR}/build-${test_name}/cargo"
|
|
156 |
)
|
|
157 |
set_tests_properties("${test_name}_cleanup_artifacts" PROPERTIES FIXTURES_CLEANUP "build_fixture_${test_name}")
|
|
158 |
set_tests_properties("${test_name}_cleanup_cargo" PROPERTIES FIXTURES_CLEANUP "build_fixture_${test_name}")
|
|
159 |
else()
|
|
160 |
add_test(NAME "${test_name}_cleanup" COMMAND "${CMAKE_COMMAND}" -E remove_directory "${CMAKE_CURRENT_BINARY_DIR}/build-${test_name}")
|
|
161 |
set_tests_properties("${test_name}_cleanup" PROPERTIES FIXTURES_CLEANUP "build_fixture_${test_name}")
|
|
162 |
endif()
|
|
163 |
endfunction()
|
|
164 |
|
|
165 |
# Please keep this in alphabetical order.
|
|
166 |
add_subdirectory(cargo_flags)
|
|
167 |
add_subdirectory(cpp2rust)
|
|
168 |
if(Rust_VERSION VERSION_GREATER_EQUAL "1.64.0")
|
|
169 |
# Flag `--crate-type` is only supported since Rust 1.64.0
|
|
170 |
add_subdirectory(crate_type)
|
16067
|
171 |
add_subdirectory(override_crate_type)
|
16050
|
172 |
endif()
|
|
173 |
add_subdirectory(custom_profiles)
|
|
174 |
add_subdirectory(cbindgen)
|
16067
|
175 |
add_subdirectory(corrosion_install)
|
16050
|
176 |
add_subdirectory(cxxbridge)
|
|
177 |
add_subdirectory(envvar)
|
|
178 |
add_subdirectory(features)
|
|
179 |
add_subdirectory(find_rust)
|
|
180 |
add_subdirectory(gensource)
|
|
181 |
add_subdirectory(hostbuild)
|
|
182 |
add_subdirectory(multitarget)
|
|
183 |
add_subdirectory(nostd)
|
|
184 |
add_subdirectory("output directory")
|
|
185 |
add_subdirectory(parse_target_triple)
|
|
186 |
add_subdirectory(rust2cpp)
|
|
187 |
add_subdirectory(rustflags)
|
|
188 |
add_subdirectory(workspace)
|