From dc7ce39f59d62bab29907d416c0c55fd8cfe3ada Mon Sep 17 00:00:00 2001 From: Yi Tang Date: Tue, 27 Aug 2019 00:25:29 +0800 Subject: [PATCH] [pulsar-client-cpp] cmake isolate auto gen srcs (#5013) --- pulsar-client-cpp/.gitignore | 7 +++---- pulsar-client-cpp/CMakeLists.txt | 4 ++++ pulsar-client-cpp/lib/CMakeLists.txt | 17 ++++++++++++----- pulsar-client-cpp/tests/CMakeLists.txt | 2 +- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/pulsar-client-cpp/.gitignore b/pulsar-client-cpp/.gitignore index dd09eb2dc8ccd..76efe8eca0922 100644 --- a/pulsar-client-cpp/.gitignore +++ b/pulsar-client-cpp/.gitignore @@ -59,9 +59,8 @@ lib*.so* # doxygen files apidocs/ -# Protobuf generated files -*.pb.cc -*.pb.h +# generated files +generated/ # CMAKE Makefile @@ -72,4 +71,4 @@ CMakeCache.txt pulsar-dist install_manifest.txt merged-library -python/venv \ No newline at end of file +python/venv diff --git a/pulsar-client-cpp/CMakeLists.txt b/pulsar-client-cpp/CMakeLists.txt index 0cb2a24bbc988..6ee1f771f1e34 100644 --- a/pulsar-client-cpp/CMakeLists.txt +++ b/pulsar-client-cpp/CMakeLists.txt @@ -195,9 +195,13 @@ MESSAGE(STATUS "HAS_SNAPPY: ${HAS_SNAPPY}") set(ADDITIONAL_LIBRARIES $ENV{PULSAR_ADDITIONAL_LIBRARIES}) link_directories( $ENV{PULSAR_ADDITIONAL_LIBRARY_PATH} ) +set(AUTOGEN_DIR ${CMAKE_BINARY_DIR}/generated) +file(MAKE_DIRECTORY ${AUTOGEN_DIR}) + include_directories( ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/include + ${AUTOGEN_DIR} ${Boost_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR} ${ZLIB_INCLUDE_DIRS} diff --git a/pulsar-client-cpp/lib/CMakeLists.txt b/pulsar-client-cpp/lib/CMakeLists.txt index c780d3338f015..cb77b172e15b8 100644 --- a/pulsar-client-cpp/lib/CMakeLists.txt +++ b/pulsar-client-cpp/lib/CMakeLists.txt @@ -25,11 +25,18 @@ set (CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} -D_PULSAR_VERSION_=\\\"${PV}\\\"") if (NOT PROTOC_PATH) set(PROTOC_PATH protoc) endif() + +set(LIB_AUTOGEN_DIR ${AUTOGEN_DIR}/lib) +file(MAKE_DIRECTORY ${LIB_AUTOGEN_DIR}) +include_directories(${LIB_AUTOGEN_DIR}) + # Protobuf generation is only supported natively starting from CMake 3.8 # Using custom command for now +set(PROTO_SOURCES ${LIB_AUTOGEN_DIR}/PulsarApi.pb.cc ${LIB_AUTOGEN_DIR}/PulsarApi.pb.h) +set(PULSAR_SOURCES ${PULSAR_SOURCES} ${PROTO_SOURCES}) ADD_CUSTOM_COMMAND( - OUTPUT ${CMAKE_SOURCE_DIR}/lib/PulsarApi.pb.h ${CMAKE_SOURCE_DIR}/lib/PulsarApi.pb.cc - COMMAND ${PROTOC_PATH} -I ../../pulsar-common/src/main/proto ../../pulsar-common/src/main/proto/PulsarApi.proto --cpp_out=${CMAKE_SOURCE_DIR}/lib + OUTPUT ${PROTO_SOURCES} + COMMAND ${PROTOC_PATH} -I ../../pulsar-common/src/main/proto ../../pulsar-common/src/main/proto/PulsarApi.proto --cpp_out=${LIB_AUTOGEN_DIR} DEPENDS ../../pulsar-common/src/main/proto/PulsarApi.proto WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) @@ -50,11 +57,11 @@ if (WIN32) string(APPEND LIB_NAME_SHARED dll) endif() -add_library(pulsarShared SHARED ${PULSAR_SOURCES} PulsarApi.pb.h PulsarApi.pb.cc) +add_library(pulsarShared SHARED ${PULSAR_SOURCES}) set_target_properties(pulsarShared PROPERTIES OUTPUT_NAME ${LIB_NAME_SHARED} VERSION ${LIBRARY_VERSION}) target_link_libraries(pulsarShared ${COMMON_LIBS} ${CMAKE_DL_LIBS}) -add_library(pulsarStatic STATIC ${PULSAR_SOURCES} PulsarApi.pb.h PulsarApi.pb.cc) +add_library(pulsarStatic STATIC ${PULSAR_SOURCES}) set_target_properties(pulsarStatic PROPERTIES OUTPUT_NAME ${LIB_NAME} VERSION ${LIBRARY_VERSION}) target_compile_definitions(pulsarStatic PRIVATE PULSAR_STATIC) @@ -84,7 +91,7 @@ if (LINK_STATIC) set(${OUTLIST} ${TEMP_OUT} PARENT_SCOPE) endfunction(remove_libtype) - add_library(pulsarStaticWithDeps STATIC ${PULSAR_SOURCES} PulsarApi.pb.h PulsarApi.pb.cc) + add_library(pulsarStaticWithDeps STATIC ${PULSAR_SOURCES}) target_include_directories(pulsarStaticWithDeps PRIVATE ${dlfcn-win32_INCLUDE_DIRS}) remove_libtype("${COMMON_LIBS}" "optimized" DEBUG_STATIC_LIBS) remove_libtype("${COMMON_LIBS}" "debug" STATIC_LIBS) diff --git a/pulsar-client-cpp/tests/CMakeLists.txt b/pulsar-client-cpp/tests/CMakeLists.txt index 2c58ed72df04c..8b5a09d11cbe9 100644 --- a/pulsar-client-cpp/tests/CMakeLists.txt +++ b/pulsar-client-cpp/tests/CMakeLists.txt @@ -32,6 +32,6 @@ file(GLOB TEST_SOURCES *.cc) add_executable(main ${TEST_SOURCES}) -target_include_directories(main PRIVATE ${CMAKE_SOURCE_DIR}/lib) +target_include_directories(main PRIVATE ${CMAKE_SOURCE_DIR}/lib ${AUTOGEN_DIR}/lib) target_link_libraries(main ${CLIENT_LIBS} pulsarShared $<$:${GMOCKD_LIBRARY_PATH}> $<$:${GTESTD_LIBRARY_PATH}> $<$>:${GMOCK_LIBRARY_PATH}> $<$>:${GTEST_LIBRARY_PATH}>)