cmake/Tests/SwiftOnly/CMakeLists.txt

57 lines
1.8 KiB
CMake
Raw Normal View History

2015-11-17 17:22:37 +01:00
cmake_minimum_required(VERSION 3.3)
2021-09-14 00:13:48 +02:00
if(POLICY CMP0126)
cmake_policy(SET CMP0126 NEW)
endif()
2020-08-30 11:54:41 +02:00
# NOTE: Force the Release mode configuration as there are some issues with the
# debug information handling on macOS on certain Xcode builds.
if(NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build" FORCE)
endif()
# NOTE: enable shared libraries by default. Older Xcode releases do not play
# well with static libraries, and Windows does not currently support static
# libraries in Swift.
set(BUILD_SHARED_LIBS YES)
2015-11-17 17:22:37 +01:00
project(SwiftOnly Swift)
2019-11-11 23:01:05 +01:00
if(NOT XCODE_VERSION VERSION_LESS 10.2)
set(CMAKE_Swift_LANGUAGE_VERSION 5.0)
elseif(NOT XCODE_VERSION VERSION_LESS 8.0)
2016-10-30 18:24:19 +01:00
set(CMAKE_Swift_LANGUAGE_VERSION 3.0)
endif()
2022-11-16 20:14:03 +01:00
add_subdirectory(SubA)
add_subdirectory(SubB)
2020-08-30 11:54:41 +02:00
set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)
2015-11-17 17:22:37 +01:00
add_executable(SwiftOnly main.swift)
2022-11-16 20:14:03 +01:00
target_compile_definitions(SwiftOnly PRIVATE SWIFTONLY)
2019-11-11 23:01:05 +01:00
2020-08-30 11:54:41 +02:00
add_library(L L.swift)
add_library(M M.swift)
target_link_libraries(M PUBLIC
L)
add_library(N N.swift)
target_link_libraries(N PUBLIC
M)
2019-11-11 23:01:05 +01:00
# Dummy to make sure generation works with such targets.
add_library(SwiftIface INTERFACE)
2020-08-30 11:54:41 +02:00
target_link_libraries(SwiftOnly PRIVATE SwiftIface)
2023-05-23 16:38:00 +02:00
# @_alwaysEmitIntoClient ensures that the function body is inserted into the
# swiftmodule instead of as a symbol in the binary itself. I'm doing this to
# avoid having to link the executable. There are some flags required in order to
# link an executable into a library that I didn't see CMake emitting for Swift
# on macOS. AEIC is the easiest workaround that still tests this functionality.
# Unfortunately, AEIC was only added recently (~Swift 5.2), so we need to check
# that it is available before using it.
if(CMAKE_Swift_COMPILER_VERSION VERSION_GREATER_EQUAL 5.2)
add_subdirectory("SwiftPlugin")
endif()