From 336fced3634f438f81e0d435ad99658688d1cf71 Mon Sep 17 00:00:00 2001 From: Paul Solt Date: Tue, 29 Apr 2025 12:32:29 -0400 Subject: [PATCH] Adds Swift Package Manager support and removes Cocoapods. --- .gitignore | 1 + Package.swift | 60 ++++++++++++++++++++++++++++++++++++++++++++ src/module.modulemap | 7 ++++++ 3 files changed, 68 insertions(+) create mode 100644 Package.swift create mode 100644 src/module.modulemap diff --git a/.gitignore b/.gitignore index 25ccba9281..08a10aaa52 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,7 @@ build.local.sh /.vs* /*build* /nbproject +/.swiftpm # Autotools autom4te.cache diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000000..80e639e3c3 --- /dev/null +++ b/Package.swift @@ -0,0 +1,60 @@ +// swift-tools-version: 5.10 + +import PackageDescription + +/// Cocoapods to SPM Notes: +/// My goal is to to minimal changes to support SPM since this is a fork of OSGeo/PROJ. +/// +/// * Creating a custom module.modulemap seems to fix build issues when using the proj.h header +/// * The public interface is C for the proj.h API we use, so we don't need to use the C++ headers exposed +/// * The C++ header search paths are added so under the hood we can find the headers. +/// * The 9.4_release_spm does not include proj.db, since with Bundles, we need to load resources in the +/// package that requires it. So projections-ios loads the proj.db from it's own bundle. (In Cocoapods you could +/// reach into other bundles, but not with SPM) +/// * Potentially the 9.6_release_spm can provided proj.db in source, but I haven't figured how that integrates. +/// * CMake autogenerates some files that need to be added like "proj_config.h" (9.6 has more autogenerated files) + +let package = Package( + name: "proj", + platforms: [ + .iOS(.v13), .macOS(.v12) + ], + products: [ + .library( + name: "proj", + type: .static, + targets: ["proj"] + ), + ], + targets: [ + .target( + name: "proj", + path: "src", + exclude: [ + "apps", + "tests", + "CMakeLists.txt", + "lib_proj.cmake", + "check_md5sum.cmake", + "generate_wkt_parser.cmake", + "general_doc.dox", + "wkt1_grammar.y", + "wkt2_grammar.y", + ], + resources: [ + ], + publicHeadersPath: ".", // The C header files are mixed with src files, we use a modulemap.module to load "proj.h" + cxxSettings: [ + .headerSearchPath("../include"), + .headerSearchPath("../include/proj"), + .headerSearchPath("../include/proj/internal"), + .headerSearchPath("../include/proj/internal/vendor/nlohmann"), + ], + linkerSettings: [ + .linkedLibrary("c++"), + .linkedLibrary("sqlite3"), + ] + ) + ], + cxxLanguageStandard: .cxx11 +) diff --git a/src/module.modulemap b/src/module.modulemap new file mode 100644 index 0000000000..e7884770cb --- /dev/null +++ b/src/module.modulemap @@ -0,0 +1,7 @@ +module proj { + // Include the header, but not as an `umbrella header "proj.h"`, since it doesn't include all headers in src folder + // The src directory has a C header API and the implementation is C++ under the hood. + header "proj.h" + + export * +}