mirror of
https://github.com/Kitware/CMake.git
synced 2025-12-30 18:29:37 -06:00
FindProtobuf: add target for protoc
This commit is contained in:
committed by
Brad King
parent
107a92ea9a
commit
c281acf807
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user