Skip to content

Commit 18fa490

Browse files
authored
Merge pull request #78827 from andrurogerz/swift-inspect-cmake
[swift-inspect] use CMake FetchContent to fetch ArgumentParser when not provided
2 parents 40185a4 + 92dea69 commit 18fa490

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

tools/swift-inspect/CMakeLists.txt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ cmake_minimum_required(VERSION 3.28)
33
project(swift-inspect
44
LANGUAGES C CXX Swift)
55

6+
include(FetchContent)
7+
68
# Set C++ standard
79
set(CMAKE_CXX_STANDARD 17)
810
set(CMAKE_CXX_STANDARD_REQUIRED ON)
@@ -12,7 +14,19 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
1214
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
1315
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
1416

15-
find_package(ArgumentParser CONFIG REQUIRED)
17+
FetchContent_Declare(ArgumentParser
18+
GIT_REPOSITORY https://github.com/apple/swift-argument-parser
19+
GIT_TAG 1.5.0
20+
GIT_SHALLOW TRUE
21+
EXCLUDE_FROM_ALL
22+
FIND_PACKAGE_ARGS CONFIG)
23+
24+
block(SCOPE_FOR VARIABLES)
25+
set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "Build as a shared library")
26+
set(BUILD_TESTING OFF CACHE INTERNAL "Skip building ArgumentParser tests")
27+
set(BUILD_EXAMPLES OFF CACHE INTERNAL "Skip building ArgumentParser examples")
28+
FetchContent_MakeAvailable(ArgumentParser)
29+
endblock()
1630

1731
add_library(SymbolicationShims INTERFACE)
1832
target_include_directories(SymbolicationShims INTERFACE

tools/swift-inspect/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ let package = Package(
5050

5151
if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
5252
package.dependencies += [
53-
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.2.2"),
53+
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.5.0"),
5454
]
5555
} else {
5656
package.dependencies += [.package(path: "../../../swift-argument-parser")]

tools/swift-inspect/README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ swift build --triple %ANDROID_ARCH%-unknown-linux-android%ANDROID_API_LEVEL% ^
5050
In order to build on Windows with CMake, some additional parameters must be passed to the build tool to locate the necessary Swift modules.
5151

5252
~~~
53-
cmake -B out -G Ninja -S . -D ArgumentParser_DIR=... -D CMAKE_Swift_FLAGS="-Xcc -I%SDKROOT%\usr\include\swift\SwiftRemoteMirror"
53+
cmake -B out -G Ninja -S . -D CMAKE_Swift_FLAGS="-Xcc -I%SDKROOT%\usr\include\swift\SwiftRemoteMirror"
5454
~~~
5555

5656
In order to build on Linux with CMake, some additional parameters must be passed to the build tool to locate the necessary Swift modules.
5757

5858
~~~
59-
cmake -B out -G Ninja -S . -D ArgumentParser_DIR=... -D CMAKE_Swift_FLAGS="-Xcc -I$(git rev-parse --show-toplevel)/include/swift/SwiftRemoteMirror"
59+
cmake -B out -G Ninja -S . -D CMAKE_Swift_FLAGS="-Xcc -I$(git rev-parse --show-toplevel)/include/swift/SwiftRemoteMirror"
6060
~~~
6161

6262
In order to build for Android with CMake on Windows, some additiona parameters must be passed to the build tool to locate the necessary Swift modules.
@@ -75,12 +75,14 @@ cmake -B build -S . -G Ninja ^
7575
-D CMAKE_SYSTEM_VERSION=%ANDROID_API_LEVEL% ^
7676
-D CMAKE_Swift_COMPILER_TARGET=%ANDROID_ARCH%-unknown-linux-android%ANDROID_API_LEVEL% ^
7777
-D CMAKE_Swift_FLAGS="-sdk %SDKROOT_ANDROID% -L%ANDROID_NDK_ROOT%\toolchains\llvm\prebuilt\windows-x86_64\lib\clang\%ANDROID_CLANG_VERSION%\lib\linux\%ANDROID_ARCH% -Xclang-linker -resource-dir -Xclang-linker %ANDROID_NDK_ROOT%\toolchains\llvm\prebuilt\windows-x86_64\lib\clang\%ANDROID_CLANG_VERSION% -Xcc -I%SDKROOT_ANDROID%\usr\include -I%SDKROOT_ANDROID%\usr\include\swift\SwiftRemoteMirror" ^
78-
-D ArgumentParser_DIR=...
7978
cmake --build build
8079
~~~
8180

82-
Building with CMake requires a local copy of [swift-argument-parser](https://github.com/apple/swift-argument-parser) built with CMake.
83-
The `ArumentParser_DIR=` definition must refer to the `cmake/modules` sub-directory of the swift-argument-parser build output directory.
81+
Building with CMake can use a local copy of [swift-argument-parser](https://github.com/apple/swift-argument-parser) built with CMake.
82+
The `ArgumentParser_DIR=` definition must refer to the `cmake/modules` sub-directory of the swift-argument-parser build output directory.
83+
~~~cmd
84+
cmake -b out -G Ninja -S . -D ArgumentParser_DIR=S:\swift-argument-parser\build\cmake\modules
85+
~~~
8486

8587
### Using
8688

0 commit comments

Comments
 (0)