-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cmake
More file actions
48 lines (44 loc) · 1.34 KB
/
test.cmake
File metadata and controls
48 lines (44 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Copyright (c) 2023, Intercreate, Inc.
# SPDX-License-Identifier: Apache-2.0
#
# Automate CMake configure, build, and test.
#
# usage:
# cmake -P test.cmake [toolchain]
#
# See the toolchain folder for options. Specify without the extension, .cmake.
#
# example:
# cmake -P test.cmake arm-none-eabi-gcc
if(${CMAKE_ARGC} EQUAL 3)
set(toolchain_arg)
set(build_folder build-native)
elseif(${CMAKE_ARGC} EQUAL 4)
set(toolchain_arg "-DCMAKE_TOOLCHAIN_FILE=toolchain/${CMAKE_ARGV3}.cmake")
set(build_folder "build-${CMAKE_ARGV3}")
else()
message(FATAL_ERROR "Must provide 0 or 1 arguments!")
endif()
execute_process(
COMMAND cmake "-B${build_folder}" "-GNinja" "${toolchain_arg}"
RESULT_VARIABLE res
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
)
if(NOT ${res} STREQUAL "0")
message(FATAL_ERROR "CMake configuration step failed.")
endif()
execute_process(
COMMAND cmake "--build" "${build_folder}" "--clean-first"
RESULT_VARIABLE res
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
)
if(NOT ${res} STREQUAL "0")
message(FATAL_ERROR "CMake build step failed.")
endif()
execute_process(COMMAND ctest "-V" "--test-dir" "${build_folder}/tests" "--output-on-failure"
RESULT_VARIABLE res
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
)
if(NOT ${res} STREQUAL "0")
message(FATAL_ERROR "1 or more tests failed.")
endif()