diff options
author | Jan Tattermusch <jtattermusch@google.com> | 2017-01-23 11:24:53 +0100 |
---|---|---|
committer | Jan Tattermusch <jtattermusch@google.com> | 2017-02-02 00:04:09 +0100 |
commit | 438c0b5771d748df299a75a844fa70c8e8539b5a (patch) | |
tree | 0906cd36971752228915318accaf23f09004a974 /templates | |
parent | bd0b0546a6e12dc6b9276502341446e91f0253f0 (diff) |
add convenience cmake targets
Diffstat (limited to 'templates')
-rw-r--r-- | templates/CMakeLists.txt.template | 144 |
1 files changed, 138 insertions, 6 deletions
diff --git a/templates/CMakeLists.txt.template b/templates/CMakeLists.txt.template index a326f36fe9..b034763fb0 100644 --- a/templates/CMakeLists.txt.template +++ b/templates/CMakeLists.txt.template @@ -59,15 +59,27 @@ deps.append("${_gRPC_PROTOBUF_PROTOC_LIBRARIES}") if target_dict.get('secure', False): deps.append("${_gRPC_SSL_LIBRARIES}") - if target_dict['name'] in ['grpc++', 'grpc++_unsecure', 'grpc++_codegen_lib']: + if target_dict.language == 'c++': deps.append("${_gRPC_PROTOBUF_LIBRARIES}") - elif target_dict['name'] in ['grpc']: + if target_dict['name'] in ['grpc']: deps.append("${_gRPC_ZLIB_LIBRARIES}") + deps.append("${_gRPC_ALLTARGETS_LIBRARIES}") for d in target_dict.get('deps', []): deps.append(d) if target_dict.build == 'test' and target_dict.language == 'c++': deps.append("${_gRPC_GFLAGS_LIBRARIES}") return deps + + def get_platforms_condition_begin(platforms): + if all(platform in platforms for platform in ['linux', 'mac', 'posix', 'windows']): + return '' + cond = ' OR '.join(['_gRPC_PLATFORM_%s' % platform.upper() for platform in platforms]) + return 'if(%s)\n' % cond + + def get_platforms_condition_end(platforms): + if not get_platforms_condition_begin(platforms): + return '' + return 'endif()\n' %> cmake_minimum_required(VERSION 2.8) @@ -100,8 +112,24 @@ set(gRPC_GFLAGS_PROVIDER "module" CACHE STRING "Provider of gflags library") set_property(CACHE gRPC_GFLAGS_PROVIDER PROPERTY STRINGS "module" "package") + set(gRPC_BENCHMARK_PROVIDER "module" CACHE STRING "Provider of benchmark library") + set_property(CACHE gRPC_BENCHMARK_PROVIDER PROPERTY STRINGS "module" "package") + set(gRPC_USE_PROTO_LITE OFF CACHE BOOL "Use the protobuf-lite library") + if(UNIX) + if(<%text>${CMAKE_SYSTEM_NAME}</%text> MATCHES "Linux") + set(_gRPC_PLATFORM_LINUX ON) + elseif(<%text>${CMAKE_SYSTEM_NAME}</%text> MATCHES "Darwin") + set(_gRPC_PLATFORM_MAC ON) + else() + set(_gRPC_PLATFORM_POSIX ON) + endif() + endif() + if(WIN32) + set(_gRPC_PLATFORM_WINDOWS ON) + endif() + if (MSVC) add_definitions(-D_WIN32_WINNT=0x600 -D_SCL_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS -D_WINSOCK_DEPRECATED_NO_WARNINGS) # needed to compile boringssl @@ -189,6 +217,7 @@ 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) @@ -223,12 +252,36 @@ 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() if(NOT MSVC) - set(CMAKE_C_FLAGS "<%text>${CMAKE_C_FLAGS}</%text> -std=c11") + set(CMAKE_C_FLAGS "<%text>${CMAKE_C_FLAGS}</%text> -std=c99") set(CMAKE_CXX_FLAGS "<%text>${CMAKE_CXX_FLAGS}</%text> -std=c++11") endif() + if(UNIX) + set(_gRPC_ALLTARGETS_LIBRARIES dl rt m pthread) + endif() + if(WIN32 AND MSVC) set(_gRPC_BASELIB_LIBRARIES wsock32 ws2_32) endif() @@ -287,9 +340,63 @@ endforeach() endfunction() + add_custom_target(plugins + DEPENDS + % for tgt in targets: + % if tgt.build == 'protoc': + ${tgt.name} + % endif + % endfor + ) + + add_custom_target(tools_c + DEPENDS + % for tgt in targets: + % if tgt.build == 'tool' and not tgt.language == 'c++': + ${tgt.name} + % endif + % endfor + ) + + add_custom_target(tools_cxx + DEPENDS + % for tgt in targets: + % if tgt.build == 'tool' and tgt.language == 'c++': + ${tgt.name} + % endif + % endfor + ) + + add_custom_target(tools + DEPENDS tools_c tools_cxx) + + if (gRPC_BUILD_TESTS) + add_custom_target(buildtests_c) + % for tgt in targets: + % if tgt.build == 'test' and not tgt.language == 'c++' and not tgt.get('external_deps', None) and not tgt.boringssl: + ${get_platforms_condition_begin(tgt.platforms)}\ + add_dependencies(buildtests_c ${tgt.name}) + ${get_platforms_condition_end(tgt.platforms)}\ + % endif + % endfor + + add_custom_target(buildtests_cxx) + % for tgt in targets: + % if tgt.build == 'test' and tgt.language == 'c++' and not tgt.get('external_deps', None) and not tgt.boringssl: + ${get_platforms_condition_begin(tgt.platforms)}\ + add_dependencies(buildtests_cxx ${tgt.name}) + ${get_platforms_condition_end(tgt.platforms)}\ + % endif + % endfor + + add_custom_target(buildtests + DEPENDS buildtests_c buildtests_cxx) + endif (gRPC_BUILD_TESTS) + % for lib in libs: - % if lib.build in ["all", "protoc", "tool", "test", "private"] and lib.language in ['c', 'c++']: + % if lib.build in ["all", "protoc", "tool", "test", "private"] and not lib.boringssl: % if not lib.get('build_system', []) or 'cmake' in lib.get('build_system', []): + % if not lib.name in ['benchmark', 'z']: # we build these using CMake instead % if lib.build in ["test", "private"]: if (gRPC_BUILD_TESTS) ${cc_library(lib)} @@ -300,17 +407,22 @@ % endif % endif % endif + % endif % endfor % for tgt in targets: - % if tgt.build in ["all", "protoc", "tool", "test", "private"] and tgt.language in ['c', 'c++']: + % if tgt.build in ["all", "protoc", "tool", "test", "private"] and not tgt.boringssl: % if tgt.build in ["test", "private"]: if (gRPC_BUILD_TESTS) + ${get_platforms_condition_begin(tgt.platforms)}\ ${cc_binary(tgt)} + ${get_platforms_condition_end(tgt.platforms)}\ endif (gRPC_BUILD_TESTS) % else: + ${get_platforms_condition_begin(tgt.platforms)}\ ${cc_binary(tgt)} ${cc_install(tgt)} + ${get_platforms_condition_end(tgt.platforms)}\ % endif % endif % endfor @@ -343,13 +455,14 @@ PRIVATE <%text>${BORINGSSL_ROOT_DIR}</%text>/include PRIVATE <%text>${PROTOBUF_ROOT_DIR}</%text>/src PRIVATE <%text>${ZLIB_INCLUDE_DIR}</%text> + PRIVATE <%text>${BENCHMARK}</%text>/include PRIVATE <%text>${CMAKE_CURRENT_BINARY_DIR}</%text>/third_party/zlib PRIVATE <%text>${CMAKE_CURRENT_BINARY_DIR}</%text>/third_party/gflags/include % if lib.build in ['test', 'private'] and lib.language == 'c++': PRIVATE third_party/googletest/include PRIVATE third_party/googletest % endif - % if any(proto_re.match(src) for src in lib.src): + % if lib.language == 'c++': PRIVATE <%text>${_gRPC_PROTO_GENS_DIR}</%text> % endif ) @@ -380,18 +493,34 @@ <%def name="cc_binary(tgt)"> add_executable(${tgt.name} % for src in tgt.src: + % if not proto_re.match(src): ${src} + % else: + ${proto_replace_ext(src, '.pb.cc')} + ${proto_replace_ext(src, '.grpc.pb.cc')} + ${proto_replace_ext(src, '.pb.h')} + ${proto_replace_ext(src, '.grpc.pb.h')} + % endif % endfor % if tgt.build == 'test' and tgt.language == 'c++': third_party/googletest/src/gtest-all.cc % endif ) + + % for src in tgt.src: + % if proto_re.match(src): + protobuf_generate_grpc_cpp( + ${src} + ) + % endif + % endfor target_include_directories(${tgt.name} PRIVATE <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text> PRIVATE <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>/include PRIVATE <%text>${BORINGSSL_ROOT_DIR}</%text>/include PRIVATE <%text>${PROTOBUF_ROOT_DIR}</%text>/src + PRIVATE <%text>${BENCHMARK_ROOT_DIR}</%text>/include PRIVATE <%text>${ZLIB_ROOT_DIR}</%text> PRIVATE <%text>${CMAKE_CURRENT_BINARY_DIR}</%text>/third_party/zlib PRIVATE <%text>${CMAKE_CURRENT_BINARY_DIR}</%text>/third_party/gflags/include @@ -399,6 +528,9 @@ PRIVATE third_party/googletest/include PRIVATE third_party/googletest % endif + % if tgt.language == 'c++': + PRIVATE <%text>${_gRPC_PROTO_GENS_DIR}</%text> + % endif ) % if len(get_deps(tgt)) > 0: |