Skip to content

Commit

Permalink
[pulsar-client-cpp] cmake isolate auto gen srcs (apache#5013)
Browse files Browse the repository at this point in the history
  • Loading branch information
yittg authored and merlimat committed Aug 26, 2019
1 parent 8d32b58 commit dc7ce39
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
7 changes: 3 additions & 4 deletions pulsar-client-cpp/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ lib*.so*
# doxygen files
apidocs/

# Protobuf generated files
*.pb.cc
*.pb.h
# generated files
generated/

# CMAKE
Makefile
Expand All @@ -72,4 +71,4 @@ CMakeCache.txt
pulsar-dist
install_manifest.txt
merged-library
python/venv
python/venv
4 changes: 4 additions & 0 deletions pulsar-client-cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
17 changes: 12 additions & 5 deletions pulsar-client-cpp/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand All @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pulsar-client-cpp/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<$<CONFIG:Debug>:${GMOCKD_LIBRARY_PATH}> $<$<CONFIG:Debug>:${GTESTD_LIBRARY_PATH}> $<$<NOT:$<CONFIG:Debug>>:${GMOCK_LIBRARY_PATH}> $<$<NOT:$<CONFIG:Debug>>:${GTEST_LIBRARY_PATH}>)

0 comments on commit dc7ce39

Please sign in to comment.