Skip to content

Commit

Permalink
Separate dependency fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
dabrahams committed Feb 16, 2024
1 parent 4ef6c4d commit 2e8a592
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 38 deletions.
43 changes: 5 additions & 38 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
cmake_minimum_required(VERSION 3.26)

#
# Standard project boilerplate
#
project(SwiftCMakeXCTesting
VERSION 0.1.0
DESCRIPTION "Cross-platform support for using XCTest in Swift projects"
Expand All @@ -8,49 +11,13 @@ project(SwiftCMakeXCTesting
)
enable_testing()

list(PREPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules)

if (PROJECT_IS_TOP_LEVEL)
include(${PROJECT_SOURCE_DIR}/cmake/TopLevelDefaults.cmake)
endif()

#
# Dependencies
#

include(FetchContent)

set(_XCTESTDISCOVERY_SAVED_BUILD_TESTING ${BUILD_TESTING})
set(_XCTESTDISCOVERY_SAVED_BUILD_EXAMPLES ${BUILD_EXAMPLES})
set(_XCTESTDISCOVERY_VENDOR_DEPENDENCIES)

set(BUILD_EXAMPLES NO)
set(BUILD_TESTING NO)

if("${SWIFT_HOST_MODULE_TRIPLE}" STREQUAL "")
execute_process(COMMAND ${CMAKE_Swift_COMPILER} -print-target-info OUTPUT_VARIABLE target-info)
string(JSON SWIFT_HOST_MODULE_TRIPLE GET ${target-info} target moduleTriple)
endif()

FetchContent_Declare(SwiftSyntax
GIT_REPOSITORY https://github.com/apple/swift-syntax.git
GIT_TAG main
FIND_PACKAGE_ARGS CONFIG
)

FetchContent_Declare(ArgumentParser
GIT_REPOSITORY https://github.com/apple/swift-argument-parser.git
GIT_TAG 1.3.0
FIND_PACKAGE_ARGS CONFIG
)

FetchContent_MakeAvailable(ArgumentParser SwiftSyntax)
target_compile_options(SwiftCompilerPluginMessageHandling PRIVATE -suppress-warnings)
target_compile_options(SwiftParser PRIVATE -suppress-warnings)
target_compile_options(SwiftParserDiagnostics PRIVATE -suppress-warnings)
target_compile_options(SwiftSyntaxMacroExpansion PRIVATE -suppress-warnings)
target_compile_options(SwiftOperators PRIVATE -suppress-warnings)

set(BUILD_TESTING ${_XCTESTDISCOVERY_SAVED_BUILD_TESTING})
set(BUILD_EXAMPLES ${_XCTESTDISCOVERY_SAVED_BUILD_EXAMPLES})

#
# Local targets
Expand Down
2 changes: 2 additions & 0 deletions cmake/TopLevelDefaults.cmake
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# commands used to create an easy development environment when
# building this project directly (not as a dependency).

include(SwiftCMakeXCTesting_FetchDependencies)
40 changes: 40 additions & 0 deletions cmake/modules/SwiftCMakeXCTesting_FetchDependencies.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Fetches dependencies for SwiftCMakeXCTesting.
include(FetchContent)

# See https://github.com/apple/swift-syntax/pull/2454, which will hopefully make this clause
# unnecessary. Without it CMake will fatal error when loading SwiftSyntax on some platforms.
if("${SWIFT_HOST_MODULE_TRIPLE}" STREQUAL "")
execute_process(COMMAND ${CMAKE_Swift_COMPILER}
-print-target-info OUTPUT_VARIABLE target-info)
string(JSON SWIFT_HOST_MODULE_TRIPLE GET ${target-info} target moduleTriple)
endif()

FetchContent_Declare(SwiftSyntax
GIT_REPOSITORY https://github.com/apple/swift-syntax.git
GIT_TAG main
FIND_PACKAGE_ARGS CONFIG
)

FetchContent_Declare(ArgumentParser
GIT_REPOSITORY https://github.com/apple/swift-argument-parser.git
GIT_TAG 1.3.0
FIND_PACKAGE_ARGS CONFIG
)

set(_XCTESTDISCOVERY_SAVED_BUILD_TESTING ${BUILD_TESTING})
set(_XCTESTDISCOVERY_SAVED_BUILD_EXAMPLES ${BUILD_EXAMPLES})

set(BUILD_EXAMPLES NO)
set(BUILD_TESTING NO)

FetchContent_MakeAvailable(ArgumentParser SwiftSyntax)

target_compile_options(SwiftCompilerPluginMessageHandling PRIVATE -suppress-warnings)
target_compile_options(SwiftParser PRIVATE -suppress-warnings)
target_compile_options(SwiftParserDiagnostics PRIVATE -suppress-warnings)
target_compile_options(SwiftSyntaxMacroExpansion PRIVATE -suppress-warnings)
target_compile_options(SwiftOperators PRIVATE -suppress-warnings)


set(BUILD_TESTING ${_XCTESTDISCOVERY_SAVED_BUILD_TESTING})
set(BUILD_EXAMPLES ${_XCTESTDISCOVERY_SAVED_BUILD_EXAMPLES})

0 comments on commit 2e8a592

Please sign in to comment.