diff options
author | Jan Tattermusch <jtattermusch@google.com> | 2017-12-19 14:05:41 -0800 |
---|---|---|
committer | Jan Tattermusch <jtattermusch@google.com> | 2017-12-19 14:05:41 -0800 |
commit | f38b1526f8981698cdd512694cd65d75073db60f (patch) | |
tree | abfabefb6ea008234573b429f617bfea91ae003a /templates/CMakeLists.txt.template | |
parent | 1c4d410c109157bfe924144bc777e57169d5c1e3 (diff) |
simplify top level CMakeLists.txt
Diffstat (limited to 'templates/CMakeLists.txt.template')
-rw-r--r-- | templates/CMakeLists.txt.template | 183 |
1 files changed, 6 insertions, 177 deletions
diff --git a/templates/CMakeLists.txt.template b/templates/CMakeLists.txt.template index 5ef34e47ad..8de0ccde82 100644 --- a/templates/CMakeLists.txt.template +++ b/templates/CMakeLists.txt.template @@ -147,183 +147,12 @@ set(_gRPC_PROTOBUF_LIBRARY_NAME "libprotobuf") endif() - if("<%text>${gRPC_ZLIB_PROVIDER}</%text>" STREQUAL "module") - if(NOT ZLIB_ROOT_DIR) - set(ZLIB_ROOT_DIR <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>/third_party/zlib) - endif() - set(ZLIB_INCLUDE_DIR "<%text>${ZLIB_ROOT_DIR}</%text>") - if(EXISTS "<%text>${ZLIB_ROOT_DIR}</%text>/CMakeLists.txt") - # TODO(jtattermusch): workaround for https://github.com/madler/zlib/issues/218 - include_directories(<%text>${ZLIB_INCLUDE_DIR}</%text>) - - add_subdirectory(<%text>${ZLIB_ROOT_DIR}</%text> third_party/zlib) - if(TARGET zlibstatic) - set(_gRPC_ZLIB_LIBRARIES zlibstatic) - endif() - else() - message(WARNING "gRPC_ZLIB_PROVIDER is \"module\" but ZLIB_ROOT_DIR is wrong") - endif() - if(gRPC_INSTALL) - message(WARNING "gRPC_INSTALL will be forced to FALSE because gRPC_ZLIB_PROVIDER is \"module\"") - set(gRPC_INSTALL FALSE) - endif() - elseif("<%text>${gRPC_ZLIB_PROVIDER}</%text>" STREQUAL "package") - find_package(ZLIB REQUIRED) - set(_gRPC_ZLIB_LIBRARIES <%text>${ZLIB_LIBRARIES}</%text>) - set(_gRPC_FIND_ZLIB "if(NOT ZLIB_FOUND)\n find_package(ZLIB)\nendif()") - endif() - - if("<%text>${gRPC_CARES_PROVIDER}</%text>" STREQUAL "module") - if(NOT CARES_ROOT_DIR) - set(CARES_ROOT_DIR <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>/third_party/cares/cares) - endif() - set(CARES_SHARED OFF CACHE BOOL "disable shared library") - set(CARES_STATIC ON CACHE BOOL "link cares statically") - set(CARES_INCLUDE_DIR "<%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>/third_party/cares/cares") - add_subdirectory(third_party/cares/cares) - if(TARGET c-ares) - set(_gRPC_CARES_LIBRARIES c-ares) - endif() - if(gRPC_INSTALL) - message(WARNING "gRPC_INSTALL will be forced to FALSE because gRPC_CARES_PROVIDER is \"module\"") - set(gRPC_INSTALL FALSE) - endif() - elseif("<%text>${gRPC_CARES_PROVIDER}</%text>" STREQUAL "package") - find_package(c-ares REQUIRED CONFIG) - if(TARGET c-ares::cares) - set(_gRPC_CARES_LIBRARIES c-ares::cares) - endif() - set(_gRPC_FIND_CARES "if(NOT c-ares_FOUND)\n find_package(c-ares CONFIG)\nendif()") - endif() - - if("<%text>${gRPC_PROTOBUF_PROVIDER}</%text>" STREQUAL "module") - # Building the protobuf tests require gmock what is not part of a standard protobuf checkout. - # Disable them unless they are explicitly requested from the cmake command line (when we assume - # gmock is downloaded to the right location inside protobuf). - if(NOT protobuf_BUILD_TESTS) - set(protobuf_BUILD_TESTS OFF CACHE BOOL "Build protobuf tests") - endif() - # Disable building protobuf with zlib. Building protobuf with zlib breaks - # the build if zlib is not installed on the system. - if(NOT protobuf_WITH_ZLIB) - set(protobuf_WITH_ZLIB OFF CACHE BOOL "Build protobuf with zlib.") - endif() - if(NOT PROTOBUF_ROOT_DIR) - set(PROTOBUF_ROOT_DIR <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>/third_party/protobuf) - endif() - set(PROTOBUF_WELLKNOWN_IMPORT_DIR <%text>${PROTOBUF_ROOT_DIR}</%text>/src) - if(EXISTS "<%text>${PROTOBUF_ROOT_DIR}</%text>/cmake/CMakeLists.txt") - set(protobuf_MSVC_STATIC_RUNTIME OFF CACHE BOOL "Link static runtime libraries") - add_subdirectory(<%text>${PROTOBUF_ROOT_DIR}</%text>/cmake third_party/protobuf) - if(TARGET <%text>${_gRPC_PROTOBUF_LIBRARY_NAME}</%text>) - set(_gRPC_PROTOBUF_LIBRARIES <%text>${_gRPC_PROTOBUF_LIBRARY_NAME}</%text>) - endif() - if(TARGET libprotoc) - set(_gRPC_PROTOBUF_PROTOC_LIBRARIES libprotoc) - endif() - if(TARGET protoc) - set(_gRPC_PROTOBUF_PROTOC protoc) - set(_gRPC_PROTOBUF_PROTOC_EXECUTABLE $<TARGET_FILE:protoc>) - endif() - else() - message(WARNING "gRPC_PROTOBUF_PROVIDER is \"module\" but PROTOBUF_ROOT_DIR is wrong") - endif() - if(gRPC_INSTALL) - message(WARNING "gRPC_INSTALL will be forced to FALSE because gRPC_PROTOBUF_PROVIDER is \"module\"") - set(gRPC_INSTALL FALSE) - endif() - elseif("<%text>${gRPC_PROTOBUF_PROVIDER}</%text>" STREQUAL "package") - find_package(Protobuf REQUIRED <%text>${gRPC_PROTOBUF_PACKAGE_TYPE}</%text>) - if(Protobuf_FOUND OR PROTOBUF_FOUND) - if(TARGET protobuf::<%text>${_gRPC_PROTOBUF_LIBRARY_NAME}</%text>) - set(_gRPC_PROTOBUF_LIBRARIES protobuf::<%text>${_gRPC_PROTOBUF_LIBRARY_NAME}</%text>) - else() - set(_gRPC_PROTOBUF_LIBRARIES <%text>${PROTOBUF_LIBRARIES}</%text>) - endif() - if(TARGET protobuf::libprotoc) - set(_gRPC_PROTOBUF_PROTOC_LIBRARIES protobuf::libprotoc) - else() - set(_gRPC_PROTOBUF_PROTOC_LIBRARIES <%text>${PROTOBUF_PROTOC_LIBRARIES}</%text>) - endif() - if(TARGET protobuf::protoc) - set(_gRPC_PROTOBUF_PROTOC protobuf::protoc) - set(_gRPC_PROTOBUF_PROTOC_EXECUTABLE $<TARGET_FILE:protobuf::protoc>) - else() - set(_gRPC_PROTOBUF_PROTOC <%text>${PROTOBUF_PROTOC_EXECUTABLE}</%text>) - set(_gRPC_PROTOBUF_PROTOC_EXECUTABLE <%text>${PROTOBUF_PROTOC_EXECUTABLE}</%text>) - endif() - set(_gRPC_FIND_PROTOBUF "if(NOT Protobuf_FOUND AND NOT PROTOBUF_FOUND)\n find_package(Protobuf <%text>${gRPC_PROTOBUF_PACKAGE_TYPE}</%text>)\nendif()") - endif() - if(PROTOBUF_FOUND) - include_directories(<%text>${PROTOBUF_INCLUDE_DIRS}</%text>) - endif() - set(PROTOBUF_WELLKNOWN_IMPORT_DIR /usr/local/include) - endif() - - if("<%text>${gRPC_SSL_PROVIDER}</%text>" STREQUAL "module") - if(NOT BORINGSSL_ROOT_DIR) - set(BORINGSSL_ROOT_DIR <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>/third_party/boringssl) - endif() - if(EXISTS "<%text>${BORINGSSL_ROOT_DIR}</%text>/CMakeLists.txt") - set(OPENSSL_NO_ASM ON) # make boringssl buildable with Visual Studio - add_subdirectory(<%text>${BORINGSSL_ROOT_DIR}</%text> third_party/boringssl) - if(TARGET ssl) - set(_gRPC_SSL_LIBRARIES ssl) - set(_gRPC_SSL_INCLUDE_DIR <%text>${BORINGSSL_ROOT_DIR}</%text>/include) - endif() - else() - message(WARNING "gRPC_SSL_PROVIDER is \"module\" but BORINGSSL_ROOT_DIR is wrong") - endif() - if(gRPC_INSTALL) - message(WARNING "gRPC_INSTALL will be forced to FALSE because gRPC_SSL_PROVIDER is \"module\"") - set(gRPC_INSTALL FALSE) - endif() - elseif("<%text>${gRPC_SSL_PROVIDER}</%text>" STREQUAL "package") - find_package(OpenSSL REQUIRED) - set(_gRPC_SSL_LIBRARIES <%text>${OPENSSL_LIBRARIES}</%text>) - set(_gRPC_SSL_INCLUDE_DIR <%text>${OPENSSL_INCLUDE_DIR}</%text>) - set(_gRPC_FIND_SSL "if(NOT OPENSSL_FOUND)\n find_package(OpenSSL)\nendif()") - endif() - - if("<%text>${gRPC_GFLAGS_PROVIDER}</%text>" STREQUAL "module") - if(NOT GFLAGS_ROOT_DIR) - set(GFLAGS_ROOT_DIR <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>/third_party/gflags) - endif() - if(EXISTS "<%text>${GFLAGS_ROOT_DIR}</%text>/CMakeLists.txt") - add_subdirectory(<%text>${GFLAGS_ROOT_DIR}</%text> third_party/gflags) - if(TARGET gflags_static) - set(_gRPC_GFLAGS_LIBRARIES gflags_static) - endif() - else() - message(WARNING "gRPC_GFLAGS_PROVIDER is \"module\" but GFLAGS_ROOT_DIR is wrong") - endif() - elseif("<%text>${gRPC_GFLAGS_PROVIDER}</%text>" STREQUAL "package") - find_package(gflags) - if(TARGET gflags::gflags) - set(_gRPC_GFLAGS_LIBRARIES gflags::gflags) - endif() - set(_gRPC_FIND_GFLAGS "if(NOT gflags_FOUND)\n find_package(gflags)\nendif()") - endif() - - if("<%text>${gRPC_BENCHMARK_PROVIDER}</%text>" STREQUAL "module") - if(NOT BENCHMARK_ROOT_DIR) - set(BENCHMARK_ROOT_DIR <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>/third_party/benchmark) - endif() - if(EXISTS "<%text>${BENCHMARK_ROOT_DIR}</%text>/CMakeLists.txt") - add_subdirectory(<%text>${BENCHMARK_ROOT_DIR}</%text> third_party/benchmark) - if(TARGET benchmark) - set(_gRPC_BENCHMARK_LIBRARIES benchmark) - endif() - else() - message(WARNING "gRPC_BENCHMARK_PROVIDER is \"module\" but BENCHMARK_ROOT_DIR is wrong") - endif() - elseif("<%text>${gRPC_BENCHMARK_PROVIDER}</%text>" STREQUAL "package") - find_package(benchmark) - if(TARGET benchmark::benchmark) - set(_gRPC_BENCHMARK_LIBRARIES benchmark::benchmark) - endif() - set(_gRPC_FIND_BENCHMARK "if(NOT benchmark_FOUND)\n find_package(benchmark)\nendif()") - endif() + include(cmake/zlib.cmake) + include(cmake/cares.cmake) + include(cmake/protobuf.cmake) + include(cmake/ssl.cmake) + include(cmake/gflags.cmake) + include(cmake/benchmark.cmake) if(NOT MSVC) set(CMAKE_C_FLAGS "<%text>${CMAKE_C_FLAGS}</%text> -std=c99") |