OLD | NEW |
1 # Minimum CMake required | 1 # Minimum CMake required |
2 cmake_minimum_required(VERSION 2.8) | 2 cmake_minimum_required(VERSION 2.8.12) |
| 3 |
| 4 if(protobuf_VERBOSE) |
| 5 message(STATUS "Protocol Buffers Configuring...") |
| 6 endif() |
| 7 |
| 8 # CMake policies |
| 9 cmake_policy(SET CMP0022 NEW) |
3 | 10 |
4 # Project | 11 # Project |
5 project(protobuf C CXX) | 12 project(protobuf C CXX) |
6 | 13 |
7 # CMake policies | |
8 cmake_policy(SET CMP0022 NEW) | |
9 | |
10 # Options | 14 # Options |
11 option(protobuf_VERBOSE "Enable for verbose output" OFF) | |
12 option(protobuf_BUILD_TESTS "Build tests" ON) | 15 option(protobuf_BUILD_TESTS "Build tests" ON) |
| 16 option(protobuf_BUILD_EXAMPLES "Build examples" OFF) |
13 if (BUILD_SHARED_LIBS) | 17 if (BUILD_SHARED_LIBS) |
14 set(protobuf_BUILD_SHARED_LIBS_DEFAULT ON) | 18 set(protobuf_BUILD_SHARED_LIBS_DEFAULT ON) |
15 else (BUILD_SHARED_LIBS) | 19 else (BUILD_SHARED_LIBS) |
16 set(protobuf_BUILD_SHARED_LIBS_DEFAULT OFF) | 20 set(protobuf_BUILD_SHARED_LIBS_DEFAULT OFF) |
17 endif (BUILD_SHARED_LIBS) | 21 endif (BUILD_SHARED_LIBS) |
18 option(protobuf_BUILD_SHARED_LIBS "Build Shared Libraries" ${protobuf_BUILD_SHAR
ED_LIBS_DEFAULT}) | 22 option(protobuf_BUILD_SHARED_LIBS "Build Shared Libraries" ${protobuf_BUILD_SHAR
ED_LIBS_DEFAULT}) |
19 option(protobuf_MSVC_STATIC_RUNTIME "Link static runtime libraries" ON) | 23 include(CMakeDependentOption) |
| 24 cmake_dependent_option(protobuf_MSVC_STATIC_RUNTIME "Link static runtime librari
es" ON |
| 25 "NOT protobuf_BUILD_SHARED_LIBS" OFF) |
20 if (MSVC) | 26 if (MSVC) |
21 set(protobuf_WITH_ZLIB_DEFAULT OFF) | 27 set(protobuf_WITH_ZLIB_DEFAULT OFF) |
22 else (MSVC) | 28 else (MSVC) |
23 set(protobuf_WITH_ZLIB_DEFAULT ON) | 29 set(protobuf_WITH_ZLIB_DEFAULT ON) |
24 endif (MSVC) | 30 endif (MSVC) |
25 option(protobuf_WITH_ZLIB "Build with zlib support" ${protobuf_WITH_ZLIB_DEFAULT
}) | 31 option(protobuf_WITH_ZLIB "Build with zlib support" ${protobuf_WITH_ZLIB_DEFAULT
}) |
26 set(protobuf_DEBUG_POSTFIX "d" | 32 set(protobuf_DEBUG_POSTFIX "d" |
27 CACHE STRING "Default debug postfix") | 33 CACHE STRING "Default debug postfix") |
| 34 mark_as_advanced(protobuf_DEBUG_POSTFIX) |
| 35 # User options |
| 36 include(protobuf-options.cmake) |
28 | 37 |
29 # Path to main configure script | 38 # Path to main configure script |
30 set(protobuf_CONFIGURE_SCRIPT "../configure.ac") | 39 set(protobuf_CONFIGURE_SCRIPT "../configure.ac") |
31 | 40 |
32 # Parse configure script | 41 # Parse configure script |
33 set(protobuf_AC_INIT_REGEX | 42 set(protobuf_AC_INIT_REGEX |
34 "^AC_INIT\\(\\[([^]]+)\\],\\[([^]]+)\\],\\[([^]]+)\\],\\[([^]]+)\\]\\)$") | 43 "^AC_INIT\\(\\[([^]]+)\\],\\[([^]]+)\\],\\[([^]]+)\\],\\[([^]]+)\\]\\)$") |
35 file(STRINGS "${protobuf_CONFIGURE_SCRIPT}" protobuf_AC_INIT_LINE | 44 file(STRINGS "${protobuf_CONFIGURE_SCRIPT}" protobuf_AC_INIT_LINE |
36 LIMIT_COUNT 1 REGEX "^AC_INIT") | 45 LIMIT_COUNT 1 REGEX "^AC_INIT") |
37 # Description | 46 # Description |
38 string(REGEX REPLACE "${protobuf_AC_INIT_REGEX}" "\\1" | 47 string(REGEX REPLACE "${protobuf_AC_INIT_REGEX}" "\\1" |
39 protobuf_DESCRIPTION "${protobuf_AC_INIT_LINE}") | 48 protobuf_DESCRIPTION "${protobuf_AC_INIT_LINE}") |
40 # Version | 49 # Version |
41 string(REGEX REPLACE "${protobuf_AC_INIT_REGEX}" "\\2" | 50 string(REGEX REPLACE "${protobuf_AC_INIT_REGEX}" "\\2" |
42 protobuf_VERSION_STRING "${protobuf_AC_INIT_LINE}") | 51 protobuf_VERSION_STRING "${protobuf_AC_INIT_LINE}") |
43 # Contact | 52 # Contact |
44 string(REGEX REPLACE "${protobuf_AC_INIT_REGEX}" "\\3" | 53 string(REGEX REPLACE "${protobuf_AC_INIT_REGEX}" "\\3" |
45 protobuf_CONTACT "${protobuf_AC_INIT_LINE}") | 54 protobuf_CONTACT "${protobuf_AC_INIT_LINE}") |
46 # Parse version tweaks | 55 # Parse version tweaks |
47 set(protobuf_VERSION_REGEX "^([0-9]+)\\.([0-9]+)\\.([0-9]+).*$") | 56 set(protobuf_VERSION_REGEX "^([0-9]+)\\.([0-9]+)\\.([0-9]+)-?(.*)$") |
48 string(REGEX REPLACE "${protobuf_VERSION_REGEX}" "\\1" | 57 string(REGEX REPLACE "${protobuf_VERSION_REGEX}" "\\1" |
49 protobuf_VERSION_MAJOR "${protobuf_VERSION_STRING}") | 58 protobuf_VERSION_MAJOR "${protobuf_VERSION_STRING}") |
50 string(REGEX REPLACE "${protobuf_VERSION_REGEX}" "\\2" | 59 string(REGEX REPLACE "${protobuf_VERSION_REGEX}" "\\2" |
51 protobuf_VERSION_MINOR "${protobuf_VERSION_STRING}") | 60 protobuf_VERSION_MINOR "${protobuf_VERSION_STRING}") |
52 string(REGEX REPLACE "${protobuf_VERSION_REGEX}" "\\3" | 61 string(REGEX REPLACE "${protobuf_VERSION_REGEX}" "\\3" |
53 protobuf_VERSION_PATCH "${protobuf_VERSION_STRING}") | 62 protobuf_VERSION_PATCH "${protobuf_VERSION_STRING}") |
| 63 string(REGEX REPLACE "${protobuf_VERSION_REGEX}" "\\4" |
| 64 protobuf_VERSION_PRERELEASE "${protobuf_VERSION_STRING}") |
| 65 |
54 # Package version | 66 # Package version |
55 set(protobuf_VERSION | 67 set(protobuf_VERSION |
56 "${protobuf_VERSION_MAJOR}.${protobuf_VERSION_MINOR}.${protobuf_VERSION_PATCH}
") | 68 "${protobuf_VERSION_MAJOR}.${protobuf_VERSION_MINOR}.${protobuf_VERSION_PATCH}
") |
57 | 69 |
| 70 if(protobuf_VERSION_PRERELEASE) |
| 71 set(protobuf_VERSION "${protobuf_VERSION}-${protobuf_VERSION_PRERELEASE}") |
| 72 endif() |
| 73 |
58 if(protobuf_VERBOSE) | 74 if(protobuf_VERBOSE) |
59 message(STATUS "Configuration script parsing status [") | 75 message(STATUS "Configuration script parsing status [") |
60 message(STATUS " Description : ${protobuf_DESCRIPTION}") | 76 message(STATUS " Description : ${protobuf_DESCRIPTION}") |
61 message(STATUS " Version : ${protobuf_VERSION} (${protobuf_VERSION_STRING
})") | 77 message(STATUS " Version : ${protobuf_VERSION} (${protobuf_VERSION_STRING
})") |
62 message(STATUS " Contact : ${protobuf_CONTACT}") | 78 message(STATUS " Contact : ${protobuf_CONTACT}") |
63 message(STATUS "]") | 79 message(STATUS "]") |
64 endif() | 80 endif() |
65 | 81 |
66 add_definitions(-DGOOGLE_PROTOBUF_CMAKE_BUILD) | 82 add_definitions(-DGOOGLE_PROTOBUF_CMAKE_BUILD) |
67 | 83 |
68 find_package(Threads REQUIRED) | 84 find_package(Threads REQUIRED) |
69 if (CMAKE_USE_PTHREADS_INIT) | 85 if (CMAKE_USE_PTHREADS_INIT) |
70 add_definitions(-DHAVE_PTHREAD) | 86 add_definitions(-DHAVE_PTHREAD) |
71 endif (CMAKE_USE_PTHREADS_INIT) | 87 endif (CMAKE_USE_PTHREADS_INIT) |
72 | 88 |
| 89 set(_protobuf_FIND_ZLIB) |
73 if (protobuf_WITH_ZLIB) | 90 if (protobuf_WITH_ZLIB) |
74 find_package(ZLIB) | 91 find_package(ZLIB) |
75 if (ZLIB_FOUND) | 92 if (ZLIB_FOUND) |
76 set(HAVE_ZLIB 1) | 93 set(HAVE_ZLIB 1) |
77 # FindZLIB module define ZLIB_INCLUDE_DIRS variable | 94 # FindZLIB module define ZLIB_INCLUDE_DIRS variable |
78 # Set ZLIB_INCLUDE_DIRECTORIES for compatible | 95 # Set ZLIB_INCLUDE_DIRECTORIES for compatible |
79 set(ZLIB_INCLUDE_DIRECTORIES ${ZLIB_INCLUDE_DIRECTORIES} ${ZLIB_INCLUDE_DIRS
}) | 96 set(ZLIB_INCLUDE_DIRECTORIES ${ZLIB_INCLUDE_DIRECTORIES} ${ZLIB_INCLUDE_DIRS
}) |
80 # Using imported target if exists | 97 # Using imported target if exists |
81 if (TARGET ZLIB::ZLIB) | 98 if (TARGET ZLIB::ZLIB) |
82 set(ZLIB_LIBRARIES ZLIB::ZLIB) | 99 set(ZLIB_LIBRARIES ZLIB::ZLIB) |
| 100 set(_protobuf_FIND_ZLIB "if(NOT ZLIB_FOUND)\n find_package(ZLIB)\nendif()
") |
83 endif (TARGET ZLIB::ZLIB) | 101 endif (TARGET ZLIB::ZLIB) |
84 else (ZLIB_FOUND) | 102 else (ZLIB_FOUND) |
85 set(HAVE_ZLIB 0) | 103 set(HAVE_ZLIB 0) |
86 # Explicitly set these to empty (override NOT_FOUND) so cmake doesn't | 104 # Explicitly set these to empty (override NOT_FOUND) so cmake doesn't |
87 # complain when we use them later. | 105 # complain when we use them later. |
88 set(ZLIB_INCLUDE_DIRECTORIES) | 106 set(ZLIB_INCLUDE_DIRECTORIES) |
89 set(ZLIB_LIBRARIES) | 107 set(ZLIB_LIBRARIES) |
90 endif (ZLIB_FOUND) | 108 endif (ZLIB_FOUND) |
91 endif (protobuf_WITH_ZLIB) | 109 endif (protobuf_WITH_ZLIB) |
92 | 110 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 | 152 |
135 if (MSVC) | 153 if (MSVC) |
136 # Add the "lib" prefix for generated .lib outputs. | 154 # Add the "lib" prefix for generated .lib outputs. |
137 set(LIB_PREFIX lib) | 155 set(LIB_PREFIX lib) |
138 else (MSVC) | 156 else (MSVC) |
139 # When building with "make", "lib" prefix will be added automatically by | 157 # When building with "make", "lib" prefix will be added automatically by |
140 # the build tool. | 158 # the build tool. |
141 set(LIB_PREFIX) | 159 set(LIB_PREFIX) |
142 endif (MSVC) | 160 endif (MSVC) |
143 | 161 |
| 162 if (protobuf_UNICODE) |
| 163 add_definitions(-DUNICODE -D_UNICODE) |
| 164 endif (protobuf_UNICODE) |
| 165 |
144 include(libprotobuf-lite.cmake) | 166 include(libprotobuf-lite.cmake) |
145 include(libprotobuf.cmake) | 167 include(libprotobuf.cmake) |
146 include(libprotoc.cmake) | 168 include(libprotoc.cmake) |
147 include(protoc.cmake) | 169 include(protoc.cmake) |
148 | 170 |
149 if (protobuf_BUILD_TESTS) | 171 if (protobuf_BUILD_TESTS) |
150 include(tests.cmake) | 172 include(tests.cmake) |
151 endif (protobuf_BUILD_TESTS) | 173 endif (protobuf_BUILD_TESTS) |
152 | 174 |
153 include(install.cmake) | 175 include(install.cmake) |
| 176 |
| 177 if (protobuf_BUILD_EXAMPLES) |
| 178 include(examples.cmake) |
| 179 endif (protobuf_BUILD_EXAMPLES) |
| 180 |
| 181 if(protobuf_VERBOSE) |
| 182 message(STATUS "Protocol Buffers Configuring done") |
| 183 endif() |
OLD | NEW |