13 target directories and will keep the build directories, which may be useful for caching." |
13 target directories and will keep the build directories, which may be useful for caching." |
14 OFF) |
14 OFF) |
15 mark_as_advanced(CORROSION_TESTS_NO_CLEANUP) |
15 mark_as_advanced(CORROSION_TESTS_NO_CLEANUP) |
16 |
16 |
17 set(test_install_path "${CMAKE_CURRENT_BINARY_DIR}/test-install-corrosion") |
17 set(test_install_path "${CMAKE_CURRENT_BINARY_DIR}/test-install-corrosion") |
18 |
18 file(REAL_PATH "${CMAKE_CURRENT_SOURCE_DIR}/.." corrosion_source_dir) |
19 set(test_header_contents |
19 set(test_header_contents |
20 "option(CORROSION_TESTS_FIND_CORROSION \"Use Corrosion as a subdirectory\" OFF)" |
20 "option(CORROSION_TESTS_FIND_CORROSION \"Use Corrosion as a subdirectory\" OFF)" |
21 "if (CORROSION_TESTS_FIND_CORROSION)" |
21 "if (CORROSION_TESTS_FIND_CORROSION)" |
22 " set(CMAKE_PREFIX_PATH \"${test_install_path}\" CACHE INTERNAL \"\" FORCE)" |
22 " set(CMAKE_PREFIX_PATH \"${test_install_path}\" CACHE INTERNAL \"\" FORCE)" |
23 " find_package(Corrosion REQUIRED PATHS \"${test_install_path}\" NO_CMAKE_SYSTEM_PATH)" |
23 " find_package(Corrosion REQUIRED PATHS \"${test_install_path}\" NO_CMAKE_SYSTEM_PATH)" |
24 "else()" |
24 "else()" |
25 " add_subdirectory(\"${CMAKE_CURRENT_SOURCE_DIR}/..\" corrosion)" |
25 " add_subdirectory(\"${corrosion_source_dir}\" corrosion)" |
26 "endif()" |
26 "endif()" |
27 ) |
27 ) |
28 |
28 |
29 string(REPLACE ";" "\n" test_header_contents "${test_header_contents}") |
29 string(REPLACE ";" "\n" test_header_contents "${test_header_contents}") |
30 |
30 |
71 "fixture_corrosion_configure;fixture_corrosion_build;fixture_corrosion_install" |
71 "fixture_corrosion_configure;fixture_corrosion_build;fixture_corrosion_install" |
72 ) |
72 ) |
73 endif() |
73 endif() |
74 |
74 |
75 function(corrosion_tests_add_test test_name bin_names) |
75 function(corrosion_tests_add_test test_name bin_names) |
76 set(options "") |
76 set(options "IS_HOSTBUILD") |
77 set(one_value_kewords "TEST_SRC_DIR") |
77 set(one_value_kewords "TEST_SRC_DIR") |
78 set(multi_value_keywords "") |
78 set(multi_value_keywords "") |
79 cmake_parse_arguments(PARSE_ARGV 2 TST "${options}" "${one_value_kewords}" "${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}") |
80 set(pass_through_arguments "${TST_UNPARSED_ARGUMENTS}") |
81 |
81 |
85 set(test_dir "${TST_TEST_SRC_DIR}") |
85 set(test_dir "${TST_TEST_SRC_DIR}") |
86 else() |
86 else() |
87 set(test_dir "${test_name}") |
87 set(test_dir "${test_name}") |
88 endif() |
88 endif() |
89 |
89 |
90 |
90 set(configure_cmake_args) |
91 if(CMAKE_C_COMPILER) |
91 if(CMAKE_C_COMPILER) |
92 set(TEST_C_COMPILER "C_COMPILER" "${CMAKE_C_COMPILER}") |
92 list(APPEND configure_cmake_args "C_COMPILER" "${CMAKE_C_COMPILER}") |
93 endif() |
93 endif() |
94 if(CMAKE_CXX_COMPILER) |
94 if(CMAKE_CXX_COMPILER) |
95 set(TEST_CXX_COMPILER "CXX_COMPILER" "${CMAKE_CXX_COMPILER}") |
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}") |
96 endif() |
102 endif() |
97 if(CMAKE_GENERATOR_PLATFORM) |
103 if(CMAKE_GENERATOR_PLATFORM) |
98 set(TEST_GENERATOR_PLATFORM "GENERATOR_PLATFORM" "${CMAKE_GENERATOR_PLATFORM}") |
104 list(APPEND configure_cmake_args "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() |
105 endif() |
104 if(CMAKE_CROSSCOMPILING) |
106 if(CMAKE_CROSSCOMPILING) |
105 set(TEST_SYSTEM_NAME SYSTEM_NAME "${CMAKE_SYSTEM_NAME}") |
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}") |
106 endif() |
114 endif() |
107 |
115 |
108 add_test(NAME "${test_name}_build" |
116 add_test(NAME "${test_name}_build" |
109 COMMAND |
117 COMMAND |
110 ${CMAKE_COMMAND} |
118 ${CMAKE_COMMAND} |
112 SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/${test_dir}" |
120 SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/${test_dir}" |
113 BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/build-${test_name}" |
121 BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/build-${test_name}" |
114 GENERATOR "${CMAKE_GENERATOR}" |
122 GENERATOR "${CMAKE_GENERATOR}" |
115 RUST_TOOLCHAIN "${Rust_TOOLCHAIN}" |
123 RUST_TOOLCHAIN "${Rust_TOOLCHAIN}" |
116 CARGO_TARGET "${Rust_CARGO_TARGET}" |
124 CARGO_TARGET "${Rust_CARGO_TARGET}" |
117 "${TEST_SYSTEM_NAME}" |
125 ${configure_cmake_args} |
118 "${TEST_C_COMPILER}" |
|
119 "${TEST_CXX_COMPILER}" |
|
120 "${TEST_GENERATOR_PLATFORM}" |
|
121 "${TEST_GENERATOR_BIN}" |
|
122 ${pass_through_arguments} |
126 ${pass_through_arguments} |
123 |
127 |
124 COMMAND_EXPAND_LISTS |
128 COMMAND_EXPAND_LISTS |
125 ) |
129 ) |
126 set_tests_properties("${test_name}_build" PROPERTIES FIXTURES_SETUP "build_fixture_${test_name}") |
130 set_tests_properties("${test_name}_build" PROPERTIES FIXTURES_SETUP "build_fixture_${test_name}") |
135 endif() |
139 endif() |
136 add_test(NAME "${test_name}_run_${bin}" COMMAND "${CMAKE_CURRENT_BINARY_DIR}/build-${test_name}/${bin_filename}") |
140 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}") |
141 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). |
142 # CMAKE_CROSSCOMPILING is not set when cross-compiling with VS (via -A flag). |
139 # Todo: We could run x86 binaries on x64 hosts. |
143 # Todo: We could run x86 binaries on x64 hosts. |
140 if(CMAKE_CROSSCOMPILING OR CMAKE_VS_PLATFORM_NAME) |
144 if((CMAKE_CROSSCOMPILING OR CMAKE_VS_PLATFORM_NAME) AND NOT "${TST_IS_HOSTBUILD}") |
141 # Todo: In the future we could potentially run some tests with qemu. |
145 # Todo: In the future we could potentially run some tests with qemu. |
142 set_tests_properties("${test_name}_run_${bin}" PROPERTIES DISABLED TRUE) |
146 set_tests_properties("${test_name}_run_${bin}" PROPERTIES DISABLED TRUE) |
143 endif() |
147 endif() |
144 endforeach() |
148 endforeach() |
145 |
149 |
162 add_subdirectory(cargo_flags) |
166 add_subdirectory(cargo_flags) |
163 add_subdirectory(cpp2rust) |
167 add_subdirectory(cpp2rust) |
164 if(Rust_VERSION VERSION_GREATER_EQUAL "1.64.0") |
168 if(Rust_VERSION VERSION_GREATER_EQUAL "1.64.0") |
165 # Flag `--crate-type` is only supported since Rust 1.64.0 |
169 # Flag `--crate-type` is only supported since Rust 1.64.0 |
166 add_subdirectory(crate_type) |
170 add_subdirectory(crate_type) |
|
171 add_subdirectory(override_crate_type) |
167 endif() |
172 endif() |
168 add_subdirectory(custom_profiles) |
173 add_subdirectory(custom_profiles) |
169 add_subdirectory(cbindgen) |
174 add_subdirectory(cbindgen) |
|
175 add_subdirectory(corrosion_install) |
170 add_subdirectory(cxxbridge) |
176 add_subdirectory(cxxbridge) |
171 add_subdirectory(envvar) |
177 add_subdirectory(envvar) |
172 add_subdirectory(external_corrosion_generator) |
|
173 add_subdirectory(features) |
178 add_subdirectory(features) |
174 add_subdirectory(find_rust) |
179 add_subdirectory(find_rust) |
175 add_subdirectory(gensource) |
180 add_subdirectory(gensource) |
176 add_subdirectory(hostbuild) |
181 add_subdirectory(hostbuild) |
177 add_subdirectory(multitarget) |
182 add_subdirectory(multitarget) |