Skip to content

Commit 9da3cfc

Browse files
markchandlera-maurice
authored andcommitted
Firebase Cpp/Unity Kokoro Fixes:
* Fixed ios build not finding existing cpp sdk * Fixed ios compiler settings not always being set correctly * Fixed trying to symlink pods before pods where installed PiperOrigin-RevId: 281322348
1 parent 19eec56 commit 9da3cfc

File tree

3 files changed

+39
-43
lines changed

3 files changed

+39
-43
lines changed

CMakeLists.txt

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -68,23 +68,6 @@ if(DEFINED ANDROID_NDK)
6868
set(ANDROID 1)
6969
endif()
7070

71-
if(DEFINED CMAKE_TOOLCHAIN_FILE AND NOT ANDROID)
72-
# Force using the toolchain file, as otherwise it loads it later in the
73-
# process, after several of the checks against it have failed.
74-
if(IS_ABSOLUTE ${CMAKE_TOOLCHAIN_FILE})
75-
message("Using Toolchain File: ${CMAKE_TOOLCHAIN_FILE}")
76-
include("${CMAKE_TOOLCHAIN_FILE}")
77-
else()
78-
message("Using Toolchain File: ${CMAKE_BINARY_DIR}/${CMAKE_TOOLCHAIN_FILE}")
79-
include("${CMAKE_BINARY_DIR}/${CMAKE_TOOLCHAIN_FILE}")
80-
endif()
81-
endif()
82-
83-
# We're on iOS if the system root is set to "iphone" or some variant.
84-
if("${CMAKE_OSX_SYSROOT}" MATCHES "iphone")
85-
set(IOS TRUE CACHE BOOL "Target platform is iOS.")
86-
endif()
87-
8871
# Set directories needed by the Firebase subprojects
8972
# Directory to store generated files.
9073
set(FIREBASE_GEN_FILE_DIR ${CMAKE_BINARY_DIR}/generated)
@@ -113,8 +96,15 @@ set(FIREBASE_DOWNLOAD_DIR ${PROJECT_BINARY_DIR}/downloads)
11396
# Run the CMake build logic that will download all the external dependencies.
11497
download_external_sources()
11598

116-
# Disable the Flatbuffer build tests
99+
# Disable the Flatbuffer build tests, install and flathash
117100
set(FLATBUFFERS_BUILD_TESTS OFF CACHE BOOL "")
101+
set(FLATBUFFERS_INSTALL OFF CACHE BOOL "")
102+
set(FLATBUFFERS_FLATHASH OFF CACHE BOOL "")
103+
104+
# Disable buliding flatc if cross compiling
105+
if(IOS OR ANDROID)
106+
set(FLATBUFFERS_BUILD_FLATC OFF CACHE BOOL "")
107+
endif()
118108

119109
# Add flatbuffers as a subdirectory, and set the directory variables for it,
120110
# so that the sub Firebase projects can depend upon it if necessary.
@@ -230,7 +220,6 @@ if(ANDROID OR IOS)
230220
endif()
231221

232222
set(FLATBUFFERS_FLATC_EXECUTABLE ${firebase_external_flatc} CACHE STRING "")
233-
set(FLATBUFFERS_BUILD_FLATC OFF CACHE BOOL "")
234223

235224
# Setup the flatc custom build target.
236225
# These commands are executed from within the currect context, which has set

cmake/ios.cmake

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,33 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
set(CMAKE_OSX_SYSROOT iphoneos)
16-
set(CMAKE_OSX_ARCHITECTURES "arm64")
15+
# Locate gcc
16+
execute_process(COMMAND /usr/bin/xcrun -sdk iphoneos -find clang
17+
OUTPUT_VARIABLE CMAKE_C_COMPILER
18+
OUTPUT_STRIP_TRAILING_WHITESPACE)
19+
20+
# Locate g++
21+
execute_process(COMMAND /usr/bin/xcrun -sdk iphoneos -find clang++
22+
OUTPUT_VARIABLE CMAKE_CXX_COMPILER
23+
OUTPUT_STRIP_TRAILING_WHITESPACE)
24+
25+
# Set the CMAKE_OSX_SYSROOT to the latest SDK found
26+
execute_process(COMMAND /usr/bin/xcrun -sdk iphoneos --show-sdk-path
27+
OUTPUT_VARIABLE CMAKE_OSX_SYSROOT
28+
OUTPUT_STRIP_TRAILING_WHITESPACE)
29+
30+
message(STATUS "gcc found at: ${CMAKE_C_COMPILER}")
31+
message(STATUS "g++ found at: ${CMAKE_CXX_COMPILER}")
32+
message(STATUS "Using iOS SDK: ${CMAKE_OSX_SYSROOT}")
33+
34+
set(CMAKE_OSX_ARCHITECTURES "arm64" CACHE STRING "")
1735
set(CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos")
1836
set(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "NO")
1937
set(CMAKE_XCODE_ATTRIBUTE_ENABLE_BITCODE "YES")
2038

2139
# skip TRY_COMPILE checks
2240
set(CMAKE_CXX_COMPILER_WORKS TRUE)
23-
set(CMAKE_C_COMPILER_WORKS TRUE)
41+
set(CMAKE_C_COMPILER_WORKS TRUE)
42+
43+
set(FIREBASE_IOS_BUILD ON CACHE BOOL "")
44+
set(IOS ON CACHE BOOL "")

ios_pod/CMakeLists.txt

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,15 @@ file(
3434
"${FIREBASE_POD_DIR}/CMakeLists.txt"
3535
)
3636

37-
# We use "env -i" to clear the environment variables, and manually keep
38-
# the PATH to regular bash path.
39-
# If we didn't do this, we'd end up building for iOS instead of OSX,
40-
# since the default Xcode environment variables target iOS when you're in
41-
# an iOS project.
42-
set(firebase_command_line_path "$ENV{PATH}")
43-
add_custom_command(
44-
# Depend on the lock file, as depending on directories can report false
45-
# positives.
46-
OUTPUT "${FIREBASE_POD_DIR}/Podfile.lock"
47-
COMMAND env -i PATH=${firebase_command_line_path} cmake . -G Xcode &&
48-
pod install
49-
DEPENDS ${FIREBASE_POD_DIR}/Podfile
50-
DEPENDS ${FIREBASE_POD_DIR}/empty.cc
51-
DEPENDS ${FIREBASE_POD_DIR}/CMakeLists.txt
52-
WORKING_DIRECTORY ${FIREBASE_POD_DIR}
37+
message("Downloading cocoa pods...")
38+
39+
execute_process(
40+
COMMAND /bin/bash -c
41+
"mkdir -p ${FIREBASE_POD_DIR} && cd ${FIREBASE_POD_DIR} && cmake . -G Xcode && pod install"
42+
OUTPUT_VARIABLE pods_output
5343
)
5444

55-
add_custom_target(ios_pod_download DEPENDS ${FIREBASE_POD_DIR}/Podfile.lock)
45+
message("${pods_output}")
5646

5747
set(FIREBASE_POD_DIR ${FIREBASE_POD_DIR} PARENT_SCOPE)
5848
set(FIREBASE_POD_HEADER_DIR
@@ -78,8 +68,6 @@ function(setup_pod_headers target_name)
7868
# Parse the arguments into SETUP_POD_HEADERS_POD_NAMES.
7969
cmake_parse_arguments(SETUP_POD_HEADERS "" "" "${multi}" ${ARGN})
8070

81-
add_dependencies(${target_name} ios_pod_download)
82-
8371
if(NOT "${SETUP_POD_HEADERS_POD_NAMES}" STREQUAL "")
8472
foreach (pod ${SETUP_POD_HEADERS_POD_NAMES})
8573
# Add pod name twice as some frameworks moved includes inside a folder with
@@ -125,8 +113,6 @@ function(symlink_pod_headers target_name pod_name dir_name)
125113
return()
126114
endif()
127115

128-
message(" ## ${target_name} '${glob_dir}'")
129-
130116
add_custom_command(
131117
OUTPUT "${gen_file}"
132118
COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/pod_sym_links

0 commit comments

Comments
 (0)