Skip to content

Commit 50cbfab

Browse files
authored
Reorganize cmake dependencies (#1508)
* Add cmake dependencies where required ... instead of relying on a topological sort in the top-level CMakeLists.txt. * Add early exits to external project builds
1 parent 954e4d5 commit 50cbfab

12 files changed

+200
-160
lines changed

CMakeLists.txt

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,5 @@ set(
4747

4848
enable_testing()
4949

50-
# These are ordered by a topological sort on DEPENDS attributes. This is
51-
# required because CMake fails the build if you have a DEPENDS on a target that
52-
# does not exist yet.
53-
include(external/GoogleUtilities)
54-
include(external/FirebaseCore)
55-
include(external/googletest)
56-
include(external/zlib)
57-
include(external/leveldb)
58-
include(external/protobuf)
59-
include(external/nanopb)
60-
include(external/c-ares)
61-
include(external/grpc)
50+
include(ExternalProject)
6251
include(external/firestore)

cmake/CompilerSetup.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,4 @@ if(APPLE)
9696

9797
-F${FIREBASE_INSTALL_DIR}/Frameworks
9898
)
99-
endif(APPLE)
99+
endif()

cmake/external/FirebaseCore.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414

1515
include(xcodebuild)
1616

17+
if(TARGET FirebaseCore)
18+
return()
19+
endif()
20+
1721
if(APPLE)
1822
# FirebaseCore is only available as a CocoaPod build.
1923
xcodebuild(FirebaseCore)

cmake/external/GoogleUtilities.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414

1515
include(xcodebuild)
1616

17+
if(TARGET GoogleUtilities)
18+
return()
19+
endif()
20+
1721
if(APPLE)
1822
# GoogleUtilities is only available as a CocoaPod build.
1923
xcodebuild(GoogleUtilities)

cmake/external/c-ares.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414

1515
include(ExternalProject)
1616

17+
if(TARGET c-ares)
18+
return()
19+
endif()
20+
1721
ExternalProject_Add(
1822
c-ares
1923

cmake/external/firestore.cmake

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,28 @@
1313
# limitations under the License.
1414

1515
include(ExternalProject)
16+
include(external/FirebaseCore)
17+
include(external/GoogleUtilities)
18+
include(external/googletest)
19+
include(external/grpc)
20+
include(external/leveldb)
21+
include(external/nanopb)
22+
include(external/protobuf)
23+
24+
if(TARGET Firestore)
25+
return()
26+
endif()
1627

1728
ExternalProject_Add(
1829
Firestore
1930
DEPENDS
2031
FirebaseCore
32+
GoogleUtilities
2133
googletest
22-
leveldb
2334
grpc
35+
leveldb
2436
nanopb
37+
protobuf
2538

2639
# Lay the binary directory out as if this were a subproject. This makes it
2740
# possible to build and test in it directly.

cmake/external/googletest.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414

1515
include(ExternalProject)
1616

17+
if(TARGET googletest)
18+
return()
19+
endif()
20+
1721
ExternalProject_Add(
1822
googletest
1923

cmake/external/grpc.cmake

Lines changed: 102 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -14,117 +14,122 @@
1414

1515
include(ExternalProject)
1616
include(ExternalProjectFlags)
17+
include(external/c-ares)
18+
include(external/protobuf)
19+
include(external/zlib)
20+
21+
if(TARGET grpc)
22+
return()
23+
endif()
1724

1825
if(GRPC_ROOT)
1926
# If the user has supplied a GRPC_ROOT then just use it. Add an empty custom
2027
# target so that the superbuild dependencies still work.
2128
add_custom_target(grpc)
22-
23-
else()
24-
set(
25-
GIT_SUBMODULES
26-
third_party/boringssl
27-
)
28-
29-
set(
30-
CMAKE_ARGS
31-
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
32-
-DBUILD_SHARED_LIBS:BOOL=OFF
33-
-DgRPC_BUILD_TESTS:BOOL=OFF
34-
35-
# TODO(rsgowman): We're currently building nanopb twice; once via grpc, and
36-
# once via nanopb. The version from grpc is the one that actually ends up
37-
# being used. We need to fix this such that either:
38-
# a) we instruct grpc to use our nanopb
39-
# b) we rely on grpc's nanopb instead of using our own.
40-
# For now, we'll pass in the necessary nanopb cflags into grpc. (We require
41-
# 16 bit fields. Without explicitly requesting this, nanopb uses 8 bit
42-
# fields.)
43-
-DCMAKE_C_FLAGS=-DPB_FIELD_16BIT
44-
-DCMAKE_CXX_FLAGS=-DPB_FIELD_16BIT
45-
)
46-
47-
48-
## c-ares
49-
if(NOT c-ares_DIR)
50-
set(c-ares_DIR ${FIREBASE_INSTALL_DIR}/lib/cmake/c-ares)
51-
endif()
52-
53-
list(
54-
APPEND CMAKE_ARGS
55-
-DgRPC_CARES_PROVIDER:STRING=package
56-
-Dc-ares_DIR:PATH=${c-ares_DIR}
57-
)
58-
59-
60-
## protobuf
61-
62-
# Unlike other dependencies of gRPC, we control the protobuf version because we
63-
# have checked-in protoc outputs that must match the runtime.
64-
65-
# The location where protobuf-config.cmake will be installed varies by platform
66-
if(NOT Protobuf_DIR)
67-
if(WIN32)
68-
set(Protobuf_DIR "${FIREBASE_INSTALL_DIR}/cmake")
69-
else()
70-
set(Protobuf_DIR "${FIREBASE_INSTALL_DIR}/lib/cmake/protobuf")
71-
endif()
29+
return()
30+
endif()
31+
32+
set(
33+
GIT_SUBMODULES
34+
third_party/boringssl
35+
)
36+
37+
set(
38+
CMAKE_ARGS
39+
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
40+
-DBUILD_SHARED_LIBS:BOOL=OFF
41+
-DgRPC_BUILD_TESTS:BOOL=OFF
42+
43+
# TODO(rsgowman): We're currently building nanopb twice; once via grpc, and
44+
# once via nanopb. The version from grpc is the one that actually ends up
45+
# being used. We need to fix this such that either:
46+
# a) we instruct grpc to use our nanopb
47+
# b) we rely on grpc's nanopb instead of using our own.
48+
# For now, we'll pass in the necessary nanopb cflags into grpc. (We require
49+
# 16 bit fields. Without explicitly requesting this, nanopb uses 8 bit
50+
# fields.)
51+
-DCMAKE_C_FLAGS=-DPB_FIELD_16BIT
52+
-DCMAKE_CXX_FLAGS=-DPB_FIELD_16BIT
53+
)
54+
55+
56+
## c-ares
57+
if(NOT c-ares_DIR)
58+
set(c-ares_DIR ${FIREBASE_INSTALL_DIR}/lib/cmake/c-ares)
59+
endif()
60+
61+
list(
62+
APPEND CMAKE_ARGS
63+
-DgRPC_CARES_PROVIDER:STRING=package
64+
-Dc-ares_DIR:PATH=${c-ares_DIR}
65+
)
66+
67+
68+
## protobuf
69+
70+
# Unlike other dependencies of gRPC, we control the protobuf version because we
71+
# have checked-in protoc outputs that must match the runtime.
72+
73+
# The location where protobuf-config.cmake will be installed varies by platform
74+
if(NOT Protobuf_DIR)
75+
if(WIN32)
76+
set(Protobuf_DIR "${FIREBASE_INSTALL_DIR}/cmake")
77+
else()
78+
set(Protobuf_DIR "${FIREBASE_INSTALL_DIR}/lib/cmake/protobuf")
7279
endif()
73-
74-
list(
75-
APPEND CMAKE_ARGS
76-
-DgRPC_PROTOBUF_PROVIDER:STRING=package
77-
-DgRPC_PROTOBUF_PACKAGE_TYPE:STRING=CONFIG
78-
-DProtobuf_DIR:PATH=${Protobuf_DIR}
79-
)
80-
81-
82-
## zlib
83-
84-
# cmake/external/zlib.cmake figures out whether or not to build zlib. Either
85-
# way, from the gRPC build's point of view it's a package.
80+
endif()
81+
82+
list(
83+
APPEND CMAKE_ARGS
84+
-DgRPC_PROTOBUF_PROVIDER:STRING=package
85+
-DgRPC_PROTOBUF_PACKAGE_TYPE:STRING=CONFIG
86+
-DProtobuf_DIR:PATH=${Protobuf_DIR}
87+
)
88+
89+
90+
## zlib
91+
92+
# cmake/external/zlib.cmake figures out whether or not to build zlib. Either
93+
# way, from the gRPC build's point of view it's a package.
94+
list(
95+
APPEND CMAKE_ARGS
96+
-DgRPC_ZLIB_PROVIDER:STRING=package
97+
)
98+
if(ZLIB_FOUND)
99+
# Propagate possible user configuration to FindZLIB.cmake in the sub-build.
86100
list(
87101
APPEND CMAKE_ARGS
88-
-DgRPC_ZLIB_PROVIDER:STRING=package
102+
-DZLIB_INCLUDE_DIR=${ZLIB_INCLUDE_DIR}
103+
-DZLIB_LIBRARY=${ZLIB_LIBRARY}
89104
)
90-
if(ZLIB_FOUND)
91-
# Propagate possible user configuration to FindZLIB.cmake in the sub-build.
92-
list(
93-
APPEND CMAKE_ARGS
94-
-DZLIB_INCLUDE_DIR=${ZLIB_INCLUDE_DIR}
95-
-DZLIB_LIBRARY=${ZLIB_LIBRARY}
96-
)
97-
endif()
105+
endif()
98106

99107

100-
ExternalProject_GitSource(
101-
GRPC_GIT
102-
GIT_REPOSITORY "https://github.com/grpc/grpc.git"
103-
GIT_TAG "v1.8.3"
104-
GIT_SUBMODULES ${GIT_SUBMODULES}
105-
)
108+
ExternalProject_GitSource(
109+
GRPC_GIT
110+
GIT_REPOSITORY "https://github.com/grpc/grpc.git"
111+
GIT_TAG "v1.8.3"
112+
GIT_SUBMODULES ${GIT_SUBMODULES}
113+
)
106114

107-
ExternalProject_Add(
108-
grpc
109-
DEPENDS
110-
c-ares
111-
protobuf
112-
zlib
115+
ExternalProject_Add(
116+
grpc
117+
DEPENDS
118+
c-ares
119+
protobuf
120+
zlib
113121

114-
${GRPC_GIT}
122+
${GRPC_GIT}
115123

116-
PREFIX ${PROJECT_BINARY_DIR}/external/grpc
124+
PREFIX ${PROJECT_BINARY_DIR}/external/grpc
117125

118-
CMAKE_ARGS
119-
${CMAKE_ARGS}
120-
121-
BUILD_COMMAND
122-
${CMAKE_COMMAND} --build . --target grpc
123-
124-
UPDATE_COMMAND ""
125-
TEST_COMMAND ""
126-
INSTALL_COMMAND ""
127-
)
126+
CMAKE_ARGS
127+
${CMAKE_ARGS}
128128

129-
endif(GRPC_ROOT)
129+
BUILD_COMMAND
130+
${CMAKE_COMMAND} --build . --target grpc
130131

132+
UPDATE_COMMAND ""
133+
TEST_COMMAND ""
134+
INSTALL_COMMAND ""
135+
)

0 commit comments

Comments
 (0)