Source release 17.1.0
This commit is contained in:
104
third_party/protobuf/cmake/CMakeLists.txt
vendored
104
third_party/protobuf/cmake/CMakeLists.txt
vendored
@@ -15,6 +15,10 @@ endif ()
|
||||
if(POLICY CMP0048)
|
||||
cmake_policy(SET CMP0048 NEW)
|
||||
endif()
|
||||
# MSVC runtime library flags are selected by an abstraction.
|
||||
if(POLICY CMP0091)
|
||||
cmake_policy(SET CMP0091 NEW)
|
||||
endif()
|
||||
|
||||
# Project
|
||||
project(protobuf C CXX)
|
||||
@@ -29,7 +33,7 @@ else()
|
||||
endif()
|
||||
|
||||
# The Intel compiler isn't able to deal with noinline member functions of
|
||||
# template classses defined in headers. As such it spams the output with
|
||||
# template classes defined in headers. As such it spams the output with
|
||||
# warning #2196: routine is both "inline" and "noinline"
|
||||
# This silences that warning.
|
||||
if (CMAKE_CXX_COMPILER_ID MATCHES Intel)
|
||||
@@ -37,10 +41,15 @@ if (CMAKE_CXX_COMPILER_ID MATCHES Intel)
|
||||
endif()
|
||||
|
||||
# Options
|
||||
if(WITH_PROTOC)
|
||||
set(protobuf_PROTOC_EXE ${WITH_PROTOC} CACHE FILEPATH "Protocol Buffer Compiler executable" FORCE)
|
||||
endif()
|
||||
option(protobuf_BUILD_TESTS "Build tests" ON)
|
||||
option(protobuf_BUILD_CONFORMANCE "Build conformance tests" OFF)
|
||||
option(protobuf_BUILD_EXAMPLES "Build examples" OFF)
|
||||
option(protobuf_BUILD_PROTOC_BINARIES "Build libprotoc and protoc compiler" ON)
|
||||
option(protobuf_BUILD_LIBPROTOC "Build libprotoc" OFF)
|
||||
option(protobuf_DISABLE_RTTI "Remove runtime type information in the binaries" OFF)
|
||||
if (BUILD_SHARED_LIBS)
|
||||
set(protobuf_BUILD_SHARED_LIBS_DEFAULT ON)
|
||||
else (BUILD_SHARED_LIBS)
|
||||
@@ -58,6 +67,10 @@ mark_as_advanced(protobuf_DEBUG_POSTFIX)
|
||||
# User options
|
||||
include(protobuf-options.cmake)
|
||||
|
||||
# Overrides for option dependencies
|
||||
if (protobuf_BUILD_PROTOC_BINARIES OR protobuf_BUILD_TESTS)
|
||||
set(protobuf_BUILD_LIBPROTOC ON)
|
||||
endif ()
|
||||
# Path to main configure script
|
||||
set(protobuf_CONFIGURE_SCRIPT "../configure.ac")
|
||||
|
||||
@@ -109,10 +122,11 @@ endif()
|
||||
|
||||
add_definitions(-DGOOGLE_PROTOBUF_CMAKE_BUILD)
|
||||
|
||||
if (protobuf_DISABLE_RTTI)
|
||||
add_definitions(-DGOOGLE_PROTOBUF_NO_RTTI=1)
|
||||
endif()
|
||||
|
||||
find_package(Threads REQUIRED)
|
||||
if (CMAKE_USE_PTHREADS_INIT)
|
||||
add_definitions(-DHAVE_PTHREAD)
|
||||
endif (CMAKE_USE_PTHREADS_INIT)
|
||||
|
||||
set(_protobuf_FIND_ZLIB)
|
||||
if (protobuf_WITH_ZLIB)
|
||||
@@ -163,25 +177,37 @@ if (protobuf_BUILD_SHARED_LIBS)
|
||||
set(protobuf_SHARED_OR_STATIC "SHARED")
|
||||
else (protobuf_BUILD_SHARED_LIBS)
|
||||
set(protobuf_SHARED_OR_STATIC "STATIC")
|
||||
# In case we are building static libraries, link also the runtime library statically
|
||||
# so that MSVCR*.DLL is not required at runtime.
|
||||
# https://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx
|
||||
# This is achieved by replacing msvc option /MD with /MT and /MDd with /MTd
|
||||
# http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F
|
||||
if (MSVC AND protobuf_MSVC_STATIC_RUNTIME)
|
||||
foreach(flag_var
|
||||
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
|
||||
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
|
||||
if(${flag_var} MATCHES "/MD")
|
||||
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
|
||||
endif(${flag_var} MATCHES "/MD")
|
||||
endforeach(flag_var)
|
||||
endif (MSVC AND protobuf_MSVC_STATIC_RUNTIME)
|
||||
# The CMAKE_<LANG>_FLAGS(_<BUILD_TYPE>)? is meant to be user controlled.
|
||||
# Prior to CMake 3.15, the MSVC runtime library was pushed into the same flags
|
||||
# making programmatic control difficult. Prefer the functionality in newer
|
||||
# CMake versions when available.
|
||||
if(CMAKE_VERSION VERSION_GREATER 3.15 OR CMAKE_VERSION VERSION_EQUAL 3.15)
|
||||
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded$<$<CONFIG:Debug>:Debug>)
|
||||
else()
|
||||
# In case we are building static libraries, link also the runtime library statically
|
||||
# so that MSVCR*.DLL is not required at runtime.
|
||||
# https://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx
|
||||
# This is achieved by replacing msvc option /MD with /MT and /MDd with /MTd
|
||||
# http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F
|
||||
if (MSVC AND protobuf_MSVC_STATIC_RUNTIME)
|
||||
foreach(flag_var
|
||||
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
|
||||
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
|
||||
if(${flag_var} MATCHES "/MD")
|
||||
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
|
||||
endif(${flag_var} MATCHES "/MD")
|
||||
endforeach(flag_var)
|
||||
endif (MSVC AND protobuf_MSVC_STATIC_RUNTIME)
|
||||
endif()
|
||||
endif (protobuf_BUILD_SHARED_LIBS)
|
||||
|
||||
if (MSVC)
|
||||
# Build with multiple processes
|
||||
add_definitions(/MP)
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
||||
# Build with multiple processes
|
||||
add_definitions(/MP)
|
||||
endif()
|
||||
# Set source file and execution character sets to UTF-8
|
||||
add_definitions(/utf-8)
|
||||
# MSVC warning suppressions
|
||||
add_definitions(
|
||||
/wd4018 # 'expression' : signed/unsigned mismatch
|
||||
@@ -209,12 +235,14 @@ if (MSVC)
|
||||
# Suppress linker warnings about files with no symbols defined.
|
||||
set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /ignore:4221")
|
||||
|
||||
# Configure Resource Compiler
|
||||
enable_language(RC)
|
||||
# use English language (0x409) in resource compiler
|
||||
set(rc_flags "/l0x409")
|
||||
# fix rc.exe invocations because of usage of add_definitions()
|
||||
set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> ${rc_flags} <DEFINES> /fo<OBJECT> <SOURCE>")
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
||||
# Configure Resource Compiler
|
||||
enable_language(RC)
|
||||
# use English language (0x409) in resource compiler
|
||||
set(rc_flags "/l0x409")
|
||||
# fix rc.exe invocations because of usage of add_definitions()
|
||||
set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> ${rc_flags} <DEFINES> /fo<OBJECT> <SOURCE>")
|
||||
endif()
|
||||
|
||||
configure_file(version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc @ONLY)
|
||||
endif (MSVC)
|
||||
@@ -242,11 +270,29 @@ endif (protobuf_UNICODE)
|
||||
|
||||
include(libprotobuf-lite.cmake)
|
||||
include(libprotobuf.cmake)
|
||||
if (protobuf_BUILD_PROTOC_BINARIES)
|
||||
if (protobuf_BUILD_LIBPROTOC)
|
||||
include(libprotoc.cmake)
|
||||
endif (protobuf_BUILD_LIBPROTOC)
|
||||
if (protobuf_BUILD_PROTOC_BINARIES)
|
||||
include(protoc.cmake)
|
||||
if (NOT DEFINED protobuf_PROTOC_EXE)
|
||||
set(protobuf_PROTOC_EXE protoc)
|
||||
endif (NOT DEFINED protobuf_PROTOC_EXE)
|
||||
endif (protobuf_BUILD_PROTOC_BINARIES)
|
||||
|
||||
# Ensure we have a protoc executable if we need one
|
||||
if (protobuf_BUILD_TESTS OR protobuf_BUILD_CONFORMANCE OR protobuf_BUILD_EXAMPLES)
|
||||
if (NOT DEFINED protobuf_PROTOC_EXE)
|
||||
find_program(protobuf_PROTOC_EXE protoc)
|
||||
if (NOT protobuf_PROTOC_EXE)
|
||||
message(FATAL "Build requires 'protoc' but binary not found and not building protoc.")
|
||||
endif ()
|
||||
endif ()
|
||||
if(protobuf_VERBOSE)
|
||||
message(STATUS "Using protoc : ${protobuf_PROTOC_EXE}")
|
||||
endif(protobuf_VERBOSE)
|
||||
endif ()
|
||||
|
||||
if (protobuf_BUILD_TESTS)
|
||||
include(tests.cmake)
|
||||
endif (protobuf_BUILD_TESTS)
|
||||
@@ -262,5 +308,5 @@ if (protobuf_BUILD_EXAMPLES)
|
||||
endif (protobuf_BUILD_EXAMPLES)
|
||||
|
||||
if(protobuf_VERBOSE)
|
||||
message(STATUS "Protocol Buffers Configuring done")
|
||||
endif()
|
||||
message(STATUS "Protocol Buffers Configuring done")
|
||||
endif(protobuf_VERBOSE)
|
||||
|
||||
Reference in New Issue
Block a user