|
| 1 | +# Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
| 2 | +# |
| 3 | +# This program is free software; you can redistribute it and/or modify |
| 4 | +# it under the terms of the GNU General Public License as published by |
| 5 | +# the Free Software Foundation; version 2 of the License. |
| 6 | +# |
| 7 | +# This program is distributed in the hope that it will be useful, |
| 8 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | +# GNU General Public License for more details. |
| 11 | +# |
| 12 | +# You should have received a copy of the GNU General Public License |
| 13 | +# along with this program; if not, write to the Free Software |
| 14 | +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 15 | + |
| 16 | +# |
| 17 | +# Usage: |
| 18 | +# |
| 19 | +# cmake -DWITH_PROTOBUF="bundled"|"system" |
| 20 | +# |
| 21 | +# Default is "bundled" |
| 22 | +# Other values will be ignored, and we fall back to "bundled" |
| 23 | +# |
| 24 | + |
| 25 | +MACRO(RESET_PROTOBUF_VARIABLES) |
| 26 | + UNSET(PROTOBUF_INCLUDE_DIR CACHE) |
| 27 | + UNSET(PROTOBUF_INCLUDE_DIR) |
| 28 | + UNSET(PROTOBUF_INCLUDE_DIRS CACHE) |
| 29 | + UNSET(PROTOBUF_INCLUDE_DIRS) |
| 30 | + UNSET(PROTOBUF_LIBRARIES CACHE) |
| 31 | + UNSET(PROTOBUF_LIBRARIES) |
| 32 | + UNSET(PROTOBUF_LIBRARY CACHE) |
| 33 | + UNSET(PROTOBUF_LIBRARY) |
| 34 | + UNSET(PROTOBUF_LIBRARY_DEBUG CACHE) |
| 35 | + UNSET(PROTOBUF_LIBRARY_DEBUG) |
| 36 | + UNSET(PROTOBUF_LITE_LIBRARY CACHE) |
| 37 | + UNSET(PROTOBUF_LITE_LIBRARY) |
| 38 | + UNSET(PROTOBUF_LITE_LIBRARY_DEBUG CACHE) |
| 39 | + UNSET(PROTOBUF_LITE_LIBRARY_DEBUG) |
| 40 | + UNSET(PROTOBUF_PROTOC_EXECUTABLE CACHE) |
| 41 | + UNSET(PROTOBUF_PROTOC_EXECUTABLE) |
| 42 | + UNSET(PROTOBUF_PROTOC_LIBRARY_DEBUG CACHE) |
| 43 | + UNSET(PROTOBUF_PROTOC_LIBRARY_DEBUG) |
| 44 | +ENDMACRO() |
| 45 | + |
| 46 | +MACRO(ECHO_PROTOBUF_VARIABLES) |
| 47 | + MESSAGE(STATUS "PROTOBUF_INCLUDE_DIR ${PROTOBUF_INCLUDE_DIR}") |
| 48 | + MESSAGE(STATUS "PROTOBUF_LIBRARY ${PROTOBUF_LIBRARY}") |
| 49 | + MESSAGE(STATUS "PROTOBUF_PROTOC_EXECUTABLE ${PROTOBUF_PROTOC_EXECUTABLE}") |
| 50 | +ENDMACRO() |
| 51 | + |
| 52 | +MACRO(COULD_NOT_FIND_PROTOBUF) |
| 53 | + ECHO_PROTOBUF_VARIABLES() |
| 54 | + MESSAGE(STATUS "Could not find (the correct version of) protobuf.") |
| 55 | + MESSAGE(STATUS "MySQL currently requires at least protobuf version 2.5") |
| 56 | + MESSAGE(FATAL_ERROR |
| 57 | + "You can build with the bundled sources" |
| 58 | + ) |
| 59 | +ENDMACRO() |
| 60 | + |
| 61 | +SET(BUNDLED_PROTO_SRCDIR ${CMAKE_SOURCE_DIR}/extra/protobuf/protobuf-2.6.0/src) |
| 62 | + |
| 63 | +MACRO(MYSQL_USE_BUNDLED_PROTOBUF) |
| 64 | + SET(WITH_PROTOBUF "bundled" CACHE INTERNAL |
| 65 | + "Bundled protoc and protobuf library") |
| 66 | + # Set the same variables as FindProtobuf.cmake |
| 67 | + SET(PROTOBUF_FOUND 1 CACHE INTERNAL "") |
| 68 | + SET(PROTOBUF_INCLUDE_DIR ${BUNDLED_PROTO_SRCDIR} CACHE INTERNAL "") |
| 69 | + SET(PROTOBUF_INCLUDE_DIRS ${BUNDLED_PROTO_SRCDIR} CACHE INTERNAL "") |
| 70 | + SET(PROTOBUF_LIBRARY protobuf CACHE INTERNAL "") |
| 71 | + SET(PROTOBUF_LIBRARY_DEBUG protobuf CACHE INTERNAL "") |
| 72 | + SET(PROTOBUF_LIBRARIES protobuf CACHE INTERNAL "") |
| 73 | + SET(PROTOBUF_PROTOC_EXECUTABLE protoc CACHE INTERNAL "") |
| 74 | + SET(PROTOBUF_PROTOC_LIBRARY protoclib CACHE INTERNAL "") |
| 75 | + SET(PROTOBUF_PROTOC_LIBRARY_DEBUG protoclib CACHE INTERNAL "") |
| 76 | + SET(PROTOBUF_LITE_LIBRARY protobuf-lite CACHE INTERNAL "") |
| 77 | + SET(PROTOBUF_LITE_LIBRARY_DEBUG protobuf-lite CACHE INTERNAL "") |
| 78 | + ADD_SUBDIRECTORY(extra/protobuf) |
| 79 | +ENDMACRO() |
| 80 | + |
| 81 | +MACRO(MYSQL_CHECK_PROTOBUF) |
| 82 | + IF (NOT WITH_PROTOBUF OR |
| 83 | + NOT WITH_PROTOBUF STREQUAL "system") |
| 84 | + SET(WITH_PROTOBUF "bundled") |
| 85 | + ENDIF() |
| 86 | + MESSAGE(STATUS "WITH_PROTOBUF=${WITH_PROTOBUF}") |
| 87 | + IF(WITH_PROTOBUF STREQUAL "bundled") |
| 88 | + MYSQL_USE_BUNDLED_PROTOBUF() |
| 89 | + ELSE() |
| 90 | + FIND_PACKAGE(Protobuf) |
| 91 | + ENDIF() |
| 92 | + |
| 93 | + IF(NOT PROTOBUF_FOUND) |
| 94 | + MESSAGE(WARNING "Protobuf could not be found") |
| 95 | + ENDIF() |
| 96 | + |
| 97 | + IF(PROTOBUF_FOUND) |
| 98 | + # Verify protobuf version number. Version information looks like: |
| 99 | + # // The current version, represented as a single integer to make comparison |
| 100 | + # // easier: major * 10^6 + minor * 10^3 + micro |
| 101 | + # #define GOOGLE_PROTOBUF_VERSION 2006000 |
| 102 | + FILE(STRINGS "${PROTOBUF_INCLUDE_DIR}/google/protobuf/stubs/common.h" |
| 103 | + PROTOBUF_VERSION_NUMBER |
| 104 | + REGEX "^#define[\t ]+GOOGLE_PROTOBUF_VERSION[\t ][0-9]+.*" |
| 105 | + ) |
| 106 | + STRING(REGEX REPLACE |
| 107 | + "^.*GOOGLE_PROTOBUF_VERSION[\t ]([0-9])[0-9][0-9]([0-9])[0-9][0-9].*$" |
| 108 | + "\\1" |
| 109 | + PROTOBUF_MAJOR_VERSION "${PROTOBUF_VERSION_NUMBER}") |
| 110 | + STRING(REGEX REPLACE |
| 111 | + "^.*GOOGLE_PROTOBUF_VERSION[\t ]([0-9])[0-9][0-9]([0-9])[0-9][0-9].*$" |
| 112 | + "\\2" |
| 113 | + PROTOBUF_MINOR_VERSION "${PROTOBUF_VERSION_NUMBER}") |
| 114 | + |
| 115 | + MESSAGE(STATUS |
| 116 | + "protobuf version is ${PROTOBUF_MAJOR_VERSION}.${PROTOBUF_MINOR_VERSION}") |
| 117 | + |
| 118 | + IF("${PROTOBUF_MAJOR_VERSION}.${PROTOBUF_MINOR_VERSION}" VERSION_LESS "2.5") |
| 119 | + COULD_NOT_FIND_PROTOBUF() |
| 120 | + ENDIF() |
| 121 | + ENDIF() |
| 122 | +ENDMACRO() |
0 commit comments