[Cmake-commits] CMake branch, next, updated. v3.5.0-rc2-149-gb60c67c

Brad King brad.king at kitware.com
Tue Feb 16 10:14:54 EST 2016


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  b60c67cc1f225fcdd270d2ed298b1b8b1b9f0697 (commit)
       via  bb7a41ab9b0b6a5a2cee3f330a2e223392ee4a70 (commit)
      from  7e4d38ed5c38d96713746574ab6d8207dcdaec06 (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 -----------------------------------------------------------------
https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=b60c67cc1f225fcdd270d2ed298b1b8b1b9f0697
commit b60c67cc1f225fcdd270d2ed298b1b8b1b9f0697
Merge: 7e4d38e bb7a41a
Author:     Brad King <brad.king at kitware.com>
AuthorDate: Tue Feb 16 10:14:53 2016 -0500
Commit:     CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Tue Feb 16 10:14:53 2016 -0500

    Merge topic 'FindProtobuf-version' into next
    
    bb7a41ab FindProtobuf: check version


https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=bb7a41ab9b0b6a5a2cee3f330a2e223392ee4a70
commit bb7a41ab9b0b6a5a2cee3f330a2e223392ee4a70
Author:     Antonio Perez Barrero <apbarrero at gmail.com>
AuthorDate: Fri Feb 12 08:23:44 2016 +0100
Commit:     Brad King <brad.king at kitware.com>
CommitDate: Tue Feb 16 10:09:39 2016 -0500

    FindProtobuf: check version
    
    Check found libraries version to match user required version.
    
    Protobuf compiler executable version is checked to be aligned with found
    libraries, raising a warning message otherwise.

diff --git a/Help/release/dev/FindProtobuf-version.rst b/Help/release/dev/FindProtobuf-version.rst
new file mode 100644
index 0000000..2bfd9f4
--- /dev/null
+++ b/Help/release/dev/FindProtobuf-version.rst
@@ -0,0 +1,6 @@
+FindProtobuf-version
+--------------------
+
+* The :module:`FindProtobuf` module learned to provide a ``PROTOBUF_VERSION``
+  variable and check the version number requested in a :command:`find_package`
+  call.
diff --git a/Modules/FindProtobuf.cmake b/Modules/FindProtobuf.cmake
index 0875349..95e3b1e 100644
--- a/Modules/FindProtobuf.cmake
+++ b/Modules/FindProtobuf.cmake
@@ -15,12 +15,16 @@
 # ``PROTOBUF_IMPORT_DIRS``
 #   List of additional directories to be searched for
 #   imported .proto files.
+# ``PROTOBUF_DEBUG``
+#   Show debug messages.
 #
 # Defines the following variables:
 #
 # ``PROTOBUF_FOUND``
 #   Found the Google Protocol Buffers library
 #   (libprotobuf & header files)
+# ``PROTOBUF_VERSION``
+#   Version of package found.
 # ``PROTOBUF_INCLUDE_DIRS``
 #   Include directories for Google Protocol Buffers
 # ``PROTOBUF_LIBRARIES``
@@ -304,10 +308,61 @@ find_program(PROTOBUF_PROTOC_EXECUTABLE
 )
 mark_as_advanced(PROTOBUF_PROTOC_EXECUTABLE)
 
+if(PROTOBUF_DEBUG)
+    message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+        "requested version of Google Protobuf is ${Protobuf_FIND_VERSION}")
+endif()
+
+if(PROTOBUF_INCLUDE_DIR)
+  set(_PROTOBUF_COMMON_HEADER ${PROTOBUF_INCLUDE_DIR}/google/protobuf/stubs/common.h)
+
+  if(PROTOBUF_DEBUG)
+    message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+                   "location of common.h: ${_PROTOBUF_COMMON_HEADER}")
+  endif()
+
+  set(PROTOBUF_VERSION "")
+  set(PROTOBUF_LIB_VERSION "")
+  file(STRINGS ${_PROTOBUF_COMMON_HEADER} _PROTOBUF_COMMON_H_CONTENTS REGEX "#define[ \t]+GOOGLE_PROTOBUF_VERSION[ \t]+")
+  if(_PROTOBUF_COMMON_H_CONTENTS MATCHES "#define[ \t]+GOOGLE_PROTOBUF_VERSION[ \t]+([0-9]+)")
+      set(PROTOBUF_LIB_VERSION "${CMAKE_MATCH_1}")
+  endif()
+  unset(_PROTOBUF_COMMON_H_CONTENTS)
+
+  math(EXPR _PROTOBUF_MAJOR_VERSION "${PROTOBUF_LIB_VERSION} / 1000000")
+  math(EXPR _PROTOBUF_MINOR_VERSION "${PROTOBUF_LIB_VERSION} / 1000 % 1000")
+  math(EXPR _PROTOBUF_SUBMINOR_VERSION "${PROTOBUF_LIB_VERSION} % 1000")
+  set(PROTOBUF_VERSION "${_PROTOBUF_MAJOR_VERSION}.${_PROTOBUF_MINOR_VERSION}.${_PROTOBUF_SUBMINOR_VERSION}")
+
+  if(PROTOBUF_DEBUG)
+    message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+        "${_PROTOBUF_COMMON_HEADER} reveals protobuf ${PROTOBUF_VERSION}")
+  endif()
+
+  # Check Protobuf compiler version to be aligned with libraries version
+  execute_process(COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} --version
+                  OUTPUT_VARIABLE _PROTOBUF_PROTOC_EXECUTABLE_VERSION)
+
+  if("${_PROTOBUF_PROTOC_EXECUTABLE_VERSION}" MATCHES "libprotoc ([0-9.]+)")
+    set(_PROTOBUF_PROTOC_EXECUTABLE_VERSION "${CMAKE_MATCH_1}")
+  endif()
+
+  if(PROTOBUF_DEBUG)
+    message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+        "${PROTOBUF_PROTOC_EXECUTABLE} reveals version ${_PROTOBUF_PROTOC_EXECUTABLE_VERSION}")
+  endif()
+
+  if(NOT "${_PROTOBUF_PROTOC_EXECUTABLE_VERSION}" VERSION_EQUAL "${PROTOBUF_VERSION}")
+      message(WARNING "Protobuf compiler version ${_PROTOBUF_PROTOC_EXECUTABLE_VERSION}"
+          " doesn't match library version ${PROTOBUF_VERSION}")
+  endif()
+endif()
 
 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(Protobuf DEFAULT_MSG
-    PROTOBUF_LIBRARY PROTOBUF_INCLUDE_DIR)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(Protobuf
+    REQUIRED_VARS PROTOBUF_LIBRARIES PROTOBUF_INCLUDE_DIR
+    VERSION_VAR PROTOBUF_VERSION
+)
 
 if(PROTOBUF_FOUND)
     set(PROTOBUF_INCLUDE_DIRS ${PROTOBUF_INCLUDE_DIR})
diff --git a/Tests/CMakeOnly/AllFindModules/CMakeLists.txt b/Tests/CMakeOnly/AllFindModules/CMakeLists.txt
index bdc2563..0aad161 100644
--- a/Tests/CMakeOnly/AllFindModules/CMakeLists.txt
+++ b/Tests/CMakeOnly/AllFindModules/CMakeLists.txt
@@ -92,4 +92,5 @@ foreach(VTEST BISON Boost CUDA DOXYGEN FLEX GIF GTK2
 endforeach()
 
 check_version_string(PYTHONINTERP PYTHON_VERSION_STRING)
+check_version_string(Protobuf PROTOBUF_VERSION)
 check_version_string(SUBVERSION Subversion_VERSION_SVN)

-----------------------------------------------------------------------

Summary of changes:
 Help/release/dev/FindProtobuf-version.rst     |    6 +++
 Modules/FindProtobuf.cmake                    |   59 ++++++++++++++++++++++++-
 Tests/CMakeOnly/AllFindModules/CMakeLists.txt |    1 +
 3 files changed, 64 insertions(+), 2 deletions(-)
 create mode 100644 Help/release/dev/FindProtobuf-version.rst


hooks/post-receive
-- 
CMake


More information about the Cmake-commits mailing list