[Cmake-commits] CMake branch, next, updated. v3.3.1-2907-gec5077c
Brad King
brad.king at kitware.com
Mon Sep 14 10:11:19 EDT 2015
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "CMake".
The branch, next has been updated
via ec5077cfa1f42eb7e10138098d1a4693fe6ce402 (commit)
via 143579c319472facbcfc3285f0b6b0ab56f1bde3 (commit)
from c8c79835fc8e3a062dd3a04b1d7d7d465d7e3a61 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=ec5077cfa1f42eb7e10138098d1a4693fe6ce402
commit ec5077cfa1f42eb7e10138098d1a4693fe6ce402
Merge: c8c7983 143579c
Author: Brad King <brad.king at kitware.com>
AuthorDate: Mon Sep 14 10:11:18 2015 -0400
Commit: CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Mon Sep 14 10:11:18 2015 -0400
Merge topic 'FindProtobuf-python-extension' into next
143579c3 FindProtobuf: Add protobuf_generate_python function
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=143579c319472facbcfc3285f0b6b0ab56f1bde3
commit 143579c319472facbcfc3285f0b6b0ab56f1bde3
Author: Andreas Bergmeier <a.bergmeier at dsfishlabs.com>
AuthorDate: Mon Sep 14 09:41:38 2015 +0200
Commit: Brad King <brad.king at kitware.com>
CommitDate: Mon Sep 14 10:10:35 2015 -0400
FindProtobuf: Add protobuf_generate_python function
diff --git a/Help/release/dev/FindProtobuf-python-extension.rst b/Help/release/dev/FindProtobuf-python-extension.rst
new file mode 100644
index 0000000..95463bf
--- /dev/null
+++ b/Help/release/dev/FindProtobuf-python-extension.rst
@@ -0,0 +1,6 @@
+FindProtobuf-python-extension
+-----------------------------
+
+* The :module:`FindProtobuf` module gained a new
+ :command:`protobuf_generate_python` function to generate python
+ sources from ``.proto`` files.
diff --git a/Modules/FindProtobuf.cmake b/Modules/FindProtobuf.cmake
index 335c408..6bf565b 100644
--- a/Modules/FindProtobuf.cmake
+++ b/Modules/FindProtobuf.cmake
@@ -57,17 +57,18 @@
# include_directories(${PROTOBUF_INCLUDE_DIRS})
# include_directories(${CMAKE_CURRENT_BINARY_DIR})
# protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS foo.proto)
+# protobuf_generate_python(PROTO_PY foo.proto)
# add_executable(bar bar.cc ${PROTO_SRCS} ${PROTO_HDRS})
# target_link_libraries(bar ${PROTOBUF_LIBRARIES})
#
# .. note::
-# The PROTOBUF_GENERATE_CPP macro and add_executable() or
-# add_library() calls only work properly within the same
-# directory.
+# The ``protobuf_generate_cpp`` and ``protobuf_generate_python``
+# functions and :command:`add_executable` or :command:`add_library`
+# calls only work properly within the same directory.
#
# .. command:: protobuf_generate_cpp
#
-# Add custom commands to process ``.proto`` files::
+# Add custom commands to process ``.proto`` files to C++::
#
# protobuf_generate_cpp (<SRCS> <HDRS> [<ARGN>...])
#
@@ -77,6 +78,17 @@
# Variable to define with autogenerated header files
# ``ARGN``
# ``.proto`` files
+#
+# .. command:: protobuf_generate_python
+#
+# Add custom commands to process ``.proto`` files to Python::
+#
+# protobuf_generate_python (<PY> [<ARGN>...])
+#
+# ``PY``
+# Variable to define with autogenerated Python files
+# ``ARGN``
+# ``.proto`` filess
#=============================================================================
# Copyright 2009 Kitware, Inc.
@@ -147,6 +159,53 @@ function(PROTOBUF_GENERATE_CPP SRCS HDRS)
set(${HDRS} ${${HDRS}} PARENT_SCOPE)
endfunction()
+function(PROTOBUF_GENERATE_PYTHON SRCS)
+ if(NOT ARGN)
+ message(SEND_ERROR "Error: PROTOBUF_GENERATE_PYTHON() called without any proto files")
+ return()
+ endif()
+
+ if(PROTOBUF_GENERATE_CPP_APPEND_PATH)
+ # Create an include path for each file specified
+ foreach(FIL ${ARGN})
+ get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
+ get_filename_component(ABS_PATH ${ABS_FIL} PATH)
+ list(FIND _protobuf_include_path ${ABS_PATH} _contains_already)
+ if(${_contains_already} EQUAL -1)
+ list(APPEND _protobuf_include_path -I ${ABS_PATH})
+ endif()
+ endforeach()
+ else()
+ set(_protobuf_include_path -I ${CMAKE_CURRENT_SOURCE_DIR})
+ endif()
+
+ if(DEFINED PROTOBUF_IMPORT_DIRS)
+ foreach(DIR ${PROTOBUF_IMPORT_DIRS})
+ get_filename_component(ABS_PATH ${DIR} ABSOLUTE)
+ list(FIND _protobuf_include_path ${ABS_PATH} _contains_already)
+ if(${_contains_already} EQUAL -1)
+ list(APPEND _protobuf_include_path -I ${ABS_PATH})
+ endif()
+ endforeach()
+ endif()
+
+ set(${SRCS})
+ foreach(FIL ${ARGN})
+ get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
+ get_filename_component(FIL_WE ${FIL} NAME_WE)
+
+ list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.py")
+ add_custom_command(
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.py"
+ COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} --python_out ${CMAKE_CURRENT_BINARY_DIR} ${_protobuf_include_path} ${ABS_FIL}
+ DEPENDS ${ABS_FIL} ${PROTOBUF_PROTOC_EXECUTABLE}
+ COMMENT "Running Python protocol buffer compiler on ${FIL}"
+ VERBATIM )
+ endforeach()
+
+ set(${SRCS} ${${SRCS}} PARENT_SCOPE)
+endfunction()
+
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(_PROTOBUF_ARCH_DIR x64/)
endif()
-----------------------------------------------------------------------
Summary of changes:
Help/release/dev/FindProtobuf-python-extension.rst | 6 ++
Modules/FindProtobuf.cmake | 67 ++++++++++++++++++--
2 files changed, 69 insertions(+), 4 deletions(-)
create mode 100644 Help/release/dev/FindProtobuf-python-extension.rst
hooks/post-receive
--
CMake
More information about the Cmake-commits
mailing list