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