blob: e57ecc2f9b9b9ba5202d998112d873cd548b3225 [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
20
21# Visual Studio specific options
22if(MSVC)
23 #For visual studio the library naming is as following:
24 # Dynamic libraries:
Jim King9de9b1f2015-04-30 16:03:34 -040025 # - thrift.dll for release library
Pascal Bachd5f87e12014-12-12 15:59:17 +010026 # - thriftd.dll for debug library
27 #
28 # Static libraries:
29 # - thriftmd.lib for /MD release build
30 # - thriftmt.lib for /MT release build
31 #
32 # - thriftmdd.lib for /MD debug build
33 # - thriftmtd.lib for /MT debug build
34 #
35 # the same holds for other libraries like libthriftz etc.
36
37 # For Debug build types, append a "d" to the library names.
38 set(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "Set debug library postfix" FORCE)
39 set(CMAKE_RELEASE_POSTFIX "" CACHE STRING "Set release library postfix" FORCE)
Jim King94d4f3e2016-11-10 16:31:28 -050040 set(CMAKE_RELWITHDEBINFO_POSTFIX "" CACHE STRING "Set release library postfix" FORCE)
Pascal Bachd5f87e12014-12-12 15:59:17 +010041
Pascal Bachd5f87e12014-12-12 15:59:17 +010042 # Build using /MT option instead of /MD if the WITH_MT options is set
43 if(WITH_MT)
44 set(CompilerFlags
45 CMAKE_CXX_FLAGS
46 CMAKE_CXX_FLAGS_DEBUG
47 CMAKE_CXX_FLAGS_RELEASE
Jim King94d4f3e2016-11-10 16:31:28 -050048 CMAKE_CXX_FLAGS_RELWITHDEBINFO
Pascal Bachd5f87e12014-12-12 15:59:17 +010049 CMAKE_C_FLAGS
50 CMAKE_C_FLAGS_DEBUG
51 CMAKE_C_FLAGS_RELEASE
Jim King94d4f3e2016-11-10 16:31:28 -050052 CMAKE_C_FLAGS_RELWITHDEBINFO
Pascal Bachd5f87e12014-12-12 15:59:17 +010053 )
54 foreach(CompilerFlag ${CompilerFlags})
55 string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
56 endforeach()
57 set(STATIC_POSTFIX "mt" CACHE STRING "Set static library postfix" FORCE)
58 else(WITH_MT)
59 set(STATIC_POSTFIX "md" CACHE STRING "Set static library postfix" FORCE)
60 endif(WITH_MT)
Jim King1673adf2015-04-13 12:25:35 -040061
Jim King9de9b1f2015-04-30 16:03:34 -040062 # Disable Windows.h definition of macros for min and max
63 add_definitions("-DNOMINMAX")
64
65 # Disable boost auto linking pragmas - cmake includes the right files
66 add_definitions("-DBOOST_ALL_NO_LIB")
67
68 # Windows build does not know how to make a shared library yet
69 # as there are no __declspec(dllexport) or exports files in the project.
70 if (WITH_SHARED_LIB)
Roger Meier86fded22015-05-15 12:01:38 +020071 message (FATAL_ERROR "Windows build does not support shared library output yet, please set -DWITH_SHARED_LIB=off")
Jim King9de9b1f2015-04-30 16:03:34 -040072 endif()
73
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
Roger Meiera6b66332015-05-15 15:21:50 +020080# WITH_*THREADS selects which threading library to use
81if(WITH_BOOSTTHREADS)
82 add_definitions("-DUSE_BOOST_THREAD=1")
83elseif(WITH_STDTHREADS)
84 add_definitions("-DUSE_STD_THREAD=1")
85endif()
86
Marco Molteni83494252015-04-16 13:50:20 +020087# GCC and Clang.
88if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
89 # FIXME -pedantic can not be used at the moment because of: https://issues.apache.org/jira/browse/THRIFT-2784
Pascal Bachd5f87e12014-12-12 15:59:17 +010090 #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O2 -Wall -Wextra -pedantic")
Marco Molteni83494252015-04-16 13:50:20 +020091 # FIXME enabling c++11 breaks some Linux builds on Travis by triggering a g++ bug, see
92 # https://travis-ci.org/apache/thrift/jobs/58017022
93 # on the other hand, both MacOSX and FreeBSD need c++11
94 if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin" OR ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
95 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O2 -Wall -Wextra")
96 endif()
Pascal Bachd5f87e12014-12-12 15:59:17 +010097endif()
James E. King, IIIc9877fb2016-11-14 10:20:52 -050098
99# If gcc older than 4.8 is detected, disable new compiler plug-in support (see THRIFT-3937)
100set(PLUGIN_COMPILER_NOT_TOO_OLD ON) # simplifies messaging in DefineOptions summary
101if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.8" AND WITH_PLUGIN)
102 message(STATUS "Disabling compiler plug-in support to work with older gcc compiler")
103 set(WITH_PLUGIN OFF)
104 set(PLUGIN_COMPILER_NOT_TOO_OLD OFF)
105endif()
106