Skip to content

Commit

Permalink
Add iOS build support to the CMake build (firebase#5052)
Browse files Browse the repository at this point in the history
* Use early exit in objc_framework CMakeLists.txt

* Clean up objc_framework CMakeLists.txt

  * Use `version` consistently
  * Use `firebase_ios_version` for the repo-level version
  * Remove INCLUDE directories that are no longer needed
  * Sort dependencies

* Simplify Example/App/CMakeLists.txt

  * Add `OBJC_FLAGS` directly, avoiding a separate `sources` variable.
  * Add resources directly

* Rename test host app to firebase_firestore_example_app

* Add a firebase_ios prefix to functions and variables

This reduces the chance of collision with other projects.

* Simplify compiler_setup

Now that compiler_setup.cmake no longer has side-effects, fold
compiler_id.cmake and archive_options.cmake into it and move
the include of compiler_setup up to the top of the main build.

* Add support for building for iOS

* Make building benchmarks optional

* Disable protoc-based source generators when cross-compiling

* Make downloading googletest optional

* Add DISABLE_STRICT_WARNINGS mode to cc_rules

This makes it possible to build non-Firestore components in the CMake
build to a lower standard than that to which we hold ourselves without
sacrificing the utility of the various build rules that we have.
wilhuff authored Mar 13, 2020
1 parent 73099bb commit a568a96
Showing 18 changed files with 359 additions and 240 deletions.
61 changes: 47 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -60,6 +60,12 @@ endif()
enable_language(C)
enable_language(CXX)

option(
FIREBASE_IOS_BUILD_BENCHMARKS
"Enable building of C++ and Objective-C benchmarks for this project"
OFF
)

option(
FIREBASE_IOS_BUILD_TESTS
"Enable building of C++ and Objective-C tests for this project"
@@ -98,19 +104,32 @@ download_external_sources()


# Googletest
set(gtest_force_shared_crt ON CACHE BOOL "Use shared run-time")
add_external_subdirectory(googletest)
firebase_ios_add_alias(GTest::GTest gtest)
firebase_ios_add_alias(GTest::Main gtest_main)
firebase_ios_add_alias(GMock::GMock gmock)
if(FIREBASE_IOS_BUILD_TESTS)
set(gtest_force_shared_crt ON CACHE BOOL "Use shared run-time")
add_external_subdirectory(googletest)
firebase_ios_add_alias(GTest::GTest gtest)
firebase_ios_add_alias(GTest::Main gtest_main)
firebase_ios_add_alias(GMock::GMock gmock)
endif()


# Benchmark
set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Firestore disabled")
set(BENCHMARK_ENABLE_EXCEPTIONS OFF CACHE BOOL "Firestore disabled")
set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "Firestore disabled")
set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE BOOL "Firestore disabled")
add_external_subdirectory(benchmark)
if(FIREBASE_IOS_BUILD_BENCHMARKS)
set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Firestore disabled")
set(BENCHMARK_ENABLE_EXCEPTIONS OFF CACHE BOOL "Firestore disabled")
set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "Firestore disabled")
set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE BOOL "Firestore disabled")

if(IOS)
# benchmark uses CMake's try_run, which doesn't work out of the box when
# compiling for iOS.
set(HAVE_STD_REGEX ON CACHE BOOL "iOS has std::regex")
set(HAVE_POSIX_REGEX ON CACHE BOOL "iOS has POSIX regex.h")
set(HAVE_STEADY_CLOCK ON CACHE BOOL "iOS has std::chrono::steady_clock")
endif()

add_external_subdirectory(benchmark)
endif()


# Abseil-cpp
@@ -146,9 +165,24 @@ endif()
# pulled in indirectly via gRPC.
unset(RANDOM_FILE CACHE)

find_package(OpenSSL QUIET)
if(OPENSSL_FOUND)
set(gRPC_SSL_PROVIDER package CACHE STRING "Use external OpenSSL")
set(CARES_INSTALL OFF CACHE BOOL "Disabled")

set(protobuf_BUILD_TESTS OFF CACHE BOOL "Disabled")
if(IOS OR ANDROID)
# C-Ares includes a number of example binaries (e.g. `ahost`) that fail to
# build when compiling for non-host targets.
set(gRPC_CARES_PROVIDER none CACHE STRING "Don't use C-Ares")

# protoc needs to be built for the host to be able to invoke it during the
# build.
set(protobuf_BUILD_PROTOC_BINARIES OFF CACHE BOOL "Disabled")
endif()

if(NOT ANDROID AND NOT IOS)
find_package(OpenSSL QUIET)
if(OPENSSL_FOUND)
set(gRPC_SSL_PROVIDER package CACHE STRING "Use external OpenSSL")
endif()
endif()

find_package(ZLIB QUIET)
@@ -239,7 +273,6 @@ target_compile_definitions(
target_include_directories(
protobuf-nanopb-static
INTERFACE
$<BUILD_INTERFACE:${FIREBASE_EXTERNAL_SOURCE_DIR}>
$<BUILD_INTERFACE:${FIREBASE_EXTERNAL_SOURCE_DIR}/nanopb>
)

8 changes: 7 additions & 1 deletion FirebaseCore/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -35,7 +35,13 @@ firebase_ios_objc_framework(
DEPENDS
FirebaseCoreDiagnosticsInterop
GoogleUtilities
"-framework AppKit"
"-framework Foundation"
DISABLE_STRICT_WARNINGS
EXCLUDE_FROM_ALL
)

if(IOS)
target_link_libraries(FirebaseCore PRIVATE "-framework UIKit")
elseif(APPLE)
target_link_libraries(FirebaseCore PRIVATE "-framework AppKit")
endif()
81 changes: 57 additions & 24 deletions Firestore/Example/App/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -16,27 +16,60 @@ if(NOT APPLE)
return()
endif()

add_executable(
firebase_firestore_example_app MACOSX_BUNDLE
macOS/AppDelegate.h
macOS/AppDelegate.m
macOS/main.m
)

target_compile_options(
firebase_firestore_example_app
PRIVATE ${FIREBASE_IOS_OBJC_FLAGS}
)

target_link_libraries(
firebase_firestore_example_app
PRIVATE
"-framework AppKit"
"-framework Foundation"
)

set_target_properties(
firebase_firestore_example_app PROPERTIES
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/macOS/Info.plist
RESOURCE GoogleService-Info.plist
)
if(IOS)
add_executable(
firebase_firestore_example_app MACOSX_BUNDLE
iOS/FIRAppDelegate.h
iOS/FIRAppDelegate.m
iOS/FIRViewController.h
iOS/FIRViewController.m
iOS/main.m
)

target_compile_options(
firebase_firestore_example_app
PRIVATE ${FIREBASE_IOS_OBJC_FLAGS}
)

target_link_libraries(
firebase_firestore_example_app
PRIVATE
"-framework UIKit"
"-framework Foundation"
)

set_target_properties(
firebase_firestore_example_app PROPERTIES
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/iOS/Firestore-Info.plist
RESOURCE GoogleService-Info.plist
)

else()
# Assume macOS

add_executable(
firebase_firestore_example_app MACOSX_BUNDLE
macOS/AppDelegate.h
macOS/AppDelegate.m
macOS/main.m
)

target_compile_options(
firebase_firestore_example_app
PRIVATE ${FIREBASE_IOS_OBJC_FLAGS}
)

target_link_libraries(
firebase_firestore_example_app
PRIVATE
"-framework AppKit"
"-framework Foundation"
)

set_target_properties(
firebase_firestore_example_app PROPERTIES
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/macOS/Info.plist
RESOURCE GoogleService-Info.plist
)

endif()
2 changes: 1 addition & 1 deletion Firestore/Example/Benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

if(APPLE)
if(FIREBASE_IOS_BUILD_BENCHMARKS AND APPLE)
firebase_ios_cc_binary(
firebase_firestore_remote_document_cache_benchmark
SOURCES
65 changes: 33 additions & 32 deletions Firestore/Example/Tests/Util/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -12,35 +12,36 @@
# See the License for the specific language governing permissions and
# limitations under the License.

if(APPLE)
firebase_ios_cc_library(
firebase_firestore_objc_test_util
HEADERS
FSTEventAccumulator.h
XCTestCase+Await.h
FSTIntegrationTestCase.h
FIRFirestore+Testing.h
FSTHelpers.h
SOURCES
FSTEventAccumulator.mm
XCTestCase+Await.mm
FSTIntegrationTestCase.mm
FSTHelpers.mm
DEPENDS
absl_any
absl_strings
FirebaseFirestore
firebase_firestore_auth
firebase_firestore_core
firebase_firestore_local
firebase_firestore_model
firebase_firestore_util
firebase_firestore_remote
firebase_firestore_remote_testing
firebase_firestore_nanopb
firebase_firestore_protos_nanopb
firebase_firestore_testutil
${XCTest_LIBRARIES}
GTest::GTest
)
endif(APPLE)
if(NOT FIREBASE_IOS_BUILD_TESTS OR NOT APPLE)
return()
endif()

firebase_ios_cc_library(
firebase_firestore_objc_test_util
SOURCES
FIRFirestore+Testing.h
FSTEventAccumulator.h
FSTEventAccumulator.mm
FSTHelpers.h
FSTHelpers.mm
FSTIntegrationTestCase.h
FSTIntegrationTestCase.mm
XCTestCase+Await.h
XCTestCase+Await.mm
DEPENDS
absl_any
absl_strings
FirebaseFirestore
firebase_firestore_auth
firebase_firestore_core
firebase_firestore_local
firebase_firestore_model
firebase_firestore_util
firebase_firestore_remote
firebase_firestore_remote_testing
firebase_firestore_nanopb
firebase_firestore_protos_nanopb
firebase_firestore_testutil
${XCTest_LIBRARIES}
GTest::GTest
)
Loading
Oops, something went wrong.

0 comments on commit a568a96

Please sign in to comment.