Skip to content

Commit 0f7d6ab

Browse files
committed
Add CMake test logic for iOS
Adds a configuration file for iOS simulator, and add platform specific logic to the cc_test function, to allow Android, iOS, and Desktop specific files without having to repeat the tests. Set up the log test to work for iOS. PiperOrigin-RevId: 259815625
1 parent 844375f commit 0f7d6ab

File tree

6 files changed

+59
-20
lines changed

6 files changed

+59
-20
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ if(DEFINED CMAKE_TOOLCHAIN_FILE AND NOT ANDROID)
6969
endif()
7070
endif()
7171

72-
# We're on iOS if the system root is set to "iphoneos" or some variant.
73-
if("${CMAKE_OSX_SYSROOT}" MATCHES "iphoneos")
72+
# We're on iOS if the system root is set to "iphone" or some variant.
73+
if("${CMAKE_OSX_SYSROOT}" MATCHES "iphone")
7474
set(IOS TRUE CACHE BOOL "Target platform is iOS.")
7575
endif()
7676

app/CMakeLists.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,11 @@ if(IOS)
331331
add_dependencies(firebase_app ${pod_target_name})
332332
endif()
333333

334-
# Add the rest subdirectory, so that other libraries can access it
335-
add_subdirectory(rest)
336-
add_subdirectory(instance_id)
334+
if (NOT ANDROID AND NOT IOS)
335+
# Add the rest subdirectory, so that other libraries can access it
336+
add_subdirectory(rest)
337+
add_subdirectory(instance_id)
338+
endif()
337339

338340
if(FIREBASE_CPP_BUILD_TESTS)
339341
# Add the tests subdirectory

cmake/ios.cmake

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,10 @@
1414

1515
set(CMAKE_OSX_SYSROOT iphoneos)
1616
set(CMAKE_OSX_ARCHITECTURES "arm64")
17-
set(CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos;-iphonesimulator")
17+
set(CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos")
1818
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO")
1919
set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE "YES")
2020

2121
# skip TRY_COMPILE checks
2222
set(CMAKE_CXX_COMPILER_WORKS TRUE)
23-
set(CMAKE_C_COMPILER_WORKS TRUE)
24-
25-
# force MAC_BUNDLE for executable
26-
#set(CMAKE_MACOSX_BUNDLE YES)
23+
set(CMAKE_C_COMPILER_WORKS TRUE)

cmake/ios_simulator.cmake

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2018 Google Inc. All rights reserved.
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+
set(CMAKE_OSX_SYSROOT iphonesimulator)
16+
set(CMAKE_OSX_ARCHITECTURES "x86_64")
17+
set(CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator")
18+
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO")
19+
set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE "YES")
20+
21+
# skip TRY_COMPILE checks
22+
set(CMAKE_CXX_COMPILER_WORKS TRUE)
23+
set(CMAKE_C_COMPILER_WORKS TRUE)

cmake/test_rules.cmake

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,34 @@ include(CMakeParseArguments)
2323
# Defines a new test executable target with the given target name, sources, and
2424
# dependencies. Implicitly adds DEPENDS on gtest and gtest_main.
2525
function(cc_test name)
26-
set(multi DEPENDS SOURCES INCLUDES DEFINES)
26+
set(multi DEPENDS SOURCES INCLUDES DEFINES
27+
ANDROID_DEPENDS ANDROID_SOURCES ANDROID_INCLUDES ANDROID_DEFINES
28+
IOS_DEPENDS IOS_SOURCES IOS_INCLUDES IOS_DEFINES
29+
DESKTOP_DEPENDS DESKTOP_SOURCES DESKTOP_INCLUDES DESKTOP_DEFINES)
2730
# Parse the arguments into cc_test_SOURCES and cc_test_DEPENDS.
2831
cmake_parse_arguments(cc_test "" "" "${multi}" ${ARGN})
2932

3033
list(APPEND cc_test_DEPENDS gmock gtest gtest_main)
34+
if (ANDROID)
35+
list(APPEND cc_test_SOURCES "${cc_test_ANDROID_SOURCES}")
36+
list(APPEND cc_test_DEPENDS "${cc_test_ANDROID_DEPENDS}")
37+
list(APPEND cc_test_INCLUDES "${cc_test_ANDROID_INCLUDES}")
38+
list(APPEND cc_test_DEFINES "${cc_test_ANDROID_DEFINES}")
39+
elseif (IOS)
40+
list(APPEND cc_test_SOURCES "${cc_test_IOS_SOURCES}")
41+
list(APPEND cc_test_DEPENDS
42+
"${cc_test_IOS_DEPENDS}"
43+
"-framework CoreFoundation"
44+
"-framework Foundation"
45+
)
46+
list(APPEND cc_test_INCLUDES "${cc_test_IOS_INCLUDES}")
47+
list(APPEND cc_test_DEFINES "${cc_test_IOS_DEFINES}")
48+
else()
49+
list(APPEND cc_test_SOURCES "${cc_test_DESKTOP_SOURCES}")
50+
list(APPEND cc_test_DEPENDS "${cc_test_DESKTOP_DEPENDS}")
51+
list(APPEND cc_test_INCLUDES "${cc_test_DESKTOP_INCLUDES}")
52+
list(APPEND cc_test_DEFINES "${cc_test_DESKTOP_DEFINES}")
53+
endif()
3154

3255
add_executable(${name} ${cc_test_SOURCES})
3356
add_test(${name} ${name})

testing/CMakeLists.txt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ binary_to_array("testdata_config_resource"
2828
set(config_common_SRCS
2929
config.h
3030
config.cc
31-
config_test.cc
3231
${FIREBASE_GEN_FILE_DIR}/testing/testdata_config_generated.h
3332
${FIREBASE_GEN_FILE_DIR}/testing/testdata_config_resource.h
3433
${FIREBASE_GEN_FILE_DIR}/testing/testdata_config_resource.cc)
@@ -57,10 +56,8 @@ endif()
5756
set(reporter_common_SRCS
5857
reporter.h
5958
reporter.cc
60-
reporter_test.cc
6159
reporter_impl.h
6260
reporter_impl.cc
63-
reporter_impl_test.cc
6461
)
6562
set(reporter_android_SRCS
6663
reporter_android.cc)
@@ -74,8 +71,7 @@ else()
7471
endif()
7572

7673
set(ticker_common_SRCS
77-
ticker.h
78-
ticker_test.cc)
74+
ticker.h)
7975
set(ticker_android_SRCS
8076
ticker_android.cc)
8177
set(ticker_ios_SRCS
@@ -99,12 +95,10 @@ endif()
9995

10096
set(util_android_SRCS
10197
util_android.h
102-
util_android.cc
103-
util_android_test.cc)
98+
util_android.cc)
10499
set(util_ios_SRCS
105100
util_ios.h
106-
util_ios.mm
107-
util_ios_test.mm)
101+
util_ios.mm)
108102
if(ANDROID)
109103
set(util_SRCS
110104
"${util_android_SRCS}")

0 commit comments

Comments
 (0)