blob: 298780c97e2b3426e9fec469f72348132f7f8276 [file] [log] [blame]
Pascal Bachd5f87e12014-12-12 15:59:17 +01001#
2# Licensed to the Apache Software Foundation (ASF) under one
3# or more contributor license agreements. See the NOTICE file
4# distributed with this work for additional information
5# regarding copyright ownership. The ASF licenses this file
6# to you under the Apache License, Version 2.0 (the
7# "License"); you may not use this file except in compliance
8# with the License. You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing,
13# software distributed under the License is distributed on an
14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15# KIND, either express or implied. See the License for the
16# specific language governing permissions and limitations
17# under the License.
18#
19
James E. King, III07f59972017-03-10 06:18:33 -050020# Uncomment this to show some basic cmake variables about platforms
21# include (NewPlatformDebug)
Pascal Bachd5f87e12014-12-12 15:59:17 +010022
James E. King III278528c2019-01-11 12:17:44 -050023# For Debug build types, append a "d" to the library names.
24set(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "Set debug library postfix" FORCE)
25
Pascal Bachd5f87e12014-12-12 15:59:17 +010026# Visual Studio specific options
27if(MSVC)
James E. King III278528c2019-01-11 12:17:44 -050028 # Allow for shared library builds
29 if(BUILD_SHARED_LIBS)
30 set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON CACHE TYPE BOOL FORCE)
31 endif()
32
Pascal Bachd5f87e12014-12-12 15:59:17 +010033 #For visual studio the library naming is as following:
34 # Dynamic libraries:
Jim King9de9b1f2015-04-30 16:03:34 -040035 # - thrift.dll for release library
Pascal Bachd5f87e12014-12-12 15:59:17 +010036 # - thriftd.dll for debug library
37 #
38 # Static libraries:
39 # - thriftmd.lib for /MD release build
40 # - thriftmt.lib for /MT release build
41 #
42 # - thriftmdd.lib for /MD debug build
43 # - thriftmtd.lib for /MT debug build
44 #
45 # the same holds for other libraries like libthriftz etc.
46
Pascal Bachd5f87e12014-12-12 15:59:17 +010047 # Build using /MT option instead of /MD if the WITH_MT options is set
48 if(WITH_MT)
49 set(CompilerFlags
50 CMAKE_CXX_FLAGS
51 CMAKE_CXX_FLAGS_DEBUG
52 CMAKE_CXX_FLAGS_RELEASE
Jim King94d4f3e2016-11-10 16:31:28 -050053 CMAKE_CXX_FLAGS_RELWITHDEBINFO
Pascal Bachd5f87e12014-12-12 15:59:17 +010054 CMAKE_C_FLAGS
55 CMAKE_C_FLAGS_DEBUG
56 CMAKE_C_FLAGS_RELEASE
Jim King94d4f3e2016-11-10 16:31:28 -050057 CMAKE_C_FLAGS_RELWITHDEBINFO
Pascal Bachd5f87e12014-12-12 15:59:17 +010058 )
59 foreach(CompilerFlag ${CompilerFlags})
60 string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
61 endforeach()
James E. King III17355422019-01-11 23:06:08 -050062 set(THRIFT_RUNTIME_POSTFIX "mt" CACHE STRING "Set runtime library postfix" FORCE)
Pascal Bachd5f87e12014-12-12 15:59:17 +010063 else(WITH_MT)
James E. King III17355422019-01-11 23:06:08 -050064 set(THRIFT_RUNTIME_POSTFIX "md" CACHE STRING "Set runtime library postfix" FORCE)
Pascal Bachd5f87e12014-12-12 15:59:17 +010065 endif(WITH_MT)
Jim King1673adf2015-04-13 12:25:35 -040066
Jim King9de9b1f2015-04-30 16:03:34 -040067 # Disable boost auto linking pragmas - cmake includes the right files
68 add_definitions("-DBOOST_ALL_NO_LIB")
69
James E. King, III7edc8fa2017-01-20 10:11:41 -050070 add_definitions("/MP") # parallel build
71 add_definitions("/W3") # warning level 3
James E. King III17355422019-01-11 23:06:08 -050072
73 add_definitions("-DUNICODE -D_UNICODE")
Jim King1673adf2015-04-13 12:25:35 -040074elseif(UNIX)
Roger Meier446a3192015-05-09 23:40:54 +020075 find_program( MEMORYCHECK_COMMAND valgrind )
76 set( MEMORYCHECK_COMMAND_OPTIONS "--gen-suppressions=all --leak-check=full" )
77 set( MEMORYCHECK_SUPPRESSIONS_FILE "${PROJECT_SOURCE_DIR}/test/valgrind.suppress" )
Jim King1673adf2015-04-13 12:25:35 -040078endif()
Pascal Bachd5f87e12014-12-12 15:59:17 +010079
James E. King, III7edc8fa2017-01-20 10:11:41 -050080add_definitions("-D__STDC_FORMAT_MACROS")
James E. King III3ae30422018-03-12 07:33:22 -040081add_definitions("-D__STDC_LIMIT_MACROS")
James E. King, III7edc8fa2017-01-20 10:11:41 -050082
James E. King, III43e959b2017-04-04 13:04:29 -040083# C++ Language Level
cyy83b65f02019-01-05 11:06:50 +080084set(CXX_LANGUAGE_LEVEL "C++${CMAKE_CXX_STANDARD}")
85if (CMAKE_CXX_STANDARD_REQUIRED)
86 string(CONCAT CXX_LANGUAGE_LEVEL "${CXX_LANGUAGE_LEVEL} [compiler must support it]")
87else()
88 string(CONCAT CXX_LANGUAGE_LEVEL "${CXX_LANGUAGE_LEVEL} [fallback to earlier if compiler does not support it]")
89endif()
90if (CMAKE_CXX_EXTENSIONS)
91 string(CONCAT CXX_LANGUAGE_LEVEL "${CXX_LANGUAGE_LEVEL} [with compiler-specific extensions]")
James E. King, III43e959b2017-04-04 13:04:29 -040092endif()
93
94if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
95 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-register")
Pascal Bachd5f87e12014-12-12 15:59:17 +010096endif()
James E. King, IIIc9877fb2016-11-14 10:20:52 -050097
James E. King, III82ae9572017-08-05 12:23:54 -040098# Building WITH_PLUGIN requires boost memory operations, for now, and gcc >= 4.8
99if (WITH_PLUGIN)
100 if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.8")
101 message(SEND_ERROR "Thrift compiler plug-in support is not possible with older gcc ( < 4.8 ) compiler")
102 endif()
James E. King, IIIc9877fb2016-11-14 10:20:52 -0500103endif()
104