From 32bdc38400258b24edb37990cc8cba057a3297de Mon Sep 17 00:00:00 2001 From: Gil Date: Wed, 6 Dec 2017 16:10:59 -0800 Subject: Rework the top-level cmake build to be a superproject (#538) All projects are now ExternalProjects This makes it much easier to build them all in a single pass. --- .gitignore | 3 +++ CMAKE.md | 30 ++++++++++++++++++++++++++---- CMakeLists.txt | 23 ++++++++++------------- Firestore/CMakeLists.txt | 20 +++++++++++++++++--- Firestore/core/CMakeLists.txt | 16 ++++++++++++++++ cmake/external/firestore.cmake | 40 ++++++++++++++++++++++++++++++++++++++++ cmake/external/googletest.cmake | 40 ++++++++++------------------------------ cmake/utils.cmake | 4 +--- 8 files changed, 123 insertions(+), 53 deletions(-) create mode 100644 Firestore/core/CMakeLists.txt create mode 100644 cmake/external/firestore.cmake diff --git a/.gitignore b/.gitignore index 9a2e82e..93e3974 100644 --- a/.gitignore +++ b/.gitignore @@ -54,3 +54,6 @@ Carthage Pods/ Podfile.lock *.xcworkspace + +# CMake +.downloads diff --git a/CMAKE.md b/CMAKE.md index 09ce143..0ec1a94 100644 --- a/CMAKE.md +++ b/CMAKE.md @@ -16,6 +16,7 @@ the Mac App Store. You can get other development tools via [homebrew](https://brew.sh). Adjust as needed for other package managers. + ``` brew install cmake ``` @@ -51,12 +52,33 @@ cd build cmake .. ``` -## Testing +You only need to do this once. + +## Initial Build + +The first build will download, compile all dependencies of the project, and run +an initial battery of tests. + +To perform the initial build, you can use CMake + +``` +cmake --build . +``` + +or use the underlying build system, e.g. + +``` +make -j all +``` + +## Working with a Project + +Once the initial build has completed, you can work with a specific subproject +to make changes and test just that project in isolation. -Once CMake has run once, you can just run `make` repeatedly and it will -regenerate Makefiles as needed. +For example, to work with just Firestore, -To build everything and run tests: ``` +cd build/Firestore make -j all test ``` diff --git a/CMakeLists.txt b/CMakeLists.txt index 53b454d..f9e7527 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,22 +12,19 @@ # See the License for the specific language governing permissions and # limitations under the License. +# Superbuild for Firebase + cmake_minimum_required(VERSION 2.8.11) project(firebase C CXX) -# We use C++11 -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_EXTENSIONS OFF) - -# Fully qualified imports, project wide -include_directories("${PROJECT_SOURCE_DIR}") +list(INSERT CMAKE_MODULE_PATH 0 ${PROJECT_SOURCE_DIR}/cmake) -# CMake's test target does not build tests before running them. This adds a -# check target that -add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure) - -include(cmake/utils.cmake) +# External Projects install into this prefix and download into the source tree +# to avoid re-downloading repeatedly during development. +set(FIREBASE_INSTALL_DIR "${PROJECT_BINARY_DIR}/usr") +set(FIREBASE_DOWNLOAD_DIR "${PROJECT_SOURCE_DIR}/.downloads") enable_testing() -add_subdirectory(Firestore) + +include(external/googletest) +include(external/firestore) diff --git a/Firestore/CMakeLists.txt b/Firestore/CMakeLists.txt index 82e1903..6c2a32e 100644 --- a/Firestore/CMakeLists.txt +++ b/Firestore/CMakeLists.txt @@ -12,7 +12,21 @@ # See the License for the specific language governing permissions and # limitations under the License. -include(${PROJECT_SOURCE_DIR}/cmake/external/googletest.cmake) +cmake_minimum_required(VERSION 2.8.11) +project(firestore) -add_subdirectory(core/src/firebase/firestore/util) -add_subdirectory(core/test/firebase/firestore/util) +set(FIREBASE_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/..") +include("${FIREBASE_SOURCE_DIR}/cmake/utils.cmake") + +find_package(GTest REQUIRED) + +# We use C++11 +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +# Fully qualified imports, project wide +include_directories("${FIREBASE_SOURCE_DIR}") + +enable_testing() +add_subdirectory(core) diff --git a/Firestore/core/CMakeLists.txt b/Firestore/core/CMakeLists.txt new file mode 100644 index 0000000..c49b6db --- /dev/null +++ b/Firestore/core/CMakeLists.txt @@ -0,0 +1,16 @@ +# Copyright 2017 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_subdirectory(src/firebase/firestore/util) +add_subdirectory(test/firebase/firestore/util) diff --git a/cmake/external/firestore.cmake b/cmake/external/firestore.cmake new file mode 100644 index 0000000..5316873 --- /dev/null +++ b/cmake/external/firestore.cmake @@ -0,0 +1,40 @@ +# Copyright 2017 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(ExternalProject) + +set(source_dir ${PROJECT_SOURCE_DIR}/Firestore) +set(binary_dir ${PROJECT_BINARY_DIR}/Firestore) + +ExternalProject_Add( + Firestore + DEPENDS googletest + + # 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} + 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= +) diff --git a/cmake/external/googletest.cmake b/cmake/external/googletest.cmake index 66b2689..a956e9f 100644 --- a/cmake/external/googletest.cmake +++ b/cmake/external/googletest.cmake @@ -13,42 +13,22 @@ # limitations under the License. include(ExternalProject) + ExternalProject_Add( - googletest_external - PREFIX googletest + googletest + URL "https://github.com/google/googletest/archive/release-1.8.0.tar.gz" URL_HASH "SHA256=58a6f4277ca2bc8565222b3bbd58a177609e9c488e8a72649359ba51450db7d8" - CMAKE_ARGS - -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} - -DBUILD_GMOCK:BOOL=OFF - -DBUILD_GTEST:BOOL=ON + PREFIX ${PROJECT_BINARY_DIR}/third_party/googletest - # Cut down on scary log output - LOG_DOWNLOAD ON - LOG_CONFIGURE ON + DOWNLOAD_DIR ${FIREBASE_DOWNLOAD_DIR} + INSTALL_DIR ${FIREBASE_INSTALL_DIR} - INSTALL_COMMAND "" - UPDATE_COMMAND "" TEST_COMMAND "" -) - -ExternalProject_Get_Property(googletest_external source_dir binary_dir) -# CMake requires paths in include_directories to exist at configure time -file(MAKE_DIRECTORY ${source_dir}/googletest/include) - -add_library(gtest STATIC IMPORTED GLBOAL) -set_target_properties( - gtest PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES ${source_dir}/googletest/include - IMPORTED_LOCATION ${binary_dir}/googletest/${CMAKE_FIND_LIBRARY_PREFIXES}gtest.a -) -add_dependencies(gtest googletest_external) - -add_library(gtest_main STATIC IMPORTED GLOBAL) -set_target_properties( - gtest_main PROPERTIES - IMPORTED_LOCATION ${binary_dir}/googletest/${CMAKE_FIND_LIBRARY_PREFIXES}gtest_main.a + CMAKE_ARGS + -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} + -DCMAKE_INSTALL_PREFIX:PATH= + -DBUILD_SHARED_LIBS:BOOL=OFF ) -add_dependencies(gtest_main googletest_external) diff --git a/cmake/utils.cmake b/cmake/utils.cmake index 40e2325..54044d6 100644 --- a/cmake/utils.cmake +++ b/cmake/utils.cmake @@ -23,7 +23,5 @@ function(cc_test name) add_executable(${name} ${ARGN}) add_test(${name} ${name}) - target_link_libraries(${name} gtest gtest_main) - - add_dependencies(check ${name}) + target_link_libraries(${name} GTest::GTest GTest::Main) endfunction() -- cgit v1.2.3