1# Protocol Buffers - Google's data interchange format 2# Copyright 2013 Google LLC All rights reserved. 3# 4# Use of this source code is governed by a BSD-style 5# license that can be found in the LICENSE file or at 6# https://developers.google.com/open-source/licenses/bsd 7 8# Refactors configuration options set on all Protobuf targets 9function(protobuf_configure_target target) 10 target_compile_features("${target}" PUBLIC cxx_std_14) 11 if (MSVC) 12 # Build with multiple processes 13 target_compile_options("${target}" PRIVATE /MP) 14 # Set source file and execution character sets to UTF-8 15 target_compile_options("${target}" PRIVATE /utf-8) 16 # MSVC warning suppressions 17 target_compile_options("${target}" PRIVATE 18 /wd4065 # switch statement contains 'default' but no 'case' labels 19 /wd4146 # unary minus operator applied to unsigned type 20 /wd4244 # 'conversion' conversion from 'type1' to 'type2', possible loss of data 21 /wd4251 # 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2' 22 /wd4267 # 'var' : conversion from 'size_t' to 'type', possible loss of data 23 /wd4305 # 'identifier' : truncation from 'type1' to 'type2' 24 /wd4307 # 'operator' : integral constant overflow 25 /wd4309 # 'conversion' : truncation of constant value 26 /wd4334 # 'operator' : result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?) 27 /wd4355 # 'this' : used in base member initializer list 28 /wd4506 # no definition for inline function 'function' 29 /wd4800 # 'type' : forcing value to bool 'true' or 'false' (performance warning) 30 /wd4996 # The compiler encountered a deprecated declaration. 31 ) 32 # Allow big object 33 target_compile_options("${target}" PRIVATE /bigobj) 34 endif () 35 if (protobuf_UNICODE) 36 target_compile_definitions("${target}" PRIVATE -DUNICODE -D_UNICODE) 37 endif () 38 target_compile_definitions("${target}" PRIVATE -DGOOGLE_PROTOBUF_CMAKE_BUILD) 39 40 if (protobuf_DISABLE_RTTI) 41 target_compile_definitions("${target}" PRIVATE -DGOOGLE_PROTOBUF_NO_RTTI=1) 42 endif() 43 44 # The Intel compiler isn't able to deal with noinline member functions of 45 # template classes defined in headers. As such it spams the output with 46 # warning #2196: routine is both "inline" and "noinline" 47 # This silences that warning. 48 if (CMAKE_CXX_COMPILER_ID MATCHES Intel) 49 target_compile_options("${target}" PRIVATE -diag-disable=2196) 50 endif() 51 52 if (HAVE_ZLIB) 53 target_compile_definitions("${target}" PRIVATE -DHAVE_ZLIB) 54 endif () 55 56 57endfunction () 58 59function(protobuf_configure_unity_target target) 60 if(protobuf_USE_UNITY_BUILD) 61 # UNITY_BUILD available in CMake >=3.18. 62 if(${CMAKE_VERSION} VERSION_GREATER 3.18 OR ${CMAKE_VERSION} VERSION_EQUAL 3.18) 63 # If protobuf_USE_UNITY_BUILD is set to ON, set target to use Unity builds. 64 set_target_properties("${target}" 65 PROPERTIES 66 UNITY_BUILD ON 67 UNITY_BUILD_MODE BATCH 68 UNITY_BUILD_BATCH_SIZE 50 69 ) 70 endif() 71 endif() 72endfunction () 73