Konstantin Podsvirov | 8298343 | 2015-07-31 23:36:00 +0300 | [diff] [blame] | 1 | # Minimum CMake required |
Corentin Le Molgat | c3b152c | 2018-04-24 17:13:15 +0200 | [diff] [blame] | 2 | cmake_minimum_required(VERSION 3.1.3) |
Feng Xiao | 4333edb | 2015-05-31 02:28:34 -0700 | [diff] [blame] | 3 | |
Konstantin Podsvirov | 7155629 | 2016-06-01 17:00:08 +0300 | [diff] [blame] | 4 | if(protobuf_VERBOSE) |
| 5 | message(STATUS "Protocol Buffers Configuring...") |
| 6 | endif() |
Feng Xiao | 4333edb | 2015-05-31 02:28:34 -0700 | [diff] [blame] | 7 | |
Konstantin Podsvirov | 905f464 | 2015-09-01 16:44:48 +0300 | [diff] [blame] | 8 | # CMake policies |
| 9 | cmake_policy(SET CMP0022 NEW) |
Mizux | 7306f54 | 2018-05-22 21:52:07 +0200 | [diff] [blame] | 10 | # On MacOS use @rpath/ for target's install name prefix path |
| 11 | if (POLICY CMP0042) |
| 12 | cmake_policy(SET CMP0042 NEW) |
| 13 | endif () |
| 14 | # Clear VERSION variables when no VERSION is given to project() |
Corentin Le Molgat | 1ec9beb | 2018-01-29 15:31:06 +0100 | [diff] [blame] | 15 | if(POLICY CMP0048) |
| 16 | cmake_policy(SET CMP0048 NEW) |
| 17 | endif() |
| 18 | |
Konstantin Podsvirov | 7155629 | 2016-06-01 17:00:08 +0300 | [diff] [blame] | 19 | # Project |
| 20 | project(protobuf C CXX) |
| 21 | |
Corentin Le Molgat | c3b152c | 2018-04-24 17:13:15 +0200 | [diff] [blame] | 22 | # Add c++11 flags |
Ivan Shynkarenka | f80a886 | 2018-05-02 02:51:08 +0300 | [diff] [blame] | 23 | if (CYGWIN) |
| 24 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11") |
| 25 | else() |
| 26 | set(CMAKE_CXX_STANDARD 11) |
| 27 | set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 28 | set(CMAKE_CXX_EXTENSIONS OFF) |
| 29 | endif() |
Silver Chan | d3e8a54 | 2018-04-04 10:31:05 +0800 | [diff] [blame] | 30 | |
Chuck Atkins | 10c48c9 | 2020-02-11 10:22:38 -0500 | [diff] [blame] | 31 | # The Intel compiler isn't able to deal with noinline member functions of |
Peter Newman | e2cc2de | 2020-08-10 19:08:25 +0100 | [diff] [blame] | 32 | # template classes defined in headers. As such it spams the output with |
Chuck Atkins | 10c48c9 | 2020-02-11 10:22:38 -0500 | [diff] [blame] | 33 | # warning #2196: routine is both "inline" and "noinline" |
| 34 | # This silences that warning. |
| 35 | if (CMAKE_CXX_COMPILER_ID MATCHES Intel) |
| 36 | string(APPEND CMAKE_CXX_FLAGS " -diag-disable=2196") |
| 37 | endif() |
| 38 | |
Konstantin Podsvirov | 8298343 | 2015-07-31 23:36:00 +0300 | [diff] [blame] | 39 | # Options |
Michael WERLE | 976f85b | 2020-05-01 16:50:53 +0900 | [diff] [blame] | 40 | if(WITH_PROTOC) |
| 41 | set(protobuf_PROTOC_EXE ${WITH_PROTOC} CACHE FILEPATH "Protocol Buffer Compiler executable" FORCE) |
| 42 | endif() |
Konstantin Podsvirov | 673d32e | 2015-09-15 15:30:02 +0300 | [diff] [blame] | 43 | option(protobuf_BUILD_TESTS "Build tests" ON) |
Josh Haberman | 4249692 | 2018-08-24 12:27:21 -0700 | [diff] [blame] | 44 | option(protobuf_BUILD_CONFORMANCE "Build conformance tests" OFF) |
Konstantin Podsvirov | 7155629 | 2016-06-01 17:00:08 +0300 | [diff] [blame] | 45 | option(protobuf_BUILD_EXAMPLES "Build examples" OFF) |
Yangqing Jia | cba18ef | 2017-11-13 15:15:39 -0800 | [diff] [blame] | 46 | option(protobuf_BUILD_PROTOC_BINARIES "Build libprotoc and protoc compiler" ON) |
Daniel Joos | c8f7633 | 2020-10-10 00:54:39 +0200 | [diff] [blame] | 47 | option(protobuf_BUILD_LIBPROTOC "Build libprotoc" OFF) |
Florian Simon | b9a036b | 2021-03-04 11:39:28 -0500 | [diff] [blame] | 48 | option(protobuf_DISABLE_RTTI "Remove runtime type information in the binaries" OFF) |
Konstantin Podsvirov | c3aa4c2 | 2015-10-15 02:56:48 +0300 | [diff] [blame] | 49 | if (BUILD_SHARED_LIBS) |
| 50 | set(protobuf_BUILD_SHARED_LIBS_DEFAULT ON) |
| 51 | else (BUILD_SHARED_LIBS) |
| 52 | set(protobuf_BUILD_SHARED_LIBS_DEFAULT OFF) |
| 53 | endif (BUILD_SHARED_LIBS) |
| 54 | option(protobuf_BUILD_SHARED_LIBS "Build Shared Libraries" ${protobuf_BUILD_SHARED_LIBS_DEFAULT}) |
Walter Gray | 4150a91 | 2016-06-09 13:25:27 -0700 | [diff] [blame] | 55 | include(CMakeDependentOption) |
Rafi Kamal | de75651 | 2019-11-20 18:03:29 -0800 | [diff] [blame] | 56 | cmake_dependent_option(protobuf_MSVC_STATIC_RUNTIME "Link static runtime libraries" ON |
| 57 | "NOT protobuf_BUILD_SHARED_LIBS" OFF) |
Corentin Le Molgat | 8dd0f4e | 2018-01-29 15:16:40 +0100 | [diff] [blame] | 58 | set(protobuf_WITH_ZLIB_DEFAULT ON) |
Konstantin Podsvirov | 620bd74 | 2015-09-15 15:31:25 +0300 | [diff] [blame] | 59 | option(protobuf_WITH_ZLIB "Build with zlib support" ${protobuf_WITH_ZLIB_DEFAULT}) |
Konstantin Podsvirov | f397ede | 2015-09-17 13:00:12 +0300 | [diff] [blame] | 60 | set(protobuf_DEBUG_POSTFIX "d" |
| 61 | CACHE STRING "Default debug postfix") |
Konstantin Podsvirov | 7155629 | 2016-06-01 17:00:08 +0300 | [diff] [blame] | 62 | mark_as_advanced(protobuf_DEBUG_POSTFIX) |
| 63 | # User options |
Walter Gray | 23fef56 | 2016-06-06 10:59:58 -0700 | [diff] [blame] | 64 | include(protobuf-options.cmake) |
Feng Xiao | 4333edb | 2015-05-31 02:28:34 -0700 | [diff] [blame] | 65 | |
Michael WERLE | 976f85b | 2020-05-01 16:50:53 +0900 | [diff] [blame] | 66 | # Overrides for option dependencies |
| 67 | if (protobuf_BUILD_PROTOC_BINARIES OR protobuf_BUILD_TESTS) |
| 68 | set(protobuf_BUILD_LIBPROTOC ON) |
Michael WERLE | 976f85b | 2020-05-01 16:50:53 +0900 | [diff] [blame] | 69 | endif () |
Konstantin Podsvirov | 743ec44 | 2015-08-01 02:01:42 +0300 | [diff] [blame] | 70 | # Path to main configure script |
| 71 | set(protobuf_CONFIGURE_SCRIPT "../configure.ac") |
Konstantin Podsvirov | 8298343 | 2015-07-31 23:36:00 +0300 | [diff] [blame] | 72 | |
Konstantin Podsvirov | db01460 | 2015-08-31 15:20:18 +0300 | [diff] [blame] | 73 | # Parse configure script |
| 74 | set(protobuf_AC_INIT_REGEX |
| 75 | "^AC_INIT\\(\\[([^]]+)\\],\\[([^]]+)\\],\\[([^]]+)\\],\\[([^]]+)\\]\\)$") |
| 76 | file(STRINGS "${protobuf_CONFIGURE_SCRIPT}" protobuf_AC_INIT_LINE |
| 77 | LIMIT_COUNT 1 REGEX "^AC_INIT") |
| 78 | # Description |
| 79 | string(REGEX REPLACE "${protobuf_AC_INIT_REGEX}" "\\1" |
| 80 | protobuf_DESCRIPTION "${protobuf_AC_INIT_LINE}") |
| 81 | # Version |
| 82 | string(REGEX REPLACE "${protobuf_AC_INIT_REGEX}" "\\2" |
| 83 | protobuf_VERSION_STRING "${protobuf_AC_INIT_LINE}") |
| 84 | # Contact |
| 85 | string(REGEX REPLACE "${protobuf_AC_INIT_REGEX}" "\\3" |
| 86 | protobuf_CONTACT "${protobuf_AC_INIT_LINE}") |
Konstantin Podsvirov | 743ec44 | 2015-08-01 02:01:42 +0300 | [diff] [blame] | 87 | # Parse version tweaks |
Paul Yang | 5b4ac53 | 2019-02-01 18:43:55 -0800 | [diff] [blame] | 88 | set(protobuf_VERSION_REGEX "^([0-9]+)\\.([0-9]+)\\.([0-9]+)([-]rc[-]|\\.)?([0-9]*)$") |
Konstantin Podsvirov | db01460 | 2015-08-31 15:20:18 +0300 | [diff] [blame] | 89 | string(REGEX REPLACE "${protobuf_VERSION_REGEX}" "\\1" |
Konstantin Podsvirov | 743ec44 | 2015-08-01 02:01:42 +0300 | [diff] [blame] | 90 | protobuf_VERSION_MAJOR "${protobuf_VERSION_STRING}") |
Konstantin Podsvirov | db01460 | 2015-08-31 15:20:18 +0300 | [diff] [blame] | 91 | string(REGEX REPLACE "${protobuf_VERSION_REGEX}" "\\2" |
Konstantin Podsvirov | 743ec44 | 2015-08-01 02:01:42 +0300 | [diff] [blame] | 92 | protobuf_VERSION_MINOR "${protobuf_VERSION_STRING}") |
Konstantin Podsvirov | db01460 | 2015-08-31 15:20:18 +0300 | [diff] [blame] | 93 | string(REGEX REPLACE "${protobuf_VERSION_REGEX}" "\\3" |
Konstantin Podsvirov | 743ec44 | 2015-08-01 02:01:42 +0300 | [diff] [blame] | 94 | protobuf_VERSION_PATCH "${protobuf_VERSION_STRING}") |
Paul Yang | 5b4ac53 | 2019-02-01 18:43:55 -0800 | [diff] [blame] | 95 | string(REGEX REPLACE "${protobuf_VERSION_REGEX}" "\\5" |
Walter Gray | f1091ab | 2016-05-27 22:48:24 -0700 | [diff] [blame] | 96 | protobuf_VERSION_PRERELEASE "${protobuf_VERSION_STRING}") |
| 97 | |
Paul Yang | 5b4ac53 | 2019-02-01 18:43:55 -0800 | [diff] [blame] | 98 | message(STATUS "${protobuf_VERSION_PRERELEASE}") |
| 99 | |
Konstantin Podsvirov | 743ec44 | 2015-08-01 02:01:42 +0300 | [diff] [blame] | 100 | # Package version |
Konstantin Podsvirov | 8298343 | 2015-07-31 23:36:00 +0300 | [diff] [blame] | 101 | set(protobuf_VERSION |
Konstantin Podsvirov | 743ec44 | 2015-08-01 02:01:42 +0300 | [diff] [blame] | 102 | "${protobuf_VERSION_MAJOR}.${protobuf_VERSION_MINOR}.${protobuf_VERSION_PATCH}") |
Konstantin Podsvirov | 8298343 | 2015-07-31 23:36:00 +0300 | [diff] [blame] | 103 | |
Walter Gray | f1091ab | 2016-05-27 22:48:24 -0700 | [diff] [blame] | 104 | if(protobuf_VERSION_PRERELEASE) |
Paul Yang | 5b4ac53 | 2019-02-01 18:43:55 -0800 | [diff] [blame] | 105 | set(protobuf_VERSION "${protobuf_VERSION}.${protobuf_VERSION_PRERELEASE}") |
| 106 | else() |
| 107 | set(protobuf_VERSION "${protobuf_VERSION}.0") |
Walter Gray | f1091ab | 2016-05-27 22:48:24 -0700 | [diff] [blame] | 108 | endif() |
Paul Yang | 5b4ac53 | 2019-02-01 18:43:55 -0800 | [diff] [blame] | 109 | message(STATUS "${protobuf_VERSION}") |
Walter Gray | f1091ab | 2016-05-27 22:48:24 -0700 | [diff] [blame] | 110 | |
Konstantin Podsvirov | db01460 | 2015-08-31 15:20:18 +0300 | [diff] [blame] | 111 | if(protobuf_VERBOSE) |
| 112 | message(STATUS "Configuration script parsing status [") |
| 113 | message(STATUS " Description : ${protobuf_DESCRIPTION}") |
| 114 | message(STATUS " Version : ${protobuf_VERSION} (${protobuf_VERSION_STRING})") |
| 115 | message(STATUS " Contact : ${protobuf_CONTACT}") |
| 116 | message(STATUS "]") |
| 117 | endif() |
| 118 | |
Jisi Liu | 78d470c | 2015-06-12 15:49:21 -0700 | [diff] [blame] | 119 | add_definitions(-DGOOGLE_PROTOBUF_CMAKE_BUILD) |
| 120 | |
Florian Simon | 1add7a7 | 2021-02-25 15:11:40 -0500 | [diff] [blame] | 121 | if (protobuf_DISABLE_RTTI) |
| 122 | add_definitions(-DGOOGLE_PROTOBUF_NO_RTTI=1) |
| 123 | endif() |
| 124 | |
Feng Xiao | 4333edb | 2015-05-31 02:28:34 -0700 | [diff] [blame] | 125 | find_package(Threads REQUIRED) |
| 126 | if (CMAKE_USE_PTHREADS_INIT) |
Jisi Liu | 78d470c | 2015-06-12 15:49:21 -0700 | [diff] [blame] | 127 | add_definitions(-DHAVE_PTHREAD) |
Feng Xiao | 4333edb | 2015-05-31 02:28:34 -0700 | [diff] [blame] | 128 | endif (CMAKE_USE_PTHREADS_INIT) |
| 129 | |
Konstantin Podsvirov | eefd1fd | 2016-08-02 22:37:36 +0300 | [diff] [blame] | 130 | set(_protobuf_FIND_ZLIB) |
Konstantin Podsvirov | 620bd74 | 2015-09-15 15:31:25 +0300 | [diff] [blame] | 131 | if (protobuf_WITH_ZLIB) |
Feng Xiao | 4333edb | 2015-05-31 02:28:34 -0700 | [diff] [blame] | 132 | find_package(ZLIB) |
| 133 | if (ZLIB_FOUND) |
| 134 | set(HAVE_ZLIB 1) |
Konstantin Podsvirov | 20b882d | 2015-08-31 16:23:40 +0300 | [diff] [blame] | 135 | # FindZLIB module define ZLIB_INCLUDE_DIRS variable |
| 136 | # Set ZLIB_INCLUDE_DIRECTORIES for compatible |
| 137 | set(ZLIB_INCLUDE_DIRECTORIES ${ZLIB_INCLUDE_DIRECTORIES} ${ZLIB_INCLUDE_DIRS}) |
| 138 | # Using imported target if exists |
| 139 | if (TARGET ZLIB::ZLIB) |
| 140 | set(ZLIB_LIBRARIES ZLIB::ZLIB) |
Konstantin Podsvirov | eefd1fd | 2016-08-02 22:37:36 +0300 | [diff] [blame] | 141 | set(_protobuf_FIND_ZLIB "if(NOT ZLIB_FOUND)\n find_package(ZLIB)\nendif()") |
Konstantin Podsvirov | 20b882d | 2015-08-31 16:23:40 +0300 | [diff] [blame] | 142 | endif (TARGET ZLIB::ZLIB) |
Feng Xiao | 4333edb | 2015-05-31 02:28:34 -0700 | [diff] [blame] | 143 | else (ZLIB_FOUND) |
| 144 | set(HAVE_ZLIB 0) |
| 145 | # Explicitly set these to empty (override NOT_FOUND) so cmake doesn't |
| 146 | # complain when we use them later. |
| 147 | set(ZLIB_INCLUDE_DIRECTORIES) |
| 148 | set(ZLIB_LIBRARIES) |
| 149 | endif (ZLIB_FOUND) |
Konstantin Podsvirov | 620bd74 | 2015-09-15 15:31:25 +0300 | [diff] [blame] | 150 | endif (protobuf_WITH_ZLIB) |
Feng Xiao | 4333edb | 2015-05-31 02:28:34 -0700 | [diff] [blame] | 151 | |
Jisi Liu | 78d470c | 2015-06-12 15:49:21 -0700 | [diff] [blame] | 152 | if (HAVE_ZLIB) |
| 153 | add_definitions(-DHAVE_ZLIB) |
| 154 | endif (HAVE_ZLIB) |
| 155 | |
boscosiu | 55ed1d4 | 2019-07-03 06:34:09 -0700 | [diff] [blame] | 156 | # We need to link with libatomic on systems that do not have builtin atomics, or |
| 157 | # don't have builtin support for 8 byte atomics |
| 158 | set(protobuf_LINK_LIBATOMIC false) |
| 159 | if (NOT MSVC) |
| 160 | include(CheckCXXSourceCompiles) |
Ben Bader | 56e7bdf | 2019-07-08 11:13:53 -0700 | [diff] [blame] | 161 | set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) |
| 162 | set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} -std=c++11) |
boscosiu | 55ed1d4 | 2019-07-03 06:34:09 -0700 | [diff] [blame] | 163 | check_cxx_source_compiles(" |
| 164 | #include <atomic> |
| 165 | int main() { |
| 166 | return std::atomic<int64_t>{}; |
| 167 | } |
| 168 | " protobuf_HAVE_BUILTIN_ATOMICS) |
| 169 | if (NOT protobuf_HAVE_BUILTIN_ATOMICS) |
| 170 | set(protobuf_LINK_LIBATOMIC true) |
| 171 | endif (NOT protobuf_HAVE_BUILTIN_ATOMICS) |
Ben Bader | 56e7bdf | 2019-07-08 11:13:53 -0700 | [diff] [blame] | 172 | set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS}) |
boscosiu | 55ed1d4 | 2019-07-03 06:34:09 -0700 | [diff] [blame] | 173 | endif (NOT MSVC) |
| 174 | |
Konstantin Podsvirov | c3aa4c2 | 2015-10-15 02:56:48 +0300 | [diff] [blame] | 175 | if (protobuf_BUILD_SHARED_LIBS) |
| 176 | set(protobuf_SHARED_OR_STATIC "SHARED") |
| 177 | else (protobuf_BUILD_SHARED_LIBS) |
| 178 | set(protobuf_SHARED_OR_STATIC "STATIC") |
Rafi Kamal | de75651 | 2019-11-20 18:03:29 -0800 | [diff] [blame] | 179 | # In case we are building static libraries, link also the runtime library statically |
| 180 | # so that MSVCR*.DLL is not required at runtime. |
| 181 | # https://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx |
| 182 | # This is achieved by replacing msvc option /MD with /MT and /MDd with /MTd |
| 183 | # http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F |
| 184 | if (MSVC AND protobuf_MSVC_STATIC_RUNTIME) |
| 185 | foreach(flag_var |
| 186 | CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE |
| 187 | CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) |
| 188 | if(${flag_var} MATCHES "/MD") |
| 189 | string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") |
| 190 | endif(${flag_var} MATCHES "/MD") |
| 191 | endforeach(flag_var) |
| 192 | endif (MSVC AND protobuf_MSVC_STATIC_RUNTIME) |
Konstantin Podsvirov | c3aa4c2 | 2015-10-15 02:56:48 +0300 | [diff] [blame] | 193 | endif (protobuf_BUILD_SHARED_LIBS) |
Feng Xiao | 4333edb | 2015-05-31 02:28:34 -0700 | [diff] [blame] | 194 | |
Feng Xiao | dffd542 | 2015-06-05 17:59:09 -0700 | [diff] [blame] | 195 | if (MSVC) |
Benjamin Bennett | 9fc4d90 | 2015-12-07 13:54:02 -0600 | [diff] [blame] | 196 | # Build with multiple processes |
| 197 | add_definitions(/MP) |
Tim Ebringer | a23669c | 2017-10-21 09:40:32 -0400 | [diff] [blame] | 198 | # MSVC warning suppressions |
| 199 | add_definitions( |
| 200 | /wd4018 # 'expression' : signed/unsigned mismatch |
| 201 | /wd4065 # switch statement contains 'default' but no 'case' labels |
| 202 | /wd4146 # unary minus operator applied to unsigned type, result still unsigned |
| 203 | /wd4244 # 'conversion' conversion from 'type1' to 'type2', possible loss of data |
| 204 | /wd4251 # 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2' |
| 205 | /wd4267 # 'var' : conversion from 'size_t' to 'type', possible loss of data |
| 206 | /wd4305 # 'identifier' : truncation from 'type1' to 'type2' |
| 207 | /wd4307 # 'operator' : integral constant overflow |
| 208 | /wd4309 # 'conversion' : truncation of constant value |
| 209 | /wd4334 # 'operator' : result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?) |
| 210 | /wd4355 # 'this' : used in base member initializer list |
| 211 | /wd4506 # no definition for inline function 'function' |
| 212 | /wd4800 # 'type' : forcing value to bool 'true' or 'false' (performance warning) |
| 213 | /wd4996 # The compiler encountered a deprecated declaration. |
| 214 | ) |
Jisi Liu | 3b6df06 | 2016-04-01 15:02:45 -0700 | [diff] [blame] | 215 | # Allow big object |
| 216 | add_definitions(/bigobj) |
Feng Xiao | dffd542 | 2015-06-05 17:59:09 -0700 | [diff] [blame] | 217 | string(REPLACE "/" "\\" PROTOBUF_SOURCE_WIN32_PATH ${protobuf_SOURCE_DIR}) |
| 218 | string(REPLACE "/" "\\" PROTOBUF_BINARY_WIN32_PATH ${protobuf_BINARY_DIR}) |
Jozef Izso | 3415201 | 2018-04-27 23:44:38 +0200 | [diff] [blame] | 219 | string(REPLACE "." "," protobuf_RC_FILEVERSION "${protobuf_VERSION}") |
Feng Xiao | dffd542 | 2015-06-05 17:59:09 -0700 | [diff] [blame] | 220 | configure_file(extract_includes.bat.in extract_includes.bat) |
Ivan Shynkarenka | f80a886 | 2018-05-02 02:51:08 +0300 | [diff] [blame] | 221 | |
Tim Ebringer | 2a72840 | 2017-10-06 14:26:43 -0400 | [diff] [blame] | 222 | # Suppress linker warnings about files with no symbols defined. |
Changming Sun | 95a1c4f | 2019-06-04 16:39:10 -0700 | [diff] [blame] | 223 | set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /ignore:4221") |
Jozef Izso | 3415201 | 2018-04-27 23:44:38 +0200 | [diff] [blame] | 224 | |
| 225 | # Configure Resource Compiler |
| 226 | enable_language(RC) |
| 227 | # use English language (0x409) in resource compiler |
| 228 | set(rc_flags "/l0x409") |
| 229 | # fix rc.exe invocations because of usage of add_definitions() |
| 230 | set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> ${rc_flags} <DEFINES> /fo<OBJECT> <SOURCE>") |
| 231 | |
| 232 | configure_file(version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc @ONLY) |
Feng Xiao | dffd542 | 2015-06-05 17:59:09 -0700 | [diff] [blame] | 233 | endif (MSVC) |
Feng Xiao | 4333edb | 2015-05-31 02:28:34 -0700 | [diff] [blame] | 234 | |
Jozef Izso | 3415201 | 2018-04-27 23:44:38 +0200 | [diff] [blame] | 235 | |
Feng Xiao | 4333edb | 2015-05-31 02:28:34 -0700 | [diff] [blame] | 236 | get_filename_component(protobuf_source_dir ${protobuf_SOURCE_DIR} PATH) |
| 237 | |
| 238 | include_directories( |
| 239 | ${ZLIB_INCLUDE_DIRECTORIES} |
| 240 | ${protobuf_BINARY_DIR} |
| 241 | ${protobuf_source_dir}/src) |
| 242 | |
| 243 | if (MSVC) |
| 244 | # Add the "lib" prefix for generated .lib outputs. |
| 245 | set(LIB_PREFIX lib) |
| 246 | else (MSVC) |
| 247 | # When building with "make", "lib" prefix will be added automatically by |
| 248 | # the build tool. |
| 249 | set(LIB_PREFIX) |
| 250 | endif (MSVC) |
| 251 | |
Wei-Yin Chen (陳威尹) | a7eaf36 | 2016-09-01 17:12:49 -0700 | [diff] [blame] | 252 | if (protobuf_UNICODE) |
Wei-Yin Chen (陳威尹) | 588a803 | 2016-08-19 15:25:54 -0700 | [diff] [blame] | 253 | add_definitions(-DUNICODE -D_UNICODE) |
Wei-Yin Chen (陳威尹) | a7eaf36 | 2016-09-01 17:12:49 -0700 | [diff] [blame] | 254 | endif (protobuf_UNICODE) |
Wei-Yin Chen (陳威尹) | 588a803 | 2016-08-19 15:25:54 -0700 | [diff] [blame] | 255 | |
Feng Xiao | 4333edb | 2015-05-31 02:28:34 -0700 | [diff] [blame] | 256 | include(libprotobuf-lite.cmake) |
| 257 | include(libprotobuf.cmake) |
Michael WERLE | 976f85b | 2020-05-01 16:50:53 +0900 | [diff] [blame] | 258 | if (protobuf_BUILD_LIBPROTOC) |
Yangqing Jia | cba18ef | 2017-11-13 15:15:39 -0800 | [diff] [blame] | 259 | include(libprotoc.cmake) |
Michael WERLE | 976f85b | 2020-05-01 16:50:53 +0900 | [diff] [blame] | 260 | endif (protobuf_BUILD_LIBPROTOC) |
| 261 | if (protobuf_BUILD_PROTOC_BINARIES) |
Yangqing Jia | cba18ef | 2017-11-13 15:15:39 -0800 | [diff] [blame] | 262 | include(protoc.cmake) |
Michael WERLE | 976f85b | 2020-05-01 16:50:53 +0900 | [diff] [blame] | 263 | if (NOT DEFINED protobuf_PROTOC_EXE) |
| 264 | set(protobuf_PROTOC_EXE protoc) |
| 265 | endif (NOT DEFINED protobuf_PROTOC_EXE) |
Yangqing Jia | cba18ef | 2017-11-13 15:15:39 -0800 | [diff] [blame] | 266 | endif (protobuf_BUILD_PROTOC_BINARIES) |
Konstantin Podsvirov | 8298343 | 2015-07-31 23:36:00 +0300 | [diff] [blame] | 267 | |
Michael WERLE | 976f85b | 2020-05-01 16:50:53 +0900 | [diff] [blame] | 268 | # Ensure we have a protoc executable if we need one |
| 269 | if (protobuf_BUILD_TESTS OR protobuf_BUILD_CONFORMANCE OR protobuf_BUILD_EXAMPLES) |
| 270 | if (NOT DEFINED protobuf_PROTOC_EXE) |
| 271 | find_program(protobuf_PROTOC_EXE protoc) |
| 272 | if (NOT protobuf_PROTOC_EXE) |
| 273 | message(FATAL "Build requires 'protoc' but binary not found and not building protoc.") |
| 274 | endif () |
| 275 | endif () |
| 276 | if(protobuf_VERBOSE) |
| 277 | message(STATUS "Using protoc : ${protobuf_PROTOC_EXE}") |
| 278 | endif(protobuf_VERBOSE) |
| 279 | endif () |
| 280 | |
Konstantin Podsvirov | 673d32e | 2015-09-15 15:30:02 +0300 | [diff] [blame] | 281 | if (protobuf_BUILD_TESTS) |
Feng Xiao | e9839ff | 2015-06-05 21:24:23 -0700 | [diff] [blame] | 282 | include(tests.cmake) |
Konstantin Podsvirov | 673d32e | 2015-09-15 15:30:02 +0300 | [diff] [blame] | 283 | endif (protobuf_BUILD_TESTS) |
Konstantin Podsvirov | 8298343 | 2015-07-31 23:36:00 +0300 | [diff] [blame] | 284 | |
Josh Haberman | 4249692 | 2018-08-24 12:27:21 -0700 | [diff] [blame] | 285 | if (protobuf_BUILD_CONFORMANCE) |
| 286 | include(conformance.cmake) |
| 287 | endif (protobuf_BUILD_CONFORMANCE) |
| 288 | |
Konstantin Podsvirov | 8298343 | 2015-07-31 23:36:00 +0300 | [diff] [blame] | 289 | include(install.cmake) |
Konstantin Podsvirov | 7155629 | 2016-06-01 17:00:08 +0300 | [diff] [blame] | 290 | |
| 291 | if (protobuf_BUILD_EXAMPLES) |
| 292 | include(examples.cmake) |
| 293 | endif (protobuf_BUILD_EXAMPLES) |
| 294 | |
| 295 | if(protobuf_VERBOSE) |
Michael WERLE | 976f85b | 2020-05-01 16:50:53 +0900 | [diff] [blame] | 296 | message(STATUS "Protocol Buffers Configuring done") |
| 297 | endif(protobuf_VERBOSE) |