Skip to content

Commit 60e675a

Browse files
Googlera-maurice
authored andcommitted
Open source CMake changes for ios tests.
- Added all cc_test_on_ios targets as they exist in google3. - Configuredthe cc_test_on_ios targets to include the correct depdendencies. These targets now compile and link via ./test_mac_ios.sh. - Added automatic download of iOS SDK to link against the frameworks. PiperOrigin-RevId: 289937761
1 parent ed8a979 commit 60e675a

File tree

5 files changed

+120
-3
lines changed

5 files changed

+120
-3
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ set(FIREBASE_INSTALL_DIR ${PROJECT_BINARY_DIR}/opt)
9595
set(FIREBASE_DOWNLOAD_DIR ${PROJECT_BINARY_DIR}/downloads)
9696

9797
# Run the CMake build logic that will download all the external dependencies.
98+
message(STATUS "Downloading external project dependencies...")
9899
download_external_sources()
100+
message(STATUS "Download complete.")
99101

100102
# Disable the Flatbuffer build tests, install and flathash
101103
set(FLATBUFFERS_BUILD_TESTS OFF CACHE BOOL "")

cmake/external/CMakeLists.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ project(Firebase-cpp-download C CXX)
2323
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})
2424

2525
include(flatbuffers)
26-
include(googletest)
26+
2727

2828
# Some of the external dependencies are not needed for mobile.
2929
if (${FIREBASE_EXTERNAL_PLATFORM} STREQUAL "DESKTOP")
@@ -33,3 +33,13 @@ if (${FIREBASE_EXTERNAL_PLATFORM} STREQUAL "DESKTOP")
3333
include(uWebSockets)
3434
include(zlib)
3535
endif()
36+
37+
# Support files for the test framework.
38+
if(FIREBASE_CPP_BUILD_TESTS)
39+
include(googletest)
40+
41+
# Download the iOS SDK Frameworks required for linking the tests.
42+
if (${FIREBASE_EXTERNAL_PLATFORM} STREQUAL "IOS")
43+
include(firebase_ios_sdk)
44+
endif()
45+
endif()

cmake/external/firebase_ios_sdk.cmake

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright 2020 Google
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
include(ExternalProject)
16+
17+
if(TARGET firebase_ios_sdk OR NOT DOWNLOAD_FIREBASE_IOS_SDK)
18+
return()
19+
endif()
20+
21+
cmake_minimum_required(VERSION 3.0)
22+
23+
set(SDK_VERSION "6.14.0")
24+
25+
# Build the download URL.
26+
string(REPLACE "." "_" SDK_VERSION_PATH ${SDK_VERSION})
27+
string(CONCAT URL
28+
"https://dl.google.com/firebase/sdk/ios/"
29+
${SDK_VERSION_PATH}
30+
"/Firebase-"
31+
${SDK_VERSION}
32+
".zip")
33+
34+
# Configure local storage of download.
35+
set(ZIP_FILENAME "./firebase_sdk_${SDK_VERSION}.zip")
36+
set(OUTDIR "./firebase_ios_sdk/")
37+
38+
# Download as required.
39+
if(FIREBASE_CPP_BUILD_TESTS)
40+
if(NOT EXISTS ${OUTDIR})
41+
if(NOT EXISTS ${ZIP_FILENAME})
42+
file(DOWNLOAD ${URL} ${ZIP_FILENAME})
43+
endif()
44+
execute_process(COMMAND mkdir ${OUTDIR})
45+
execute_process(COMMAND tar -xf ${ZIP_FILENAME} -C ${OUTDIR})
46+
execute_process(COMMAND rm ${ZIP_FILENAME})
47+
endif()
48+
endif()

cmake/external_rules.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ function(download_external_sources)
5252
check_use_local_directory(NANOPB)
5353
check_use_local_directory(UWEBSOCKETS)
5454
check_use_local_directory(ZLIB)
55+
check_use_local_directory(FIREBASE_IOS_SDK)
5556

5657
execute_process(
5758
COMMAND
@@ -66,6 +67,8 @@ function(download_external_sources)
6667
-DDOWNLOAD_NANOPB=${DOWNLOAD_NANOPB}
6768
-DDOWNLOAD_UWEBSOCKETS=${DOWNLOAD_UWEBSOCKETS}
6869
-DDOWNLOAD_ZLIB=${DOWNLOAD_ZLIB}
70+
-DDOWNLOAD_FIREBASE_IOS_SDK=${DOWNLOAD_FIREBASE_IOS_SDK}
71+
-DFIREBASE_CPP_BUILD_TESTS=${FIREBASE_CPP_BUILD_TESTS}
6972
${PROJECT_SOURCE_DIR}/cmake/external
7073
OUTPUT_FILE ${PROJECT_BINARY_DIR}/external/output_cmake_config.txt
7174
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/external

cmake/test_rules.cmake

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,26 +61,80 @@ endfunction()
6161
# target
6262
# SOURCES sources...
6363
# DEPENDS libraries...
64+
# CUSTOM_FRAMEWORKS frameworks...
6465
# )
6566
#
6667
# Defines a new test executable target with the given target name, sources, and
6768
# dependencies. Implicitly adds DEPENDS on gtest, gtest_main, Foundation and
68-
# CoreFoundation frameworks.
69+
# CoreFoundation frameworks. CUSTOM_FRAMEWORKS will include any custom Cocoapods
70+
# frameworks beyond the baseline FirebaseAnalytics.
6971
function(cc_test_on_ios name)
7072
if (NOT IOS)
7173
return()
7274
endif()
7375

74-
set(multi DEPENDS SOURCES INCLUDES DEFINES)
76+
set(multi DEPENDS SOURCES INCLUDES DEFINES CUSTOM_FRAMEWORKS)
7577
# Parse the arguments into cc_test_SOURCES and cc_test_DEPENDS.
7678
cmake_parse_arguments(cc_test "" "" "${multi}" ${ARGN})
7779

80+
set(SDK_FRAMEWORK_DIR_NAMES
81+
FirebaseABTesting
82+
FirebaseAnalytics
83+
FirebaseAuth
84+
FirebaseDatabase
85+
FirebaseDynamicLinks
86+
FirebaseFunctions
87+
FirebaseMessaging
88+
FirebaseRemoteConfig
89+
FirebaseStorage
90+
GoogleSignIn
91+
)
92+
93+
# The build environment can use a user-downloaded Firebase IOS SDK defined by
94+
# FIREBASE_IOS_SDK_DIR. Alternatively download the SDK directly if it's not
95+
# configured and store the files in external/firebase_ios_sdk.
96+
if(NOT DEFINED ${FIREBASE_IOS_SDK_DIR})
97+
set(FIREBASE_IOS_SDK_DIR
98+
"${CMAKE_BINARY_DIR}/external/firebase_ios_sdk/Firebase")
99+
endif()
100+
101+
# Add the directories of the SDK download to the framework searchpath.
102+
foreach(FRAMEWORK IN LISTS SDK_FRAMEWORK_DIR_NAMES)
103+
set(directory "${FIREBASE_IOS_SDK_DIR}/${FRAMEWORK}")
104+
LIST(APPEND FRAMEWORK_DIRS "-F ${directory}")
105+
endforeach()
106+
107+
# All Firebase SDK modules require the Firebase Analytics Frameworks
108+
# so include them by default:
109+
set(DEFAULT_FRAMEWORKS
110+
FIRAnalyticsConnector
111+
FirebaseAnalytics
112+
FirebaseCore
113+
FirebaseCoreDiagnostics
114+
FirebaseInstanceID
115+
GTMSessionFetcher
116+
GoogleAppMeasurement
117+
GoogleDataTransport
118+
GoogleDataTransportCCTSupport
119+
GoogleUtilities
120+
nanopb
121+
)
122+
123+
# Construct a command line list of frameworks from the default frameworks
124+
# (above) and for those passed to this function through the CUSTOM_FRAMEWORKS
125+
# parameter.
126+
foreach(FRAMEWORK IN LISTS DEFAULT_FRAMEWORKS cc_test_CUSTOM_FRAMEWORKS)
127+
LIST(APPEND FRAMEWORK_INCLUDES "-framework ${FRAMEWORK}")
128+
endforeach()
129+
78130
list(APPEND cc_test_DEPENDS
79131
gmock
80132
gtest
81133
gtest_main
134+
"${FRAMEWORK_DIRS}"
82135
"-framework CoreFoundation"
83136
"-framework Foundation"
137+
"${FRAMEWORK_INCLUDES}"
84138
)
85139

86140
add_executable(${name} ${cc_test_SOURCES})

0 commit comments

Comments
 (0)