Skip to content

Commit b15283b

Browse files
authored
Build gRPC for Firestore C++ (#652)
* Clean up quoting and other minor issues * Reorganize CMake build output Make it clearer which parts of the output pertain to external projects. * Use a consistent ordering of ExternalProject arguments * Prevent the top-level build from running in parallel This prevents spurious failures when running make -j. * Actually parse arguments in the xcodebuild function * Use ExternalProject features when available * submodule limits from CMake 3.0 * shallow clones from CMake 3.6 * git progress output from CMake 3.8 * Only build the parts of leveldb we need Skip building the tools and other libraries * Avoid installing ExternalProjects Consume build output directly so that we can build just the targets we need. Installing causes all targets to be built. This doesn't matter as much for these targets but the gRPC build includes a ton of stuff we don't need so it's worth adopting this as a general strategy. * Define an external build for grpc * Test that grpc can link successfully. * Add a FindGRPC CMake module * Actually comment ExternalProjext_GitSource
1 parent b5454f1 commit b15283b

File tree

16 files changed

+522
-40
lines changed

16 files changed

+522
-40
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ set(FIREBASE_INSTALL_DIR ${PROJECT_BINARY_DIR})
3737
enable_testing()
3838

3939
include(external/FirebaseCore)
40-
4140
include(external/googletest)
4241
include(external/leveldb)
42+
include(external/grpc)
4343
include(external/firestore)

Firestore/CMakeLists.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,24 @@
1313
# limitations under the License.
1414

1515
cmake_minimum_required(VERSION 2.8.11)
16-
project(firestore)
16+
project(firestore C CXX)
1717

18-
set(FIREBASE_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/..")
18+
set(FIREBASE_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/..)
1919

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

2828
list(INSERT CMAKE_MODULE_PATH 0 ${FIREBASE_SOURCE_DIR}/cmake)
2929
include(utils)
3030

3131
find_package(GTest REQUIRED)
3232
find_package(LevelDB REQUIRED)
33+
find_package(GRPC REQUIRED)
3334

3435
if(APPLE)
3536
find_package(FirebaseCore REQUIRED)
@@ -41,7 +42,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
4142
set(CMAKE_CXX_EXTENSIONS OFF)
4243

4344
# Fully qualified imports, project wide
44-
include_directories("${FIREBASE_SOURCE_DIR}")
45+
include_directories(${FIREBASE_SOURCE_DIR})
4546

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

5960
enable_testing()
60-
add_subdirectory(third_party/abseil-cpp EXCLUDE_FROM_ALL)
61+
add_subdirectory(third_party/abseil-cpp)
6162
add_subdirectory(core)

Firestore/core/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@
1313
# limitations under the License.
1414

1515
add_subdirectory(src/firebase/firestore/util)
16+
add_subdirectory(src/firebase/firestore/remote)
17+
1618
add_subdirectory(test/firebase/firestore/util)
19+
add_subdirectory(test/firebase/firestore/remote)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2018 Google
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+
add_library(
16+
firebase_firestore_remote
17+
datastore.h
18+
datastore.cc
19+
)
20+
target_link_libraries(
21+
firebase_firestore_remote
22+
grpc::grpc
23+
)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2018 Google
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "Firestore/core/src/firebase/firestore/remote/datastore.h"
18+
19+
namespace firebase {
20+
namespace firestore {
21+
namespace remote {
22+
23+
Datastore::Datastore() {
24+
}
25+
26+
Datastore::~Datastore() {
27+
}
28+
29+
} // namespace remote
30+
} // namespace firestore
31+
} // namespace firebase
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2018 Google
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_REMOTE_DATASTORE_H_
18+
#define FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_REMOTE_DATASTORE_H_
19+
20+
namespace firebase {
21+
namespace firestore {
22+
namespace remote {
23+
24+
class Datastore {
25+
public:
26+
Datastore();
27+
~Datastore();
28+
29+
Datastore(const Datastore& other) = delete;
30+
Datastore(Datastore&& other) = delete;
31+
32+
Datastore& operator=(const Datastore& other) = delete;
33+
Datastore& operator=(Datastore&& other) = delete;
34+
};
35+
36+
} // namespace remote
37+
} // namespace firestore
38+
} // namespace firebase
39+
40+
#endif // FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_REMOTE_DATASTORE_H_
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright 2018 Google
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+
cc_test(
16+
firebase_firestore_remote_test
17+
datastore_test.cc
18+
)
19+
target_link_libraries(
20+
firebase_firestore_remote_test
21+
firebase_firestore_remote
22+
)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2018 Google
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "Firestore/core/src/firebase/firestore/remote/datastore.h"
18+
19+
#include <grpc/grpc.h>
20+
#include <gtest/gtest.h>
21+
22+
TEST(Datastore, CanLinkToGrpc) {
23+
// This test doesn't actually do anything interesting as far as actually
24+
// using gRPC is concerned but that it can run at all is proof that all the
25+
// libraries required for gRPC to work are actually linked correctly into the
26+
// test.
27+
grpc_init();
28+
}

cmake/ExternalProjectFlags.cmake

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Copyright 2018 Google
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+
include(CMakeParseArguments)
16+
17+
# Assemble the git-related arguments to an external project making use of the
18+
# latest features where available but avoiding them when run under CMake
19+
# versions that don't support them.
20+
#
21+
# The complete set of git-related arguments are stored as a list in the
22+
# variable named by RESULT_VAR in the calling scope.
23+
#
24+
# Currently this handles:
25+
# * GIT_SUBMODULES -- added on CMake 3.0 or later. Earlier CMakes will
26+
# check out all submodules.
27+
# * GIT_SHALLOW -- added by default on CMake 3.6 or later. Disable by passing
28+
# GIT_SHALLOW OFF
29+
# * GIT_PROGRESS -- added by default on CMake 3.8 or later. Disable by
30+
# passing GIT_PROGRESS OFF
31+
function(ExternalProject_GitSource RESULT_VAR)
32+
# Parse arguments
33+
set(options "")
34+
set(single_value GIT_REPOSITORY GIT_TAG GIT_PROGRESS GIT_SHALLOW)
35+
set(multi_value GIT_SUBMODULES)
36+
cmake_parse_arguments(EP "${options}" "${single_value}" "${multi_value}" ${ARGN})
37+
38+
set(
39+
result
40+
GIT_REPOSITORY ${EP_GIT_REPOSITORY}
41+
GIT_TAG ${EP_GIT_TAG}
42+
${EP_UNPARSED_ARGUMENTS}
43+
)
44+
45+
# CMake 3.0 added support for constraining the set of submodules to clone
46+
if(NOT (CMAKE_VERSION VERSION_LESS "3.0") AND EP_GIT_SUBMODULES)
47+
list(APPEND result GIT_SUBMODULES ${EP_GIT_SUBMODULES})
48+
endif()
49+
50+
# CMake 3.6 added support for shallow git clones. Use a shallow clone if
51+
# available
52+
if(NOT (CMAKE_VERSION VERSION_LESS "3.6"))
53+
if(NOT EP_GIT_SHALLOW)
54+
set(EP_GIT_SHALLOW ON)
55+
endif()
56+
57+
list(APPEND result GIT_SHALLOW ${EP_GIT_SHALLOW})
58+
endif()
59+
60+
# CMake 3.8 added support for showing progress for large downloads
61+
if(NOT (CMAKE_VERSION VERSION_LESS "3.8"))
62+
if(NOT EP_GIT_PROGRESS)
63+
set(EP_GIT_PROGRESS ON)
64+
endif()
65+
66+
list(APPEND result GIT_PROGRESS ${EP_GIT_PROGRESS})
67+
endif()
68+
69+
set(${RESULT_VAR} ${result} PARENT_SCOPE)
70+
71+
endfunction()

0 commit comments

Comments
 (0)