Skip to content

Commit b09235b

Browse files
authored
Allow configuring iOS build with CMake (#3234)
1 parent 7562931 commit b09235b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+696
-954
lines changed

.github/workflows/ios-ci.yml

+18-1
Original file line numberDiff line numberDiff line change
@@ -332,13 +332,30 @@ jobs:
332332
run: |
333333
VERSION=${{ env.version }} COCOAPODS_TRUNK_TOKEN=${{ secrets.COCOAPODS_PASSWORD }} pod trunk push MapLibre.podspec
334334
335+
ios-build-cmake:
336+
needs: pre_job
337+
runs-on: macos-latest
338+
if: needs.pre_job.outputs.should_skip != 'true'
339+
steps:
340+
- uses: actions/checkout@v4
341+
with:
342+
submodules: recursive
343+
fetch-depth: 0
344+
345+
- name: Configure build with CMake
346+
run: cmake --preset ios
347+
348+
- name: Build mbgl-core
349+
run: cmake --build build-ios --target mbgl-core ios-sdk-static app
350+
335351
ios-ci-result:
336352
runs-on: ubuntu-latest
337353
if: needs.pre_job.outputs.should_skip != 'true' && always()
338354
needs:
339355
- pre_job
340356
- ios-build
357+
- ios-build-cmake
341358
steps:
342359
- name: Mark result as failed
343-
if: needs.ios-build.result != 'success'
360+
if: needs.ios-build.result != 'success' || needs.ios-build-cmake.result != 'success'
344361
run: exit 1

.github/workflows/node-ci.yml

+2-11
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ jobs:
167167
if: ${{contains(runner.name, 'GitHub Actions')}}
168168
uses: jwlawson/actions-setup-cmake@v2
169169
with:
170-
cmake-version: '3.29.2'
170+
cmake-version: '3.31'
171171

172172
- name: cmake version
173173
run: |
@@ -204,16 +204,7 @@ jobs:
204204
- name: Configure maplibre-native (MacOS)
205205
if: runner.os == 'MacOS'
206206
run: |
207-
cmake . -B build \
208-
-G Ninja \
209-
-DCMAKE_BUILD_TYPE=${{ env.BUILDTYPE }} \
210-
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
211-
-DMLN_WITH_NODE=ON \
212-
-DMLN_WITH_OPENGL=OFF \
213-
-DMLN_WITH_METAL=ON \
214-
-DMLN_LEGACY_RENDERER=OFF \
215-
-DMLN_DRAWABLE_RENDERER=ON \
216-
-DMLN_WITH_WERROR=OFF
207+
cmake --preset macos-node -DCMAKE_BUILD_TYPE=${{ env.BUILDTYPE }}
217208
218209
- name: Configure maplibre-native (Linux)
219210
if: runner.os == 'Linux'

CMakeLists.txt

+9-4
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ target_compile_options(
8686
$<$<STREQUAL:${MLN_WITH_SANITIZER},undefined>:-fsanitize=float-divide-by-zero,
8787
-fsanitize-blacklist=${UBSAN_BLACKLIST}>
8888
$<$<PLATFORM_ID:iOS>:-fembed-bitcode>
89-
$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<NOT:$<OR:$<BOOL:${MLN_WITH_RTTI}>,$<CXX_COMPILER_ID:MSVC>>>>:-fno-rtti>
89+
$<$<AND:$<OR:$<COMPILE_LANGUAGE:CXX>,$<COMPILE_LANGUAGE:OBJCXX>>,$<NOT:$<OR:$<BOOL:${MLN_WITH_RTTI}>,$<CXX_COMPILER_ID:MSVC>>>>:-fno-rtti>
9090
$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<NOT:$<PLATFORM_ID:Windows>>>:-Wall>
9191
$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<NOT:$<PLATFORM_ID:Windows>>>:-Wshadow>
9292
$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<NOT:$<PLATFORM_ID:Windows>>>:-Wextra>
@@ -1268,6 +1268,7 @@ if(MLN_WITH_METAL)
12681268
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/raster.cpp
12691269
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/symbol.cpp
12701270
${PROJECT_SOURCE_DIR}/src/mbgl/shaders/mtl/widevector.cpp
1271+
${PROJECT_SOURCE_DIR}/src/mbgl/style/layers/mtl/custom_layer_render_parameters.cpp
12711272
)
12721273

12731274
find_library(METAL_FRAMEWORK Metal)
@@ -1372,12 +1373,12 @@ endif()
13721373
if(MLN_DRAWABLE_RENDERER)
13731374
list(APPEND
13741375
SRC_FILES
1375-
${PROJECT_SOURCE_DIR}/src/mbgl/style/layers/custom_drawable_layer.cpp
13761376
${PROJECT_SOURCE_DIR}/src/mbgl/layermanager/custom_drawable_layer_factory.cpp
1377-
${PROJECT_SOURCE_DIR}/src/mbgl/style/layers/custom_drawable_layer_impl.cpp
1378-
${PROJECT_SOURCE_DIR}/src/mbgl/style/layers/custom_drawable_layer_impl.hpp
13791377
${PROJECT_SOURCE_DIR}/src/mbgl/renderer/layers/render_custom_drawable_layer.cpp
13801378
${PROJECT_SOURCE_DIR}/src/mbgl/renderer/layers/render_custom_drawable_layer.hpp
1379+
${PROJECT_SOURCE_DIR}/src/mbgl/style/layers/custom_drawable_layer_impl.cpp
1380+
${PROJECT_SOURCE_DIR}/src/mbgl/style/layers/custom_drawable_layer_impl.hpp
1381+
${PROJECT_SOURCE_DIR}/src/mbgl/style/layers/custom_drawable_layer.cpp
13811382
)
13821383
endif()
13831384

@@ -1579,7 +1580,11 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL Android)
15791580
elseif(CMAKE_SYSTEM_NAME STREQUAL Linux)
15801581
include(${PROJECT_SOURCE_DIR}/platform/linux/linux.cmake)
15811582
elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
1583+
include(${PROJECT_SOURCE_DIR}/platform/darwin/darwin.cmake)
15821584
include(${PROJECT_SOURCE_DIR}/platform/macos/macos.cmake)
1585+
elseif(CMAKE_SYSTEM_NAME STREQUAL iOS)
1586+
include(${PROJECT_SOURCE_DIR}/platform/darwin/darwin.cmake)
1587+
include(${PROJECT_SOURCE_DIR}/platform/ios/ios.cmake)
15831588
elseif(WIN32)
15841589
include(${PROJECT_SOURCE_DIR}/platform/windows/windows.cmake)
15851590
else()

CMakePresets.json

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"version": 10,
3+
"cmakeMinimumRequired": {
4+
"major": 3,
5+
"minor": 21,
6+
"patch": 0
7+
},
8+
"configurePresets": [
9+
{
10+
"name": "ios",
11+
"displayName": "iOS",
12+
"generator": "Xcode",
13+
"description": "Create Xcode project for iOS",
14+
"binaryDir": "${sourceDir}/build-ios",
15+
"cacheVariables": {
16+
"CMAKE_SYSTEM_NAME": "iOS",
17+
"CMAKE_CXX_COMPILER_LAUNCHER": "ccache",
18+
"MLN_WITH_METAL": "ON",
19+
"MLN_WITH_OPENGL": "OFF",
20+
"MLN_DRAWABLE_RENDERER": "ON"
21+
}
22+
},
23+
{
24+
"name": "macos",
25+
"displayName": "macOS",
26+
"generator": "Ninja",
27+
"binaryDir": "${sourceDir}/build-macos",
28+
"cacheVariables": {
29+
"CMAKE_SYSTEM_NAME": "Darwin",
30+
"CMAKE_CXX_COMPILER_LAUNCHER": "ccache",
31+
"MLN_WITH_METAL": "ON",
32+
"MLN_WITH_OPENGL": "OFF",
33+
"MLN_DRAWABLE_RENDERER": "ON"
34+
}
35+
},
36+
{
37+
"name": "macos-vulkan",
38+
"displayName": "macOS",
39+
"generator": "Ninja",
40+
"binaryDir": "${sourceDir}/build-macos-vulkan",
41+
"cacheVariables": {
42+
"CMAKE_SYSTEM_NAME": "Darwin",
43+
"CMAKE_CXX_COMPILER_LAUNCHER": "ccache",
44+
"MLN_WITH_VULKAN": "ON",
45+
"MLN_WITH_OPENGL": "OFF",
46+
"MLN_DRAWABLE_RENDERER": "ON"
47+
}
48+
},
49+
{
50+
"name": "macos-node",
51+
"inherits": "macos",
52+
"binaryDir": "${sourceDir}/build",
53+
"cacheVariables": {
54+
"MLN_WITH_NODE": "ON",
55+
"MLN_WITH_WERROR": "OFF"
56+
}
57+
}
58+
]
59+
}

docs/mdbook/src/ios/README.md

+16-2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,20 @@ bazel run //platform/ios:App --//:renderer=metal
7373

7474
You can also build targets from the command line. For example, if you want to build your own XCFramework, see the 'Build XCFramework' step in the [iOS CI workflow](../../.github/workflows/ios-ci.yml).
7575

76-
## Swift App
76+
## CMake
7777

78-
There is also an example app built with Swift instead of Objective-C. The target is called `MapLibreApp` and the source code lives in `platform/ios/app-swift`.
78+
It is also possible to generate an Xcode project using CMake. As of February 2025, targets `mbgl-core`, `ios-sdk-static` and `app` (Objective-C development app) are supported.
79+
80+
```
81+
cmake --preset ios -DDEVELOPMENT_TEAM_ID=YOUR_TEAM_ID
82+
xed build-ios/MapLibre\ Native.xcodeproj
83+
```
84+
85+
## Distribution
86+
87+
MapLibre iOS is distributed as an XCFramework via the [maplibre/maplibre-gl-native-distribution](https://github.com/maplibre/maplibre-gl-native-distribution) repository. See [Release MapLibre iOS](./release.md) for the release process. Refer to the [`ios-ci.yml`](https://github.com/maplibre/maplibre-native/blob/main/.github/workflows/ios-ci.yml) workflow for an up-to-date recipe for building an XCFramework. As of February 2025 we use:
88+
89+
```
90+
bazel build --compilation_mode=opt --features=dead_strip,thin_lto --objc_enable_binary_stripping \
91+
--apple_generate_dsym --output_groups=+dsyms --//:renderer=metal //platform/ios:MapLibre.dynamic --embed_label=maplibre_ios_"$(cat VERSION)"
92+
```

docs/mdbook/src/platforms.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,12 @@ In 2023 we co-opted Bazel as a build tool (generator), mostly due to it having b
4848
| Platform | CMake | Bazel |
4949
|---|---|---|
5050
| Android | ✅ (via Gradle) ||
51-
| iOS | ||
51+
| iOS | [^3] ||
5252
| Linux |||
53-
| Windows || |
53+
| Windows || |
5454
| macOS |||
5555
| Node.js |||
5656
| Qt |||
57+
58+
59+
[^3]: Some targets are supported, see [here](ios/README.md#cmake).

include/mbgl/mtl/index_buffer_resource.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace mtl {
88

99
class IndexBufferResource : public gfx::IndexBufferResource {
1010
public:
11-
IndexBufferResource() noexcept = default;
11+
IndexBufferResource() noexcept = delete;
1212
IndexBufferResource(BufferResource&&) noexcept;
1313
IndexBufferResource(IndexBufferResource&& other) noexcept
1414
: buffer(std::move(other.buffer)) {}

include/mbgl/mtl/vertex_buffer_resource.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace mtl {
1010

1111
class VertexBufferResource : public gfx::VertexBufferResource {
1212
public:
13-
VertexBufferResource() noexcept = default;
13+
VertexBufferResource() noexcept = delete;
1414
VertexBufferResource(BufferResource&&) noexcept;
1515
VertexBufferResource(VertexBufferResource&& other) noexcept
1616
: buffer(std::move(other.buffer)) {}

platform/darwin/BUILD.bazel

+13-12
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ cc_library(
200200
objc_library(
201201
name = "darwin-objc",
202202
srcs = [
203-
"src/native_apple_interface.m",
203+
"core/native_apple_interface.m",
204204
],
205205
hdrs = [
206206
"include/mbgl/interface/native_apple_interface.h",
@@ -227,15 +227,15 @@ objc_library(
227227
objc_library(
228228
name = "darwin-objcpp",
229229
srcs = [
230+
"core/collator.mm",
231+
"core/http_file_source.mm",
232+
"core/image.mm",
233+
"core/local_glyph_rasterizer.mm",
234+
"core/logging_nslog.mm",
235+
"core/nsthread.mm",
236+
"core/number_format.mm",
237+
"core/string_nsstring.mm",
230238
"src/CFHandle.hpp",
231-
"src/collator.mm",
232-
"src/http_file_source.mm",
233-
"src/image.mm",
234-
"src/local_glyph_rasterizer.mm",
235-
"src/logging_nslog.mm",
236-
"src/nsthread.mm",
237-
"src/number_format.mm",
238-
"src/string_nsstring.mm",
239239
] + select({
240240
"//:metal_renderer": [],
241241
"//conditions:default": ["src/headless_backend_eagl.mm"],
@@ -252,6 +252,7 @@ objc_library(
252252
],
253253
includes = [
254254
"include",
255+
"src",
255256
],
256257
sdk_frameworks = [
257258
"CoreText",
@@ -269,9 +270,9 @@ objc_library(
269270
objc_library(
270271
name = "darwin-loop",
271272
srcs = [
272-
"src/async_task.cpp",
273-
"src/run_loop.cpp",
274-
"src/timer.cpp",
273+
"core/async_task.cpp",
274+
"core/run_loop.cpp",
275+
"core/timer.cpp",
275276
] + select({
276277
"//:metal_renderer": [],
277278
"//conditions:default": ["src/gl_functions.cpp"],
File renamed without changes.
File renamed without changes.

platform/darwin/src/http_file_source.mm platform/darwin/core/http_file_source.mm

+1-4
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ void cancel() {
8686
public:
8787
Impl(const ResourceOptions& resourceOptions_, const ClientOptions& clientOptions_)
8888
: resourceOptions(resourceOptions_.clone()), clientOptions(clientOptions_.clone()) {
89-
@autoreleasepool {
9089
NSURLSessionConfiguration *sessionConfig = MLNNativeNetworkManager.sharedManager.sessionConfiguration;
9190
session = [NSURLSession sessionWithConfiguration:sessionConfig];
9291

@@ -95,8 +94,6 @@ void cancel() {
9594
} else {
9695
userAgent = sessionConfig.HTTPAdditionalHeaders[@"User-Agent"];
9796
}
98-
99-
}
10097
}
10198

10299
void setResourceOptions(ResourceOptions options);
@@ -280,7 +277,7 @@ BOOL isValidMapboxEndpoint(NSURL *url) {
280277
[MLNNativeNetworkManager.sharedManager startDownloadEvent:url.relativePath type:@"tile"];
281278
}
282279

283-
__block NSURLSession *session;
280+
__block NSURLSession *session = nil;
284281

285282
// Use the delegate's session if there is one, otherwise use the one that
286283
// was created when this class was constructed.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)