Skip to content

Build gRPC for Firestore C++ #652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jan 13, 2018
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ set(FIREBASE_INSTALL_DIR ${PROJECT_BINARY_DIR})
enable_testing()

include(external/FirebaseCore)

include(external/googletest)
include(external/leveldb)
include(external/grpc)
include(external/firestore)
11 changes: 6 additions & 5 deletions Firestore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,24 @@
# 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)

find_package(GTest REQUIRED)
find_package(LevelDB REQUIRED)
find_package(GRPC REQUIRED)

if(APPLE)
find_package(FirebaseCore REQUIRED)
Expand All @@ -41,7 +42,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 +58,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)
3 changes: 3 additions & 0 deletions Firestore/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@
# limitations under the License.

add_subdirectory(src/firebase/firestore/util)
add_subdirectory(src/firebase/firestore/remote)

add_subdirectory(test/firebase/firestore/util)
add_subdirectory(test/firebase/firestore/remote)
23 changes: 23 additions & 0 deletions Firestore/core/src/firebase/firestore/remote/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 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.

add_library(
firebase_firestore_remote
datastore.h
datastore.cc
)
target_link_libraries(
firebase_firestore_remote
grpc::grpc
)
31 changes: 31 additions & 0 deletions Firestore/core/src/firebase/firestore/remote/datastore.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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 "Firestore/core/src/firebase/firestore/remote/datastore.h"

namespace firebase {
namespace firestore {
namespace remote {

Datastore::Datastore() {
}

Datastore::~Datastore() {
}

} // namespace remote
} // namespace firestore
} // namespace firebase
40 changes: 40 additions & 0 deletions Firestore/core/src/firebase/firestore/remote/datastore.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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.
*/

#ifndef FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_REMOTE_DATASTORE_H_
#define FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_REMOTE_DATASTORE_H_

namespace firebase {
namespace firestore {
namespace remote {

class Datastore {
public:
Datastore();
~Datastore();

Datastore(const Datastore& other) = delete;
Datastore(Datastore&& other) = delete;

Datastore& operator=(const Datastore& other) = delete;
Datastore& operator=(Datastore&& other) = delete;
};

} // namespace remote
} // namespace firestore
} // namespace firebase

#endif // FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_REMOTE_DATASTORE_H_
22 changes: 22 additions & 0 deletions Firestore/core/test/firebase/firestore/remote/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 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.

cc_test(
firebase_firestore_remote_test
datastore_test.cc
)
target_link_libraries(
firebase_firestore_remote_test
firebase_firestore_remote
)
28 changes: 28 additions & 0 deletions Firestore/core/test/firebase/firestore/remote/datastore_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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 "Firestore/core/src/firebase/firestore/remote/datastore.h"

#include <grpc/grpc.h>
#include <gtest/gtest.h>

TEST(Datastore, CanLinkToGrpc) {
// This test doesn't actually do anything interesting as far as actually
// using gRPC is concerned but that it can run at all is proof that all the
// libraries required for gRPC to work are actually linked correctly into the
// test.
grpc_init();
}
71 changes: 71 additions & 0 deletions cmake/ExternalProjectFlags.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# 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 making use of the
# latest features where available but avoiding them when run under CMake
# versions that don't support them.
#
# The complete set of git-related arguments are stored as a list in the
# variable named by RESULT_VAR in the calling scope.
#
# Currently this handles:
# * GIT_SUBMODULES -- added on CMake 3.0 or later. Earlier CMakes will
# check out all submodules.
# * GIT_SHALLOW -- added by default on CMake 3.6 or later. Disable by passing
# GIT_SHALLOW OFF
# * GIT_PROGRESS -- added by default on CMake 3.8 or later. Disable by
# passing GIT_PROGRESS OFF
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()
Loading