16021
|
1 |
# CMake script to configure and build a test project
|
|
2 |
|
|
3 |
set(TEST_ARG_LIST)
|
|
4 |
|
|
5 |
# Expect actual arguments to start at index 3 (cmake -P <script_name>)
|
|
6 |
foreach(ARG_INDEX RANGE 3 ${CMAKE_ARGC})
|
|
7 |
list(APPEND TEST_ARG_LIST "${CMAKE_ARGV${ARG_INDEX}}")
|
|
8 |
endforeach()
|
|
9 |
|
|
10 |
set(options "USE_INSTALLED_CORROSION")
|
|
11 |
set(oneValueArgs
|
|
12 |
SOURCE_DIR
|
|
13 |
BINARY_DIR
|
|
14 |
GENERATOR
|
|
15 |
GENERATOR_PLATFORM
|
|
16 |
RUST_TOOLCHAIN
|
|
17 |
CARGO_TARGET
|
|
18 |
C_COMPILER
|
|
19 |
CXX_COMPILER
|
16038
|
20 |
C_COMPILER_TARGET
|
|
21 |
CXX_COMPILER_TARGET
|
16021
|
22 |
SYSTEM_NAME
|
|
23 |
CARGO_PROFILE
|
16038
|
24 |
OSX_ARCHITECTURES
|
|
25 |
TOOLCHAIN_FILE
|
16021
|
26 |
)
|
|
27 |
set(multiValueArgs "PASS_THROUGH_ARGS")
|
|
28 |
cmake_parse_arguments(TEST "${options}" "${oneValueArgs}"
|
|
29 |
"${multiValueArgs}" ${TEST_ARG_LIST} )
|
|
30 |
|
16038
|
31 |
set(configure_args "")
|
16021
|
32 |
if(TEST_CARGO_TARGET)
|
16038
|
33 |
list(APPEND configure_args "-DRust_CARGO_TARGET=${TEST_CARGO_TARGET}")
|
16021
|
34 |
endif()
|
|
35 |
if(TEST_USE_INSTALLED_CORROSION)
|
16038
|
36 |
list(APPEND configure_args "-DCORROSION_TESTS_FIND_CORROSION=ON")
|
16021
|
37 |
endif()
|
|
38 |
if(TEST_GENERATOR_PLATFORM)
|
16038
|
39 |
list(APPEND configure_args "-A${TEST_GENERATOR_PLATFORM}")
|
16021
|
40 |
endif()
|
|
41 |
if(TEST_C_COMPILER)
|
16038
|
42 |
list(APPEND configure_args "-DCMAKE_C_COMPILER=${TEST_C_COMPILER}")
|
16021
|
43 |
endif()
|
|
44 |
if(TEST_CXX_COMPILER)
|
16038
|
45 |
list(APPEND configure_args "-DCMAKE_CXX_COMPILER=${TEST_CXX_COMPILER}")
|
|
46 |
endif()
|
|
47 |
if(TEST_C_COMPILER_TARGET)
|
|
48 |
list(APPEND configure_args "-DCMAKE_C_COMPILER_TARGET=${TEST_C_COMPILER_TARGET}")
|
|
49 |
endif()
|
|
50 |
if(TEST_CXX_COMPILER_TARGET)
|
|
51 |
list(APPEND configure_args "-DCMAKE_CXX_COMPILER_TARGET=${TEST_CXX_COMPILER_TARGET}")
|
16021
|
52 |
endif()
|
|
53 |
if(TEST_SYSTEM_NAME)
|
16038
|
54 |
list(APPEND configure_args "-DCMAKE_SYSTEM_NAME=${TEST_SYSTEM_NAME}")
|
16021
|
55 |
endif()
|
16038
|
56 |
if(TEST_OSX_ARCHITECTURES)
|
|
57 |
list(APPEND configure_args "-DCMAKE_OSX_ARCHITECTURES=${TEST_OSX_ARCHITECTURES}")
|
|
58 |
endif()
|
|
59 |
if(TEST_TOOLCHAIN_FILE)
|
|
60 |
list(APPEND configure_args "-DCMAKE_TOOLCHAIN_FILE=${TEST_TOOLCHAIN_FILE}")
|
16021
|
61 |
endif()
|
|
62 |
if(TEST_CARGO_PROFILE)
|
16038
|
63 |
list(APPEND configure_args "-DCARGO_PROFILE=${TEST_CARGO_PROFILE}")
|
16021
|
64 |
endif()
|
|
65 |
|
|
66 |
# Remove old binary directory
|
|
67 |
file(REMOVE_RECURSE "${TEST_BINARY_DIR}")
|
|
68 |
|
|
69 |
file(MAKE_DIRECTORY "${TEST_BINARY_DIR}")
|
|
70 |
|
|
71 |
message(STATUS "TEST_BINARY_DIRECTORY: ${TEST_BINARY_DIR}")
|
|
72 |
|
|
73 |
execute_process(
|
|
74 |
COMMAND
|
|
75 |
"${CMAKE_COMMAND}"
|
|
76 |
"-G${TEST_GENERATOR}"
|
|
77 |
"-DRust_TOOLCHAIN=${TEST_RUST_TOOLCHAIN}"
|
|
78 |
--log-level Debug
|
16038
|
79 |
${configure_args}
|
16021
|
80 |
${TEST_PASS_THROUGH_ARGS}
|
|
81 |
-S "${TEST_SOURCE_DIR}"
|
|
82 |
-B "${TEST_BINARY_DIR}"
|
|
83 |
COMMAND_ECHO STDOUT
|
|
84 |
RESULT_VARIABLE EXIT_CODE
|
|
85 |
)
|
|
86 |
|
|
87 |
if (NOT "${EXIT_CODE}" EQUAL 0)
|
|
88 |
message(FATAL_ERROR "Configure step failed. Exit code: `${EXIT_CODE}`")
|
|
89 |
endif()
|
|
90 |
|
|
91 |
if ("${TEST_GENERATOR}" STREQUAL "Ninja Multi-Config"
|
|
92 |
OR "${TEST_GENERATOR}" MATCHES "Visual Studio"
|
|
93 |
)
|
|
94 |
foreach(config Debug Release RelWithDebInfo)
|
|
95 |
execute_process(
|
|
96 |
COMMAND "${CMAKE_COMMAND}"
|
|
97 |
--build "${TEST_BINARY_DIR}"
|
|
98 |
--config "${config}"
|
|
99 |
COMMAND_ECHO STDOUT
|
|
100 |
RESULT_VARIABLE EXIT_CODE
|
|
101 |
)
|
|
102 |
if (NOT "${EXIT_CODE}" EQUAL 0)
|
|
103 |
message(FATAL_ERROR "Build step failed for config `${config}`. "
|
|
104 |
"Exit code: `${EXIT_CODE}`")
|
|
105 |
endif()
|
|
106 |
endforeach()
|
|
107 |
else()
|
|
108 |
execute_process(
|
|
109 |
COMMAND "${CMAKE_COMMAND}" --build "${TEST_BINARY_DIR}"
|
|
110 |
COMMAND_ECHO STDOUT
|
|
111 |
RESULT_VARIABLE EXIT_CODE
|
|
112 |
)
|
|
113 |
if (NOT "${EXIT_CODE}" EQUAL 0)
|
|
114 |
message(FATAL_ERROR "Build step failed. Exit code: `${EXIT_CODE}`")
|
|
115 |
endif()
|
|
116 |
endif()
|
|
117 |
|
|
118 |
|