Skip to content

Commit

Permalink
Refactor and clean up the CMake build ahead of CMake/iOS support (fir…
Browse files Browse the repository at this point in the history
…ebase#5051)

* 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.
  • Loading branch information
wilhuff authored Mar 11, 2020
1 parent 8fa6431 commit e404054
Show file tree
Hide file tree
Showing 43 changed files with 340 additions and 375 deletions.
20 changes: 9 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2017 Google
# Copyright 2017 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -34,7 +34,7 @@ endif()

# Generate Ninja phony rules for unknown dependencies in the build tree and
# don't complain about doing so. Our dependencies aren't good about declaring
# BYPRODUCTS and we mix them all into a single uber build so we can't enable
# BYPRODUCTS and we mix them all into a single superbuild so we can't enable
# this policy until all dependencies are capable of doing so.
if(POLICY CMP0058)
cmake_policy(SET CMP0058 OLD)
Expand Down Expand Up @@ -68,8 +68,7 @@ option(


list(INSERT CMAKE_MODULE_PATH 0 ${PROJECT_SOURCE_DIR}/cmake)
include(compiler_id)
include(archive_options)
include(compiler_setup)
include(sanitizer_options)
include(fuzzing_options)

Expand Down Expand Up @@ -101,9 +100,9 @@ download_external_sources()
# Googletest
set(gtest_force_shared_crt ON CACHE BOOL "Use shared run-time")
add_external_subdirectory(googletest)
add_alias(GTest::GTest gtest)
add_alias(GTest::Main gtest_main)
add_alias(GMock::GMock gmock)
firebase_ios_add_alias(GTest::GTest gtest)
firebase_ios_add_alias(GTest::Main gtest_main)
firebase_ios_add_alias(GMock::GMock gmock)


# Benchmark
Expand Down Expand Up @@ -179,14 +178,14 @@ if(OPENSSL_FOUND)

else()
# Not using outboard OpenSSL so set up BoringSSL to look like it.
add_alias(OpenSSL::Crypto crypto)
firebase_ios_add_alias(OpenSSL::Crypto crypto)
target_include_directories(
crypto
INTERFACE
$<BUILD_INTERFACE:${FIREBASE_EXTERNAL_SOURCE_DIR}/grpc/third_party/boringssl/include>
)

add_alias(OpenSSL::SSL ssl)
firebase_ios_add_alias(OpenSSL::SSL ssl)
target_include_directories(
ssl
INTERFACE
Expand Down Expand Up @@ -223,7 +222,7 @@ set(LEVELDB_BUILD_TESTS OFF CACHE BOOL "Firestore disabled")
set(LEVELDB_BUILD_BENCHMARKS OFF CACHE BOOL "Firestore disabled")
set(LEVELDB_INSTALL OFF CACHE BOOL "Firestore disabled")
add_external_subdirectory(leveldb)
add_alias(LevelDB::LevelDB leveldb)
firebase_ios_add_alias(LevelDB::LevelDB leveldb)


# nanopb
Expand Down Expand Up @@ -254,7 +253,6 @@ endif()
if(FIREBASE_IOS_BUILD_TESTS)
enable_testing()
endif()
include(compiler_setup)

add_subdirectory(FirebaseCore)
add_subdirectory(Firestore)
Expand Down
52 changes: 26 additions & 26 deletions FirebaseCore/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019 Google
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -12,30 +12,30 @@
# See the License for the specific language governing permissions and
# limitations under the License.

if(APPLE)
file(GLOB sources Sources/*.m)
file(GLOB headers Sources/Private/*.h Sources/Public/*.h)
if(NOT APPLE)
return()
endif()

podspec_version(core_version ${PROJECT_SOURCE_DIR}/FirebaseCore.podspec)
firebase_version(fb_version ${PROJECT_SOURCE_DIR}/FirebaseCore.podspec)
file(GLOB sources Sources/*.m)
file(GLOB headers Sources/Private/*.h Sources/Public/*.h)

objc_framework(
FirebaseCore
SOURCES ${sources}
HEADERS ${headers}
VERSION ${core_version}
DEFINES
FIRCore_VERSION=${core_version}
Firebase_VERSION=${fb_version}
INCLUDES
Sources/Private
Sources/Public
${PROJECT_SOURCE_DIR}
DEPENDS
GoogleUtilities
FirebaseCoreDiagnosticsInterop
"-framework Foundation"
"-framework AppKit"
EXCLUDE_FROM_ALL
)
endif()
podspec_version(version ${PROJECT_SOURCE_DIR}/FirebaseCore.podspec)
firebase_version(firebase_ios_version ${PROJECT_SOURCE_DIR}/FirebaseCore.podspec)

firebase_ios_objc_framework(
FirebaseCore
SOURCES ${sources}
HEADERS ${headers}
VERSION ${version}
DEFINES
FIRCore_VERSION=${version}
Firebase_VERSION=${firebase_ios_version}
INCLUDES
${PROJECT_SOURCE_DIR}
DEPENDS
FirebaseCoreDiagnosticsInterop
GoogleUtilities
"-framework AppKit"
"-framework Foundation"
EXCLUDE_FROM_ALL
)
57 changes: 25 additions & 32 deletions Firestore/Example/App/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019 Google
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -12,38 +12,31 @@
# See the License for the specific language governing permissions and
# limitations under the License.

if(APPLE)
set(
sources
macOS/main.m
macOS/AppDelegate.m
macOS/AppDelegate.h
)
if(NOT APPLE)
return()
endif()

set(
resources
GoogleService-Info.plist
)
add_executable(
firebase_firestore_example_app MACOSX_BUNDLE
macOS/AppDelegate.h
macOS/AppDelegate.m
macOS/main.m
)

add_executable(
firestore_example_app_macos MACOSX_BUNDLE
${sources}
)
target_compile_options(
firebase_firestore_example_app
PRIVATE ${FIREBASE_IOS_OBJC_FLAGS}
)

add_objc_flags(
firestore_example_app_macos
${sources}
)
target_link_libraries(
firebase_firestore_example_app
PRIVATE
"-framework AppKit"
"-framework Foundation"
)

target_link_libraries(
firestore_example_app_macos
PRIVATE "-framework AppKit"
)

set_target_properties(
firestore_example_app_macos PROPERTIES
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/macOS/Info.plist
RESOURCE "${resources}"
)

endif(APPLE)
set_target_properties(
firebase_firestore_example_app PROPERTIES
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/macOS/Info.plist
RESOURCE GoogleService-Info.plist
)
2 changes: 1 addition & 1 deletion Firestore/Example/Benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

if(APPLE)
cc_binary(
firebase_ios_cc_binary(
firebase_firestore_remote_document_cache_benchmark
SOURCES
remote_document_cache_benchmark.mm
Expand Down
6 changes: 3 additions & 3 deletions Firestore/Example/Tests/API/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019 Google
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -13,9 +13,9 @@
# limitations under the License.

if(APPLE)
objc_test(
firebase_ios_objc_test(
firebase_firestore_objc_api_test
HOST firestore_example_app_macos
HOST firebase_firestore_example_app
SOURCES
FIRCollectionReferenceTests.mm
FIRDocumentReferenceTests.mm
Expand Down
54 changes: 28 additions & 26 deletions Firestore/Example/Tests/Integration/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019 Google
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -12,28 +12,30 @@
# See the License for the specific language governing permissions and
# limitations under the License.

if(APPLE)
objc_test(
firebase_firestore_objc_integration_test
HOST firestore_example_app_macos
SOURCES
FSTSmokeTests.mm
FSTDatastoreTests.mm
FSTTransactionTests.mm
API/FIRArrayTransformTests.mm
API/FIRFieldsTests.mm
API/FIRNumericTransformTests.mm
API/FIRTypeTests.mm
API/FIRCursorTests.mm
API/FIRFirestoreSourceTests.mm
API/FIRQueryTests.mm
API/FIRValidationTests.mm
API/FIRDatabaseTests.mm
API/FIRListenerRegistrationTests.mm
API/FIRServerTimestampTests.mm
API/FIRWriteBatchTests.mm
DEPENDS
FirebaseFirestore
firebase_firestore_objc_test_util
)
endif(APPLE)
if(NOT APPLE)
return()
endif()

firebase_ios_objc_test(
firebase_firestore_objc_integration_test
HOST firebase_firestore_example_app
SOURCES
FSTSmokeTests.mm
FSTDatastoreTests.mm
FSTTransactionTests.mm
API/FIRArrayTransformTests.mm
API/FIRFieldsTests.mm
API/FIRNumericTransformTests.mm
API/FIRTypeTests.mm
API/FIRCursorTests.mm
API/FIRFirestoreSourceTests.mm
API/FIRQueryTests.mm
API/FIRValidationTests.mm
API/FIRDatabaseTests.mm
API/FIRListenerRegistrationTests.mm
API/FIRServerTimestampTests.mm
API/FIRWriteBatchTests.mm
DEPENDS
FirebaseFirestore
firebase_firestore_objc_test_util
)
6 changes: 3 additions & 3 deletions Firestore/Example/Tests/SpecTests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019 Google
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -13,9 +13,9 @@
# limitations under the License.

if(APPLE)
objc_test(
firebase_ios_objc_test(
firebase_firestore_objc_spec_test
HOST firestore_example_app_macos
HOST firebase_firestore_example_app
SOURCES
FSTLevelDBSpecTests.mm
FSTMemorySpecTests.mm
Expand Down
4 changes: 2 additions & 2 deletions Firestore/Example/Tests/Util/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019 Google
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -13,7 +13,7 @@
# limitations under the License.

if(APPLE)
cc_library(
firebase_ios_cc_library(
firebase_firestore_objc_test_util
HEADERS
FSTEventAccumulator.h
Expand Down
8 changes: 4 additions & 4 deletions Firestore/Protos/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2018 Google
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -33,6 +33,7 @@ set(
google/rpc/status
google/type/latlng
)

# Full filenames (i.e. with the .proto) from within the proto directory,
# excluding anything in google/protobuf
foreach(root ${PROTO_FILE_ROOTS})
Expand All @@ -58,6 +59,7 @@ set(
google/protobuf/timestamp
google/protobuf/wrappers
)

# Full filenames (i.e. with the .proto) from within the proto directory, from
# the google/protobuf package.
foreach(root ${WELL_KNOWN_PROTO_FILE_ROOTS})
Expand Down Expand Up @@ -111,7 +113,7 @@ function(snake_case_to_camel_case str var)
set(${var} ${str} PARENT_SCOPE)
endfunction()

cc_library(
firebase_ios_cc_library(
firebase_firestore_protos_nanopb
SOURCES
${NANOPB_GENERATED_SOURCES}
Expand Down Expand Up @@ -141,7 +143,6 @@ if(CXX_CLANG OR CXX_GNU)
)
endif()


target_include_directories(
firebase_firestore_protos_libprotobuf PUBLIC
${FIREBASE_SOURCE_DIR}/Firestore/Protos/cpp
Expand Down Expand Up @@ -172,7 +173,6 @@ add_custom_command(
${PROTOBUF_PROTO}
)


# Generate the python representation of nanopb's protos
set(NANOPB_DIR ${FIREBASE_BINARY_DIR}/external/src/nanopb)
set(
Expand Down
4 changes: 2 additions & 2 deletions Firestore/Source/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019 Google
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -18,7 +18,7 @@ if(APPLE)
${PROJECT_SOURCE_DIR}/FirebaseFirestore.podspec
)

objc_framework(
firebase_ios_objc_framework(
FirebaseFirestore
SHARED
HEADERS
Expand Down
Loading

0 comments on commit e404054

Please sign in to comment.