Skip to content

Commit

Permalink
Reduces dependencies on APPLE platforms, unless advanced flag set.
Browse files Browse the repository at this point in the history
  • Loading branch information
dabrahams committed Feb 17, 2024
1 parent 9a25c15 commit 3be8d62
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 54 deletions.
38 changes: 21 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,31 @@ enable_testing()

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

option(SwiftCMakeXCTesting_FORCE_BUILD_GenerateXCTestMain
"Force-build generate-xctest-main on platforms where it's not needed." OFF)
mark_as_advanced(SwiftCMakeXCTesting_FORCE_BUILD_GenerateXCTestMain)

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



#
# Local targets
#

add_executable(generate-xctest-main Sources/GenerateXCTestMain.swift)
target_link_libraries(generate-xctest-main
ArgumentParser
SwiftSyntax
SwiftSyntaxBuilder
SwiftOperators
SwiftParser
SwiftParserDiagnostics
)
# Needed where @main is used.
target_compile_options(generate-xctest-main PRIVATE -parse-as-library)
if(NOT APPLE OR SwiftCMakeXCTesting_FORCE_BUILD_GenerateXCTestMain)
find_package(ArgumentParser REQUIRED)
find_package(SwiftSyntax REQUIRED)

add_executable(generate-xctest-main Sources/GenerateXCTestMain.swift)
target_link_libraries(generate-xctest-main
ArgumentParser
SwiftSyntax
SwiftSyntaxBuilder
SwiftOperators
SwiftParser
SwiftParserDiagnostics
)

# Needed where @main is used.
target_compile_options(generate-xctest-main PRIVATE -parse-as-library)
endif()

if(ENABLE_TESTING)
include(${PROJECT_SOURCE_DIR}/cmake/modules/SwiftCMakeXCTesting.cmake)
Expand Down
77 changes: 40 additions & 37 deletions cmake/modules/SwiftCMakeXCTesting_FetchDependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,44 @@

include(FetchContent)

block()
set(FETCHCONTENT_TRY_FIND_PACKAGE_MODE NEVER)

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

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

# 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()

block()
set(BUILD_EXAMPLES NO)
set(BUILD_TESTING NO)

FetchContent_MakeAvailable(ArgumentParser SwiftSyntax)
endblock()

# Suppress noisy warnings from dependencies.
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)
if(NOT APPLE OR SwiftCMakeXCTesting_FORCE_BUILD_GenerateXCTestMain)

block()
set(FETCHCONTENT_TRY_FIND_PACKAGE_MODE NEVER)

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

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

# 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()

block()
set(BUILD_EXAMPLES NO)
set(BUILD_TESTING NO)

FetchContent_MakeAvailable(ArgumentParser SwiftSyntax)
endblock()

# Suppress noisy warnings from dependencies.
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)

endif()

0 comments on commit 3be8d62

Please sign in to comment.