blob: 07272ce1a72563455d8b8499cf455aa8a1a41f7d [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)
40
Pascal Bachd5f87e12014-12-12 15:59:17 +010041 # Build using /MT option instead of /MD if the WITH_MT options is set
42 if(WITH_MT)
43 set(CompilerFlags
44 CMAKE_CXX_FLAGS
45 CMAKE_CXX_FLAGS_DEBUG
46 CMAKE_CXX_FLAGS_RELEASE
47 CMAKE_C_FLAGS
48 CMAKE_C_FLAGS_DEBUG
49 CMAKE_C_FLAGS_RELEASE
50 )
51 foreach(CompilerFlag ${CompilerFlags})
52 string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
53 endforeach()
54 set(STATIC_POSTFIX "mt" CACHE STRING "Set static library postfix" FORCE)
55 else(WITH_MT)
56 set(STATIC_POSTFIX "md" CACHE STRING "Set static library postfix" FORCE)
57 endif(WITH_MT)
Jim King1673adf2015-04-13 12:25:35 -040058
Jim King9de9b1f2015-04-30 16:03:34 -040059 # Disable Windows.h definition of macros for min and max
60 add_definitions("-DNOMINMAX")
61
62 # Disable boost auto linking pragmas - cmake includes the right files
63 add_definitions("-DBOOST_ALL_NO_LIB")
64
65 # Windows build does not know how to make a shared library yet
66 # as there are no __declspec(dllexport) or exports files in the project.
67 if (WITH_SHARED_LIB)
68 message (FATAL_ERROR "Windows build does not support shared library output yet!")
69 endif()
70
Jim King1673adf2015-04-13 12:25:35 -040071elseif(UNIX)
72 # For UNIX
73 # WITH_*THREADS selects which threading library to use
74 if(WITH_BOOSTTHREADS)
75 add_definitions("-DUSE_BOOST_THREAD=1")
76 elseif(WITH_STDTHREADS)
77 add_definitions("-DUSE_STD_THREAD=1")
78 endif()
79
80endif()
Pascal Bachd5f87e12014-12-12 15:59:17 +010081
Marco Molteni83494252015-04-16 13:50:20 +020082# GCC and Clang.
83if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
84 # 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 +010085 #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O2 -Wall -Wextra -pedantic")
Marco Molteni83494252015-04-16 13:50:20 +020086 # FIXME enabling c++11 breaks some Linux builds on Travis by triggering a g++ bug, see
87 # https://travis-ci.org/apache/thrift/jobs/58017022
88 # on the other hand, both MacOSX and FreeBSD need c++11
89 if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin" OR ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
90 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O2 -Wall -Wextra")
91 endif()
Pascal Bachd5f87e12014-12-12 15:59:17 +010092endif()