|
1 if(CMAKE_VERSION VERSION_LESS 3.19.0) |
|
2 return() |
|
3 endif() |
|
4 |
|
5 if(CMAKE_C_COMPILER) |
|
6 set(TEST_C_COMPILER "C_COMPILER" "${CMAKE_C_COMPILER}") |
|
7 endif() |
|
8 if(CMAKE_CXX_COMPILER) |
|
9 set(TEST_CXX_COMPILER "CXX_COMPILER" "${CMAKE_CXX_COMPILER}") |
|
10 endif() |
|
11 if(CMAKE_GENERATOR_PLATFORM) |
|
12 set(TEST_GENERATOR_PLATFORM "GENERATOR_PLATFORM" "${CMAKE_GENERATOR_PLATFORM}") |
|
13 endif() |
|
14 |
|
15 add_test(NAME "output_directory_build" |
|
16 COMMAND |
|
17 ${CMAKE_COMMAND} |
|
18 -P "${CMAKE_SOURCE_DIR}/test/ConfigureAndBuild.cmake" |
|
19 SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/output directory" |
|
20 BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/build" |
|
21 GENERATOR "${CMAKE_GENERATOR}" |
|
22 RUST_TOOLCHAIN "${Rust_TOOLCHAIN}" |
|
23 CARGO_TARGET "${Rust_CARGO_TARGET}" |
|
24 SYSTEM_NAME "${CMAKE_SYSTEM_NAME}" |
|
25 "${TEST_C_COMPILER}" |
|
26 "${TEST_CXX_COMPILER}" |
|
27 "${TEST_GENERATOR_PLATFORM}" |
|
28 |
|
29 COMMAND_EXPAND_LISTS |
|
30 ) |
|
31 set_tests_properties("output_directory_build" PROPERTIES FIXTURES_SETUP "build_fixture_output_directory") |
|
32 if(CORROSION_TESTS_INSTALL_CORROSION) |
|
33 set_tests_properties("output_directory_build" PROPERTIES FIXTURES_REQUIRED "fixture_corrosion_install") |
|
34 endif() |
|
35 |
|
36 foreach(output_approach targetprop var) |
|
37 if(output_approach STREQUAL "targetprop") |
|
38 set(rust_proj_suffix "1") |
|
39 elseif(output_approach STREQUAL "var") |
|
40 set(rust_proj_suffix "2") |
|
41 else() |
|
42 message(FATAL_ERROR "specify rust project suffix for new output approach ${output_approach}") |
|
43 endif() |
|
44 |
|
45 set(bin_name "rust_bin${rust_proj_suffix}${CMAKE_EXECUTABLE_SUFFIX}") |
|
46 |
|
47 add_test(NAME output_directory_bin_${output_approach} |
|
48 COMMAND |
|
49 "${CMAKE_COMMAND}" |
|
50 -P "${CMAKE_CURRENT_SOURCE_DIR}/TestFileExists.cmake" |
|
51 "${CMAKE_CURRENT_BINARY_DIR}/build/custom_bin_${output_approach}/${bin_name}" |
|
52 ) |
|
53 set_tests_properties("output_directory_bin_${output_approach}" PROPERTIES FIXTURES_REQUIRED "build_fixture_output_directory") |
|
54 |
|
55 set(lib_name "rust_lib${rust_proj_suffix}") |
|
56 |
|
57 set(static_lib_name "${CMAKE_STATIC_LIBRARY_PREFIX}${lib_name}${CMAKE_STATIC_LIBRARY_SUFFIX}") |
|
58 |
|
59 add_test(NAME output_directory_staticlib_${output_approach} |
|
60 COMMAND |
|
61 "${CMAKE_COMMAND}" |
|
62 -P "${CMAKE_CURRENT_SOURCE_DIR}/TestFileExists.cmake" |
|
63 "${CMAKE_CURRENT_BINARY_DIR}/build/custom_archive_${output_approach}/${static_lib_name}" |
|
64 ) |
|
65 set_tests_properties("output_directory_staticlib_${output_approach}" PROPERTIES FIXTURES_REQUIRED "build_fixture_output_directory") |
|
66 |
|
67 if(MINGW) |
|
68 # Windows-GNU defines "lib" as prefix for DLLs, but cargo creates foo.dll instead of libfoo.dll |
|
69 set(dynamic_lib_prefix "") |
|
70 else() |
|
71 set(dynamic_lib_prefix "${CMAKE_SHARED_LIBRARY_PREFIX}") |
|
72 endif() |
|
73 set(dynamic_lib_name "${dynamic_lib_prefix}${lib_name}${CMAKE_SHARED_LIBRARY_SUFFIX}") |
|
74 |
|
75 add_test(NAME output_directory_cdylib_${output_approach} |
|
76 COMMAND |
|
77 "${CMAKE_COMMAND}" |
|
78 -P "${CMAKE_CURRENT_SOURCE_DIR}/TestFileExists.cmake" |
|
79 "${CMAKE_CURRENT_BINARY_DIR}/build/custom_lib_${output_approach}/${dynamic_lib_name}" |
|
80 ) |
|
81 set_tests_properties("output_directory_cdylib_${output_approach}" PROPERTIES FIXTURES_REQUIRED "build_fixture_output_directory") |
|
82 |
|
83 if(WIN32) |
|
84 set(implib_name ${CMAKE_IMPORT_LIBRARY_PREFIX}${lib_name}${CMAKE_IMPORT_LIBRARY_SUFFIX}) |
|
85 |
|
86 add_test(NAME output_directory_implib_${output_approach} |
|
87 COMMAND |
|
88 "${CMAKE_COMMAND}" |
|
89 -P "${CMAKE_CURRENT_SOURCE_DIR}/TestFileExists.cmake" |
|
90 # Implib is an ARCHIVE artifact, see: |
|
91 # https://cmake.org/cmake/help/v3.25/manual/cmake-buildsystem.7.html#archive-output-artifacts |
|
92 "${CMAKE_CURRENT_BINARY_DIR}/build/custom_archive_${output_approach}/${implib_name}" |
|
93 ) |
|
94 set_tests_properties("output_directory_implib_${output_approach}" PROPERTIES FIXTURES_REQUIRED "build_fixture_output_directory") |
|
95 |
|
96 if(MSVC) |
|
97 if(output_approach STREQUAL "targetprop") |
|
98 set(expected_lib_pdb_path "custom_lib_pdb_targetprop") |
|
99 set(expected_bin_pdb_path "custom_bin_pdb_targetprop") |
|
100 elseif(output_approach STREQUAL "var") |
|
101 # When using a CMAKE_ variable instead of a target property, both targets |
|
102 # end up in the same directory. |
|
103 set(expected_lib_pdb_path "custom_binlib_pdb_var") |
|
104 set(expected_bin_pdb_path "custom_binlib_pdb_var") |
|
105 else() |
|
106 message(FATAL_ERROR "specify rust project suffix for new output approach ${output_approach}") |
|
107 endif() |
|
108 |
|
109 set(lib_pdb_name "${lib_name}.pdb") |
|
110 add_test(NAME output_directory_cdylib_pdb_${output_approach} |
|
111 COMMAND |
|
112 "${CMAKE_COMMAND}" |
|
113 -P "${CMAKE_CURRENT_SOURCE_DIR}/TestFileExists.cmake" |
|
114 "${CMAKE_CURRENT_BINARY_DIR}/build/${expected_lib_pdb_path}/${lib_pdb_name}" |
|
115 ) |
|
116 set_tests_properties("output_directory_cdylib_pdb_${output_approach}" PROPERTIES FIXTURES_REQUIRED "build_fixture_output_directory") |
|
117 |
|
118 set(bin_pdb_name "rust_bin${rust_proj_suffix}.pdb") |
|
119 add_test(NAME output_directory_bin_pdb_${output_approach} |
|
120 COMMAND |
|
121 "${CMAKE_COMMAND}" |
|
122 -P "${CMAKE_CURRENT_SOURCE_DIR}/TestFileExists.cmake" |
|
123 "${CMAKE_CURRENT_BINARY_DIR}/build/${expected_bin_pdb_path}/${bin_pdb_name}" |
|
124 ) |
|
125 set_tests_properties("output_directory_bin_pdb_${output_approach}" PROPERTIES FIXTURES_REQUIRED "build_fixture_output_directory") |
|
126 endif() |
|
127 endif() |
|
128 |
|
129 endforeach() |
|
130 |
|
131 add_test(NAME postbuild_custom_command |
|
132 COMMAND |
|
133 "${CMAKE_COMMAND}" |
|
134 -P "${CMAKE_CURRENT_SOURCE_DIR}/TestFileExists.cmake" |
|
135 "${CMAKE_CURRENT_BINARY_DIR}/build/another_dir/moved_bin" |
|
136 ) |
|
137 set_tests_properties("postbuild_custom_command" PROPERTIES FIXTURES_REQUIRED "build_fixture_output_directory") |
|
138 |
|
139 add_test(NAME "output_directory_cleanup" COMMAND "${CMAKE_COMMAND}" -E remove_directory "${CMAKE_CURRENT_BINARY_DIR}/build") |
|
140 set_tests_properties("output_directory_cleanup" PROPERTIES FIXTURES_CLEANUP "build_fixture_output_directory") |