Skip to content

Commit

Permalink
build: add a CMake based build for Windows (apple#44)
Browse files Browse the repository at this point in the history
Since swift-package-manager doesn't work on Windows yet, add a CMake
based build system.
  • Loading branch information
compnerd authored Mar 2, 2020
1 parent 49edf19 commit b9eb417
Show file tree
Hide file tree
Showing 12 changed files with 131 additions and 0 deletions.
24 changes: 24 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
cmake_minimum_required(VERSION 3.16.0)

project(swift-argument-parser
LANGUAGES Swift)

option(BUILD_EXAMPLES "Build Example Programs" TRUE)

include(CTest)

set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)

find_package(Foundation QUIET)
find_package(XCTest QUIET)

add_subdirectory(Sources)
if(BUILD_EXAMPLES)
add_subdirectory(Examples)
endif()
if(BUILD_TESTING)
add_subdirectory(Tests)
endif()

export(TARGETS ArgumentParser
FILE swift-argument-parser-config.cmake)
3 changes: 3 additions & 0 deletions Examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
add_subdirectory(math)
add_subdirectory(repeat)
add_subdirectory(roll)
4 changes: 4 additions & 0 deletions Examples/math/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
add_executable(math
main.swift)
target_link_libraries(math PRIVATE
ArgumentParser)
4 changes: 4 additions & 0 deletions Examples/repeat/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
add_executable(repeat
main.swift)
target_link_libraries(repeat PRIVATE
ArgumentParser)
5 changes: 5 additions & 0 deletions Examples/roll/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
add_executable(roll
main.swift
SplitMix64.swift)
target_link_libraries(roll PRIVATE
ArgumentParser)
39 changes: 39 additions & 0 deletions Sources/ArgumentParser/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
add_library(ArgumentParser
"Parsable Properties/Argument.swift"
"Parsable Properties/ArgumentHelp.swift"
"Parsable Properties/Flag.swift"
"Parsable Properties/NameSpecification.swift"
"Parsable Properties/Option.swift"
"Parsable Properties/OptionGroup.swift"
"Parsable Properties/ValidationError.swift"

"Parsable Types/CommandConfiguration.swift"
"Parsable Types/ExpressibleByArgument.swift"
"Parsable Types/ParsableArguments.swift"
"Parsable Types/ParsableCommand.swift"

Parsing/ArgumentDecoder.swift
Parsing/ArgumentDefinition.swift
Parsing/ArgumentSet.swift
Parsing/ArgumentSetSequence.swift
Parsing/CommandParser.swift
Parsing/InputOrigin.swift
Parsing/Name.swift
Parsing/Parsed.swift
Parsing/ParsedValues.swift
Parsing/ParserError.swift
Parsing/SplitArguments.swift

Usage/HelpCommand.swift
Usage/HelpGenerator.swift
Usage/MessageInfo.swift
Usage/UsageGenerator.swift

Utilities/StringExtensions.swift
Utilities/Tree.swift)
set_target_properties(ArgumentParser PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
target_compile_options(ArgumentParser PRIVATE
$<$<BOOL:${BUILD_TESTING}>:-enable-testing>)
target_link_libraries(ArgumentParser PRIVATE
Foundation)
4 changes: 4 additions & 0 deletions Sources/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
add_subdirectory(ArgumentParser)
if(BUILD_TESTING)
add_subdirectory(TestHelpers)
endif()
8 changes: 8 additions & 0 deletions Sources/TestHelpers/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
add_library(TestHelpers
StringHelpers.swift
TestHelpers.swift)
set_target_properties(TestHelpers PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
target_link_libraries(TestHelpers PUBLIC
ArgumentParser
XCTest)
2 changes: 2 additions & 0 deletions Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_subdirectory(EndToEndTests)
add_subdirectory(UnitTests)
19 changes: 19 additions & 0 deletions Tests/EndToEndTests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
add_library(EndToEndTests
CustomParsingEndToEndTests.swift
DefaultsEndToEndTests.swift
EnumEndToEndTests.swift
FlagsEndToEndTests.swift
LongNameWithShortDashEndToEndTests.swift
NestedCommandEndToEndTests.swift
OptionalEndToEndTests.swift
OptionGroupEndToEndTests.swift
PositionalEndToEndTests.swift
RawRepresentableEndToEndTests.swift
RepeatingEndToEndTests.swift
ShortNameEndToEndTests.swift
SimpleEndToEndTests.swift
SingleValueParsingStrategyTests.swift
SubcommandEndToEndTests.swift
ValidationEndToEndTests.swift)
target_link_libraries(EndToEndTests PUBLIC
TestHelpers)
8 changes: 8 additions & 0 deletions Tests/PackageManagerTests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
add_library(PackageManagerTests
HelpTests.swift
PackageManager/Clean.swift
PackageManager/Config.swift
PackageManager/Describe.swift
PackageManager/GenerateXcodeProject.swift
PackageManager/Options.swift
Tests.swift)
11 changes: 11 additions & 0 deletions Tests/UnitTests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
add_library(UnitTests
ErrorMessageTests.swift
HelpGenerationTests.swift
NameSpecificationTests.swift
SplitArgumentTests.swift
StringWrappingTests.swift
TreeTests.swift
UsageGenerationTests.swift)
target_link_libraries(UnitTests PRIVATE
ArgumentParser
TestHelpers)

0 comments on commit b9eb417

Please sign in to comment.