Skip to content
Merged
10 changes: 5 additions & 5 deletions Firestore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
# limitations under the License.

cmake_minimum_required(VERSION 2.8.11)
project(firestore)
project(firestore C CXX)

set(FIREBASE_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/..")
set(FIREBASE_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/..)

# CMAKE_INSTALL_PREFIX should be passed in to this build so that it can find
# outputs of the superbuild. This is handled automatically if run via the
# superbuild (i.e. by invoking cmake on the directory above this).
#
# If you want to use this project directly in e.g. CLion, make sure you
# configure this.
set(FIREBASE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}")
set(FIREBASE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX})

list(INSERT CMAKE_MODULE_PATH 0 ${FIREBASE_SOURCE_DIR}/cmake)
include(utils)
Expand All @@ -41,7 +41,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# Fully qualified imports, project wide
include_directories("${FIREBASE_SOURCE_DIR}")
include_directories(${FIREBASE_SOURCE_DIR})

if(APPLE)
# CMake has no special support for Objective-C as a distinct language but enabling modules and
Expand All @@ -57,5 +57,5 @@ if(APPLE)
endif(APPLE)

enable_testing()
add_subdirectory(third_party/abseil-cpp EXCLUDE_FROM_ALL)
add_subdirectory(third_party/abseil-cpp)
add_subdirectory(core)
58 changes: 58 additions & 0 deletions cmake/ExternalProjectFlags.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Copyright 2018 Google
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

include(CMakeParseArguments)

# Assemble the git-related arguments to an external project in a way that
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: complete the sentence?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies. Now fully commented.

function(ExternalProject_GitSource RESULT_VAR)
# Parse arguments
set(options "")
set(single_value GIT_REPOSITORY GIT_TAG GIT_PROGRESS GIT_SHALLOW)
set(multi_value GIT_SUBMODULES)
cmake_parse_arguments(EP "${options}" "${single_value}" "${multi_value}" ${ARGN})

set(
result
GIT_REPOSITORY ${EP_GIT_REPOSITORY}
GIT_TAG ${EP_GIT_TAG}
${EP_UNPARSED_ARGUMENTS}
)

# CMake 3.0 added support for constraining the set of submodules to clone
if(NOT (CMAKE_VERSION VERSION_LESS "3.0") AND EP_GIT_SUBMODULES)
list(APPEND result GIT_SUBMODULES ${EP_GIT_SUBMODULES})
endif()

# CMake 3.6 added support for shallow git clones. Use a shallow clone if
# available
if(NOT (CMAKE_VERSION VERSION_LESS "3.6"))
if(NOT EP_GIT_SHALLOW)
set(EP_GIT_SHALLOW ON)
endif()

list(APPEND result GIT_SHALLOW ${EP_GIT_SHALLOW})
endif()

# CMake 3.8 added support for showing progress for large downloads
if(NOT (CMAKE_VERSION VERSION_LESS "3.8"))
if(NOT EP_GIT_PROGRESS)
set(EP_GIT_PROGRESS ON)
endif()

list(APPEND result GIT_PROGRESS ${EP_GIT_PROGRESS})
endif()

set(${RESULT_VAR} ${result} PARENT_SCOPE)

endfunction()
2 changes: 1 addition & 1 deletion cmake/FindLevelDB.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

set(binary_dir ${FIREBASE_INSTALL_DIR}/third_party/leveldb/src/leveldb)
set(binary_dir ${FIREBASE_INSTALL_DIR}/external/leveldb/src/leveldb)

find_path(
LEVELDB_INCLUDE_DIR leveldb/db.h
Expand Down
27 changes: 13 additions & 14 deletions cmake/external/firestore.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,26 @@

include(ExternalProject)

set(source_dir ${PROJECT_SOURCE_DIR}/Firestore)
set(binary_dir ${PROJECT_BINARY_DIR}/Firestore)

ExternalProject_Add(
Firestore
DEPENDS FirebaseCore googletest leveldb
DEPENDS
FirebaseCore
googletest
leveldb

# Lay the binary directory out as if this were a subproject. This makes it
# possible to build and test in it directly.
PREFIX ${binary_dir}
SOURCE_DIR ${source_dir}
BINARY_DIR ${binary_dir}
PREFIX ${PROJECT_BINARY_DIR}/external/Firestore
SOURCE_DIR ${PROJECT_SOURCE_DIR}/Firestore
BINARY_DIR ${PROJECT_BINARY_DIR}/Firestore

CMAKE_ARGS
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
-DCMAKE_INSTALL_PREFIX:PATH=${FIREBASE_INSTALL_DIR}
${GTEST_CMAKE_ARGS}

BUILD_ALWAYS ON

# Even though this isn't installed, set up the INSTALL_DIR so that
# find_package can find dependencies built from source.
INSTALL_DIR ${FIREBASE_INSTALL_DIR}
INSTALL_COMMAND ""
TEST_BEFORE_INSTALL ON

CMAKE_ARGS
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
)
39 changes: 31 additions & 8 deletions cmake/external/googletest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,44 @@
# limitations under the License.

include(ExternalProject)
include(ExternalProjectFlags)

ExternalProject_GitSource(
GOOGLETEST_GIT
GIT_REPOSITORY "https://github.com/google/googletest.git"
GIT_TAG "release-1.8.0"
)

ExternalProject_Add(
googletest
DEPENDS
FirebaseCore # for sequencing

GIT_REPOSITORY "https://github.com/google/googletest.git"
GIT_TAG "release-1.8.0"
${GOOGLETEST_GIT}

PREFIX ${PROJECT_BINARY_DIR}/third_party/googletest
PREFIX ${PROJECT_BINARY_DIR}/external/googletest

INSTALL_DIR ${FIREBASE_INSTALL_DIR}
CMAKE_ARGS
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
-DBUILD_SHARED_LIBS:BOOL=OFF

INSTALL_COMMAND ""
TEST_COMMAND ""
)

CMAKE_ARGS
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
-DBUILD_SHARED_LIBS:BOOL=OFF
ExternalProject_Get_Property(
googletest
SOURCE_DIR BINARY_DIR
)

# Arguments to pass to another CMake invocation so that it can find googletest
# without installing it using the standard FindGTest module.
set(GTEST_INCLUDE_DIR ${SOURCE_DIR}/googletest/include)
set(GTEST_LIBRARY ${BINARY_DIR}/googlemock/gtest/libgtest.a)
set(GTEST_MAIN_LIBRARY ${BINARY_DIR}/googlemock/gtest/libgtest_main.a)
set(
GTEST_CMAKE_ARGS
-DGTEST_INCLUDE_DIR=${GTEST_INCLUDE_DIR}
-DGTEST_LIBRARY=${GTEST_LIBRARY}
-DGTEST_MAIN_LIBRARY=${GTEST_MAIN_LIBRARY}
)
26 changes: 21 additions & 5 deletions cmake/external/leveldb.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

include(ExternalProject)
include(ExternalProjectFlags)

if(WIN32 OR LEVELDB_ROOT)
# If the user has supplied a LEVELDB_ROOT then just use it. Add an empty
Expand Down Expand Up @@ -41,23 +42,38 @@ else()
$<$<CONFIG:Release>:${CMAKE_CXX_FLAGS_RELEASE}>"
)

ExternalProject_GitSource(
LEVELDB_GIT
GIT_REPOSITORY "https://github.com/google/leveldb.git"
GIT_TAG "v1.20"
)

ExternalProject_Add(
leveldb
DEPENDS
googletest # for sequencing

GIT_REPOSITORY "https://github.com/google/leveldb.git"
GIT_TAG "v1.20"
${LEVELDB_GIT}

PREFIX ${PROJECT_BINARY_DIR}/third_party/leveldb
PREFIX ${PROJECT_BINARY_DIR}/external/leveldb

# LevelDB's configuration is done in the Makefile
CONFIGURE_COMMAND ""
BUILD_ALWAYS ON

# The Makefile-based build of leveldb does not support building
# out-of-source.
BUILD_IN_SOURCE ON

# Only build the leveldb library skipping the tools and in-memory
# implementation we don't use.
BUILD_COMMAND
env CXXFLAGS=${LEVELDB_CXX_FLAGS} OPT=${LEVELDB_OPT} make -j all
env CXXFLAGS=${LEVELDB_CXX_FLAGS} OPT=${LEVELDB_OPT}
make -j out-static/libleveldb.a

INSTALL_DIR ${FIREBASE_INSTALL_DIR}

INSTALL_COMMAND ""
TEST_COMMAND ""
)

endif(WIN32 OR LEVELDB_ROOT)
11 changes: 5 additions & 6 deletions cmake/xcodebuild.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function(xcodebuild framework)
set(options "")
set(single_value SCHEME WORKSPACE)
set(multi_value DEPENDS)
cmake_parse_arguments(xcb "${options}" "${single_value}" "${multi_value}")
cmake_parse_arguments(xcb "${options}" "${single_value}" "${multi_value}" ${ARGN})

if(NOT xcb_WORKSPACE)
set(xcb_WORKSPACE ${PROJECT_SOURCE_DIR}/Example/Firebase.xcworkspace)
Expand All @@ -46,8 +46,6 @@ function(xcodebuild framework)
set(destination "platform=macOS,arch=x86_64")
set(scheme "${framework}-${platform}")

set(binary_dir ${PROJECT_BINARY_DIR}/${scheme})

# CMake has a variety of release types, but Xcode has just one by default.
if(CMAKE_BUILD_TYPE STREQUAL Debug)
set(configuration Debug)
Expand All @@ -65,11 +63,11 @@ function(xcodebuild framework)
${framework}
DEPENDS ${xcb_DEPENDS}

PREFIX ${binary_dir}
PREFIX ${PROJECT_BINARY_DIR}/external/${framework}

# The source directory doesn't actually matter
SOURCE_DIR ${PROJECT_SOURCE_DIR}
BINARY_DIR ${binary_dir}
BINARY_DIR ${PROJECT_BINARY_DIR}/Frameworks

CONFIGURE_COMMAND ""

Expand All @@ -79,12 +77,13 @@ function(xcodebuild framework)
-scheme ${scheme}
-configuration ${configuration}
-destination ${destination}
CONFIGURATION_BUILD_DIR=${FIREBASE_INSTALL_DIR}/Frameworks
CONFIGURATION_BUILD_DIR=<BINARY_DIR>
build
${pipe_xcpretty}
BUILD_ALWAYS ${BUILD_PODS}

INSTALL_COMMAND ""
TEST_COMMAND ""
)

endfunction()