| 1 |
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying |
| 2 |
# file LICENSE.rst or https://cmake.org/licensing for details. |
| 3 |
|
| 4 |
cmake_minimum_required(VERSION 3.12 FATAL_ERROR) |
| 5 |
|
| 6 |
project(test C) |
| 7 |
|
| 8 |
# Tests assume no previous builds in the build directory |
| 9 |
file(REMOVE_RECURSE ${CMAKE_CURRENT_BINARY_DIR}/build) |
| 10 |
|
| 11 |
macro (test_output) |
| 12 |
if (BUILD_OUTPUT STREQUAL EXPECTED_LINES ) |
| 13 |
message("Build OK") |
| 14 |
else() |
| 15 |
message("BUILD_OUTPUT") |
| 16 |
foreach(Line IN LISTS BUILD_OUTPUT) |
| 17 |
message("${Line}") |
| 18 |
endforeach() |
| 19 |
message("EXPECTED_LINES") |
| 20 |
foreach(Line IN LISTS EXPECTED_LINES) |
| 21 |
message("${Line}") |
| 22 |
endforeach() |
| 23 |
message(SEND_ERROR "Build KO") |
| 24 |
endif() |
| 25 |
endmacro() |
| 26 |
|
| 27 |
message("Copy project") |
| 28 |
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt.in |
| 29 |
${CMAKE_CURRENT_BINARY_DIR}/src/CMakeLists.txt COPYONLY) |
| 30 |
|
| 31 |
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/exe1.c |
| 32 |
${CMAKE_CURRENT_SOURCE_DIR}/lib1.c |
| 33 |
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/src |
| 34 |
) |
| 35 |
|
| 36 |
message("Building ALL target") |
| 37 |
try_compile(RESULT |
| 38 |
${CMAKE_CURRENT_BINARY_DIR}/build |
| 39 |
${CMAKE_CURRENT_BINARY_DIR}/src |
| 40 |
test |
| 41 |
CMAKE_FLAGS |
| 42 |
-DCMAKE_EXE_LINKER_FLAGS=${CMAKE_EXE_LINKER_FLAGS} |
| 43 |
OUTPUT_VARIABLE BUILD_OUTPUT) |
| 44 |
|
| 45 |
message("Output from build:\n${BUILD_OUTPUT}") |
| 46 |
|
| 47 |
#filter outputs |
| 48 |
string(REPLACE "\r" "" BUILD_OUTPUT "${BUILD_OUTPUT}") |
| 49 |
string(REPLACE "\n" ";" BUILD_OUTPUT "${BUILD_OUTPUT}") |
| 50 |
list(FILTER BUILD_OUTPUT INCLUDE REGEX "^.*CT:") |
| 51 |
|
| 52 |
unset(EXPECTED_LINES) |
| 53 |
list(APPEND EXPECTED_LINES "CT: Processing target_empty_prebuild") |
| 54 |
list(APPEND EXPECTED_LINES "CT: Processing target_empty_postbuild") |
| 55 |
list(APPEND EXPECTED_LINES "CT: Processing target_cmd") |
| 56 |
list(APPEND EXPECTED_LINES "CT: Processing target_cmd_prebuild") |
| 57 |
list(APPEND EXPECTED_LINES "CT: Processing target_cmd_postbuild") |
| 58 |
|
| 59 |
test_output() |
| 60 |
|
| 61 |
message("Building target_update_files target") |
| 62 |
try_compile(RESULT |
| 63 |
${CMAKE_CURRENT_BINARY_DIR}/build |
| 64 |
${CMAKE_CURRENT_BINARY_DIR}/src |
| 65 |
test target_update_files |
| 66 |
CMAKE_FLAGS |
| 67 |
-DCMAKE_EXE_LINKER_FLAGS=${CMAKE_EXE_LINKER_FLAGS} |
| 68 |
OUTPUT_VARIABLE BUILD_OUTPUT) |
| 69 |
|
| 70 |
message("Output from build:\n${BUILD_OUTPUT}") |
| 71 |
|
| 72 |
#filter outputs |
| 73 |
string(REPLACE "\r" "" BUILD_OUTPUT "${BUILD_OUTPUT}") |
| 74 |
string(REPLACE "\n" ";" BUILD_OUTPUT "${BUILD_OUTPUT}") |
| 75 |
list(FILTER BUILD_OUTPUT INCLUDE REGEX "^.*CT:") |
| 76 |
|
| 77 |
unset(EXPECTED_LINES) |
| 78 |
list(APPEND EXPECTED_LINES "CT: Processing target_empty_prebuild") |
| 79 |
list(APPEND EXPECTED_LINES "CT: Processing target_empty_postbuild") |
| 80 |
list(APPEND EXPECTED_LINES "CT: generate C file another_file") |
| 81 |
list(APPEND EXPECTED_LINES "CT: generate text file dependsA") |
| 82 |
list(APPEND EXPECTED_LINES "CT: generate text file out_of_order_dep") |
| 83 |
list(APPEND EXPECTED_LINES "CT: generate text files A, B, and C") |
| 84 |
list(APPEND EXPECTED_LINES "CT: Processing target_update_files") |
| 85 |
|
| 86 |
test_output() |
| 87 |
|
| 88 |
message("Rerun target_update_files target") |
| 89 |
try_compile(RESULT |
| 90 |
${CMAKE_CURRENT_BINARY_DIR}/build |
| 91 |
${CMAKE_CURRENT_BINARY_DIR}/src |
| 92 |
test target_update_files |
| 93 |
CMAKE_FLAGS |
| 94 |
-DCMAKE_EXE_LINKER_FLAGS=${CMAKE_EXE_LINKER_FLAGS} |
| 95 |
OUTPUT_VARIABLE BUILD_OUTPUT) |
| 96 |
|
| 97 |
message("Output from build:\n${BUILD_OUTPUT}") |
| 98 |
|
| 99 |
#filter outputs |
| 100 |
string(REPLACE "\r" "" BUILD_OUTPUT "${BUILD_OUTPUT}") |
| 101 |
string(REPLACE "\n" ";" BUILD_OUTPUT "${BUILD_OUTPUT}") |
| 102 |
list(FILTER BUILD_OUTPUT INCLUDE REGEX "^.*CT:") |
| 103 |
|
| 104 |
unset(EXPECTED_LINES) |
| 105 |
list(APPEND EXPECTED_LINES "CT: Processing target_empty_prebuild") |
| 106 |
list(APPEND EXPECTED_LINES "CT: Processing target_empty_postbuild") |
| 107 |
list(APPEND EXPECTED_LINES "CT: generate text files A, B, and C") |
| 108 |
list(APPEND EXPECTED_LINES "CT: Processing target_update_files") |
| 109 |
|
| 110 |
test_output() |