From 15e5f05e7d8e020588f8d1a21280954c0d8701a6 Mon Sep 17 00:00:00 2001 From: Jean-Philip Desjardins Date: Fri, 3 Sep 2021 13:43:00 -0400 Subject: [PATCH] Add CMake integration (#1) * Add CMake config. * Set proper Swift version. * Make module usable through Swift header. * Add some comments in CMake project. * Add CMake integration steps in README. --- CMakeLists.txt | 38 ++++++++++++++++++++++++++++++++ README.md | 15 +++++++++++++ Sources/CAltKit/module.modulemap | 4 ++++ 3 files changed, 57 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 Sources/CAltKit/module.modulemap diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..d28050e --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,38 @@ +cmake_minimum_required(VERSION 3.15.1) + +project(AltKit LANGUAGES C Swift) + +add_library(CAltKit + Sources/CAltKit/NSError+ALTServerError.h + Sources/CAltKit/NSError+ALTServerError.m +) + +add_library(AltKit + Sources/AltKit/Extensions/ALTServerError+Conveniences.swift + Sources/AltKit/Extensions/Result+Conveniences.swift + + Sources/AltKit/Server/Connection.swift + Sources/AltKit/Server/NetworkConnection.swift + Sources/AltKit/Server/Server.swift + Sources/AltKit/Server/ServerConnection.swift + Sources/AltKit/Server/ServerManager.swift + Sources/AltKit/Server/ServerProtocol.swift + + Sources/AltKit/Types/CodableServerError.swift +) + +target_link_libraries(AltKit PRIVATE CAltKit) + +set_property(TARGET AltKit PROPERTY XCODE_ATTRIBUTE_SWIFT_VERSION "5.0") + +# Make CAltKit's modulemap available to AltKit +set_property(TARGET AltKit PROPERTY XCODE_ATTRIBUTE_SWIFT_INCLUDE_PATHS "${CMAKE_CURRENT_SOURCE_DIR}/Sources/CAltKit") + +# Add binary dir to interface include path to make Swift header accessible to targets using AltKit +target_include_directories(AltKit INTERFACE ${CMAKE_CURRENT_BINARY_DIR}) + +# Copy generated Swift header to binary dir +add_custom_command(TARGET AltKit + POST_BUILD + COMMAND cp $DERIVED_SOURCES_DIR/AltKit-Swift.h ${CMAKE_CURRENT_BINARY_DIR} +) diff --git a/README.md b/README.md index a94c2c2..6344989 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,21 @@ Finally, right-click on your app's `Info.plist`, select "Open As > Source Code", [Your app] uses the local network to find and communicate with AltServer. ``` +### CMake Integration + +Note: CMake 3.15 is required for the integration. The integration only works with the Xcode generator. + +Steps: +- Add the AltKit CMake project to your CMake project using `add_subdirectory`. +- Add Swift to your project's supported languages. (ex.: `project(projName LANGUAGES C Swift)`) + +If you're using `add_compile_options` or `target_compile_options` and the Swift compiler complains about the option not being supported, it's possible to use CMake's generator expressions to limit the options to non-Swift source files. + +Example: +``` +add_compile_options($<$>:-fPIC>) +``` + ## Usage ### Swift diff --git a/Sources/CAltKit/module.modulemap b/Sources/CAltKit/module.modulemap new file mode 100644 index 0000000..e52c084 --- /dev/null +++ b/Sources/CAltKit/module.modulemap @@ -0,0 +1,4 @@ +module CAltKit { + umbrella "./include" + export * +}