Skip to content

Commit e0ffdc0

Browse files
authored
Clean up cmake ios for new cmake version (#1843)
* Clean up cmake ios for new cmake version * explicity add in the ios simulator to the build
1 parent 5f348b8 commit e0ffdc0

File tree

11 files changed

+46
-1062
lines changed

11 files changed

+46
-1062
lines changed

AGENTS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ The SDK uses CMake for C++ compilation and Gradle for Android-specific parts.
6060
2. Run CMake to configure: `cmake ..`
6161
* For Desktop: Run as is. You can use BORINGSSL instead of OpenSSL (for fewer
6262
system dependencies with the `-DFIREBASE_USE_BORINGSSL=YES` parameter.
63-
* For iOS, include the `-DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/ios.cmake`
63+
* For iOS, include the `-DCMAKE_SYSTEM_NAME=iOS`
6464
parameter. This requires running on a Mac build machine.
6565
3. Build specific targets: `cmake --build . --target firebase_analytics`
6666
(replace `firebase_analytics` with the desired library).

CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,17 @@ if(FIREBASE_CPP_BUILD_TESTS OR FIREBASE_CPP_BUILD_STUB_TESTS)
119119
${CMAKE_BINARY_DIR})
120120
endif()
121121

122-
if (PLATFORM STREQUAL TVOS OR PLATFORM STREQUAL SIMULATOR_TVOS)
122+
if(PLATFORM STREQUAL TVOS OR PLATFORM STREQUAL SIMULATOR_TVOS OR CMAKE_SYSTEM_NAME STREQUAL "tvOS")
123123
# UMP is not supported on tvOS.
124124
set(FIREBASE_INCLUDE_UMP OFF)
125125
endif()
126126

127+
# CMake 3.14+ native iOS support sets CMAKE_SYSTEM_NAME to iOS, 3.21+ for tvOS
128+
if(CMAKE_SYSTEM_NAME STREQUAL "iOS" OR CMAKE_SYSTEM_NAME STREQUAL "tvOS")
129+
set(IOS ON CACHE BOOL "")
130+
set(FIREBASE_IOS_BUILD ON CACHE BOOL "")
131+
endif()
132+
127133
# Occasionally ANDROID is not being set correctly when invoked by gradle, so
128134
# set it manually if ANDROID_NDK has been defined.
129135
if(DEFINED ANDROID_NDK)

README.md

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -167,28 +167,22 @@ Currently, the third party libraries that can be provided this way are:
167167
| ZLIB |
168168

169169
#### Building with CMake for iOS
170-
The Firebase C++ SDK comes with a CMake config file to build the library for
171-
iOS platforms, [cmake/toolchains/ios.cmake](/cmake/toolchains/ios.cmake). In
172-
order to build with it, when running the CMake configuration pass it in with
173-
the CMAKE_TOOLCHAIN_FILE definition. For example, to build the Auth
174-
library for iOS, you could run the following commands:
170+
Starting with CMake 3.14, iOS is supported natively by CMake. To build for iOS, set the `CMAKE_SYSTEM_NAME` to `iOS`.
171+
For example, to build the Auth library for iOS, you could run the following commands:
175172

176173
``` bash
177174
mkdir ios_build && cd ios_build
178-
cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/ios.cmake ..
175+
cmake -DCMAKE_SYSTEM_NAME=iOS ..
179176
cmake --build . --target firebase_auth
180177
```
181178

182179
#### Building with CMake for tvOS
183-
The Firebase C++ SDK comes with a CMake config file to build the library for
184-
tvOS platforms, [cmake/toolchains/apple.toolchain.cmake](/cmake/toolchains/apple.toolchain.cmake). In
185-
order to build with it, when running the CMake configuration pass it in with
186-
the CMAKE_TOOLCHAIN_FILE definition. For example, to build the Auth
187-
library for tvOS, you could run the following commands:
180+
Starting with CMake 3.14, tvOS is supported natively by CMake. To build for tvOS, set the `CMAKE_SYSTEM_NAME` to `tvOS`.
181+
For example, to build the Auth library for tvOS, you could run the following commands:
188182

189183
``` bash
190184
mkdir tvos_build && cd tvos_build
191-
cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/apple.toolchain.cmake -DPLATFORM=TVOS ..
185+
cmake -DCMAKE_SYSTEM_NAME=tvOS ..
192186
cmake --build . --target firebase_auth
193187
```
194188

build_scripts/ios/build.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ cmakeBuild=true
4040

4141
# check options
4242
IFS=',' # split options on ',' characters
43-
while getopts ":b:s:a:t:g:ch" opt; do
43+
while getopts ":b:s:p:a:t:g:ch" opt; do
4444
case $opt in
4545
h)
4646
usage
@@ -121,17 +121,19 @@ frameworkspath="frameworks/ios"
121121
if ${generateMakefiles}; then
122122
for platform in ${platforms[@]}; do
123123
for arch in ${architectures[@]}; do
124+
sysroot_arg=""
124125
if [[ "${platform}" == "device" && " ${DEVICE_ARCHITECTURES[@]} " =~ " ${arch} " ]]; then
125-
toolchain="cmake/toolchains/ios.cmake"
126+
sysroot_arg="" # Default iphoneos sysroot is correct for iOS devices
126127
elif [[ "${platform}" == "simulator" && " ${SIMULATOR_ARCHITECTURES[@]} " =~ " ${arch} " ]]; then
127-
toolchain="cmake/toolchains/ios_simulator.cmake"
128+
sysroot_arg="-DCMAKE_OSX_SYSROOT=iphonesimulator" # Must specify sysroot for simulator, especially for x86_64
128129
else
129-
continue
130+
continue # Skip invalid platform/OS combinations
130131
fi
131132

132133
echo "generate Makefiles start"
133134
mkdir -p ${buildpath}/ios_build_file/${platform}-${arch} && cd ${buildpath}/ios_build_file/${platform}-${arch}
134-
cmake -DCMAKE_TOOLCHAIN_FILE=${sourcepath}/${toolchain} \
135+
cmake -DCMAKE_SYSTEM_NAME=iOS \
136+
${sysroot_arg} \
135137
-DCMAKE_OSX_ARCHITECTURES=${arch} \
136138
-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=${buildpath}/${frameworkspath}/${platform}-${arch} \
137139
${sourcepath}

build_scripts/tvos/build.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ cmakeBuild=true
4040

4141
# check options
4242
IFS=',' # split options on ',' characters
43-
while getopts ":b:s:a:t:g:ch" opt; do
43+
while getopts ":b:s:p:a:t:g:ch" opt; do
4444
case $opt in
4545
h)
4646
usage
@@ -123,18 +123,20 @@ if ${generateMakefiles}; then
123123
for platform in ${platforms[@]}; do
124124
for arch in ${architectures[@]}; do
125125
if [[ "${platform}" == "device" && " ${DEVICE_ARCHITECTURES[@]} " =~ " ${arch} " ]]; then
126-
toolchain="cmake/toolchains/apple.toolchain.cmake"
126+
# Device build
127+
:
127128
elif [[ "${platform}" == "simulator" && " ${SIMULATOR_ARCHITECTURES[@]} " =~ " ${arch} " ]]; then
128-
toolchain="cmake/toolchains/apple.toolchain.cmake"
129129
tvos_toolchain_platform="SIMULATOR_TVOS"
130+
sysroot_arg="-DCMAKE_OSX_SYSROOT=appletvsimulator"
130131
else
131132
continue
132133
fi
133134

134135
echo "generate Makefiles start"
135136
mkdir -p ${buildpath}/tvos_build_file/${platform}-${arch} && cd ${buildpath}/tvos_build_file/${platform}-${arch}
136-
cmake -DCMAKE_TOOLCHAIN_FILE=${sourcepath}/${toolchain} \
137-
-DPLATFORM=${tvos_toolchain_platform} \
137+
cmake -DCMAKE_SYSTEM_NAME=tvOS \
138+
-DCMAKE_OSX_ARCHITECTURES=${arch} \
139+
${sysroot_arg} \
138140
-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=${buildpath}/${frameworkspath}/${platform}-${arch} \
139141
${sourcepath}
140142
echo "generate Makefiles end"

0 commit comments

Comments
 (0)