|
| 1 | +# This source file is part of the Swift open source project |
| 2 | +# |
| 3 | +# Copyright (c) 2025 Apple Inc. and the Swift project authors. |
| 4 | +# Licensed under Apache License v2.0 with Runtime Library Exception |
| 5 | +# |
| 6 | +# See https://swift.org/LICENSE.txt for license information |
| 7 | +# ============================================================================= |
| 8 | +# This file configure testing that each project configures and builds with |
| 9 | +# ctest. |
| 10 | +# It is not meant for configuring and building each project. |
| 11 | + |
| 12 | +cmake_minimum_required(VERSION 3.22) |
| 13 | +project(SwiftCMakeExamples LANGUAGES NONE) |
| 14 | + |
| 15 | +include(CTest) |
| 16 | + |
| 17 | +function(add_cmake_test name source_dir) |
| 18 | + cmake_parse_arguments(PARSE_ARGV 2 ARG "" "CMAKE_VERSION" "" ) |
| 19 | + if(NOT ARG_CMAKE_VERSION) |
| 20 | + set(ARG_CMAKE_VERSION 3.22) |
| 21 | + endif() |
| 22 | + |
| 23 | + if(${CMAKE_VERSION} VERSION_LESS ${ARG_CMAKE_VERSION}) |
| 24 | + message(STATUS "Skipping ${name} -- CMake version too old: ${CMAKE_VERSION} < ${ARG_CMAKE_VERSION}") |
| 25 | + return() |
| 26 | + endif() |
| 27 | + |
| 28 | + add_test(NAME "${name}-configure" |
| 29 | + COMMAND ${CMAKE_COMMAND} |
| 30 | + -G ${CMAKE_GENERATOR} |
| 31 | + -B "${name}-build" |
| 32 | + -S "${CMAKE_CURRENT_SOURCE_DIR}/${source_dir}" |
| 33 | + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}) |
| 34 | + add_test(NAME "${name}-build" COMMAND |
| 35 | + ${CMAKE_COMMAND} --build "${name}-build") |
| 36 | + set_tests_properties("${name}-build" PROPERTIES DEPENDS "${name}-configure") |
| 37 | +endfunction() |
| 38 | + |
| 39 | +add_cmake_test(SingleExecutable 1_single_executable) |
| 40 | +add_cmake_test(ExecutableLibrary 2_executable_library) |
| 41 | +add_cmake_test(BidirectionalCxxInterop 3_bidirectional_cxx_interop |
| 42 | + CMAKE_VERSION 3.26) |
| 43 | +add_cmake_test(SwiftMacros 4_swift_macros) |
0 commit comments