From c281acf80768c56bbe12a9f017a856d8e966f084 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Apitzsch?= Date: Tue, 11 Jul 2017 15:20:36 +0200 Subject: FindProtobuf: add target for protoc --- Modules/FindProtobuf.cmake | 20 ++++++++++++++++---- Tests/FindProtobuf/Test/CMakeLists.txt | 2 ++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Modules/FindProtobuf.cmake b/Modules/FindProtobuf.cmake index 33262f3..90f7a2e 100644 --- a/Modules/FindProtobuf.cmake +++ b/Modules/FindProtobuf.cmake @@ -48,6 +48,8 @@ # The protobuf lite library. # ``protobuf::libprotoc`` # The protoc library. +# ``protobuf::protoc`` +# The protoc compiler. # # The following cache variables are also available to set or use: # @@ -172,9 +174,9 @@ function(PROTOBUF_GENERATE_CPP SRCS HDRS) add_custom_command( OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc" "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h" - COMMAND ${Protobuf_PROTOC_EXECUTABLE} + COMMAND protobuf::protoc ARGS "--cpp_out=${DLL_EXPORT_DECL}${CMAKE_CURRENT_BINARY_DIR}" ${_protobuf_include_path} ${ABS_FIL} - DEPENDS ${ABS_FIL} ${Protobuf_PROTOC_EXECUTABLE} + DEPENDS ${ABS_FIL} protobuf::protoc COMMENT "Running C++ protocol buffer compiler on ${FIL}" VERBATIM ) endforeach() @@ -232,8 +234,8 @@ function(PROTOBUF_GENERATE_PYTHON SRCS) list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}_pb2.py") add_custom_command( OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}_pb2.py" - COMMAND ${Protobuf_PROTOC_EXECUTABLE} --python_out ${CMAKE_CURRENT_BINARY_DIR} ${_protobuf_include_path} ${ABS_FIL} - DEPENDS ${ABS_FIL} ${Protobuf_PROTOC_EXECUTABLE} + COMMAND protobuf::protoc --python_out ${CMAKE_CURRENT_BINARY_DIR} ${_protobuf_include_path} ${ABS_FIL} + DEPENDS ${ABS_FIL} protobuf::protoc COMMENT "Running Python protocol buffer compiler on ${FIL}" VERBATIM ) endforeach() @@ -501,6 +503,16 @@ if(Protobuf_INCLUDE_DIR) endif() endif() endif() + + if(Protobuf_PROTOC_EXECUTABLE) + if(NOT TARGET protobuf::protoc) + add_executable(protobuf::protoc IMPORTED) + if(EXISTS "${Protobuf_PROTOC_EXECUTABLE}") + set_target_properties(protobuf::protoc PROPERTIES + IMPORTED_LOCATION "${Protobuf_PROTOC_EXECUTABLE}") + endif() + endif() + endif() endif() include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) diff --git a/Tests/FindProtobuf/Test/CMakeLists.txt b/Tests/FindProtobuf/Test/CMakeLists.txt index 8b6e38a..10ce976 100644 --- a/Tests/FindProtobuf/Test/CMakeLists.txt +++ b/Tests/FindProtobuf/Test/CMakeLists.txt @@ -30,3 +30,5 @@ add_executable(test_var_protoc main-protoc.cxx) target_include_directories(test_var_protoc PRIVATE ${Protobuf_INCLUDE_DIRS}) target_link_libraries(test_var_protoc PRIVATE ${Protobuf_PROTOC_LIBRARIES}) add_test(NAME test_var_protoc COMMAND test_var_protoc) + +add_test(NAME test_tgt_protoc_version COMMAND protobuf::protoc --version) -- cgit v0.12