Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 1 | # |
| 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, III | 07f5997 | 2017-03-10 06:18:33 -0500 | [diff] [blame] | 20 | # Uncomment this to show some basic cmake variables about platforms |
| 21 | # include (NewPlatformDebug) |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 22 | |
| 23 | # Visual Studio specific options |
| 24 | if(MSVC) |
| 25 | #For visual studio the library naming is as following: |
| 26 | # Dynamic libraries: |
Jim King | 9de9b1f | 2015-04-30 16:03:34 -0400 | [diff] [blame] | 27 | # - thrift.dll for release library |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 28 | # - thriftd.dll for debug library |
| 29 | # |
| 30 | # Static libraries: |
| 31 | # - thriftmd.lib for /MD release build |
| 32 | # - thriftmt.lib for /MT release build |
| 33 | # |
| 34 | # - thriftmdd.lib for /MD debug build |
| 35 | # - thriftmtd.lib for /MT debug build |
| 36 | # |
| 37 | # the same holds for other libraries like libthriftz etc. |
| 38 | |
| 39 | # For Debug build types, append a "d" to the library names. |
| 40 | set(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "Set debug library postfix" FORCE) |
| 41 | set(CMAKE_RELEASE_POSTFIX "" CACHE STRING "Set release library postfix" FORCE) |
Jim King | 94d4f3e | 2016-11-10 16:31:28 -0500 | [diff] [blame] | 42 | set(CMAKE_RELWITHDEBINFO_POSTFIX "" CACHE STRING "Set release library postfix" FORCE) |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 43 | |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 44 | # Build using /MT option instead of /MD if the WITH_MT options is set |
| 45 | if(WITH_MT) |
| 46 | set(CompilerFlags |
| 47 | CMAKE_CXX_FLAGS |
| 48 | CMAKE_CXX_FLAGS_DEBUG |
| 49 | CMAKE_CXX_FLAGS_RELEASE |
Jim King | 94d4f3e | 2016-11-10 16:31:28 -0500 | [diff] [blame] | 50 | CMAKE_CXX_FLAGS_RELWITHDEBINFO |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 51 | CMAKE_C_FLAGS |
| 52 | CMAKE_C_FLAGS_DEBUG |
| 53 | CMAKE_C_FLAGS_RELEASE |
Jim King | 94d4f3e | 2016-11-10 16:31:28 -0500 | [diff] [blame] | 54 | CMAKE_C_FLAGS_RELWITHDEBINFO |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 55 | ) |
| 56 | foreach(CompilerFlag ${CompilerFlags}) |
| 57 | string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}") |
| 58 | endforeach() |
| 59 | set(STATIC_POSTFIX "mt" CACHE STRING "Set static library postfix" FORCE) |
| 60 | else(WITH_MT) |
| 61 | set(STATIC_POSTFIX "md" CACHE STRING "Set static library postfix" FORCE) |
| 62 | endif(WITH_MT) |
Jim King | 1673adf | 2015-04-13 12:25:35 -0400 | [diff] [blame] | 63 | |
Jim King | 9de9b1f | 2015-04-30 16:03:34 -0400 | [diff] [blame] | 64 | # Disable Windows.h definition of macros for min and max |
| 65 | add_definitions("-DNOMINMAX") |
| 66 | |
| 67 | # Disable boost auto linking pragmas - cmake includes the right files |
| 68 | add_definitions("-DBOOST_ALL_NO_LIB") |
| 69 | |
| 70 | # Windows build does not know how to make a shared library yet |
| 71 | # as there are no __declspec(dllexport) or exports files in the project. |
| 72 | if (WITH_SHARED_LIB) |
Roger Meier | 86fded2 | 2015-05-15 12:01:38 +0200 | [diff] [blame] | 73 | message (FATAL_ERROR "Windows build does not support shared library output yet, please set -DWITH_SHARED_LIB=off") |
Jim King | 9de9b1f | 2015-04-30 16:03:34 -0400 | [diff] [blame] | 74 | endif() |
| 75 | |
James E. King, III | 7edc8fa | 2017-01-20 10:11:41 -0500 | [diff] [blame] | 76 | add_definitions("/MP") # parallel build |
| 77 | add_definitions("/W3") # warning level 3 |
| 78 | |
| 79 | # VS2010 does not provide inttypes which we need for "PRId64" used in many places |
| 80 | find_package(Inttypes) |
| 81 | if (Inttypes_FOUND) |
| 82 | include_directories(${INTTYPES_INCLUDE_DIRS}) |
| 83 | # OpenSSL conflicts with the definition of PRId64 unless it is defined first |
| 84 | add_definitions("/FIinttypes.h") |
| 85 | endif () |
Jim King | 1673adf | 2015-04-13 12:25:35 -0400 | [diff] [blame] | 86 | elseif(UNIX) |
Roger Meier | 446a319 | 2015-05-09 23:40:54 +0200 | [diff] [blame] | 87 | find_program( MEMORYCHECK_COMMAND valgrind ) |
| 88 | set( MEMORYCHECK_COMMAND_OPTIONS "--gen-suppressions=all --leak-check=full" ) |
| 89 | set( MEMORYCHECK_SUPPRESSIONS_FILE "${PROJECT_SOURCE_DIR}/test/valgrind.suppress" ) |
Jim King | 1673adf | 2015-04-13 12:25:35 -0400 | [diff] [blame] | 90 | endif() |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 91 | |
James E. King, III | 7edc8fa | 2017-01-20 10:11:41 -0500 | [diff] [blame] | 92 | add_definitions("-D__STDC_FORMAT_MACROS") |
James E. King III | 3ae3042 | 2018-03-12 07:33:22 -0400 | [diff] [blame] | 93 | add_definitions("-D__STDC_LIMIT_MACROS") |
James E. King, III | 7edc8fa | 2017-01-20 10:11:41 -0500 | [diff] [blame] | 94 | |
Roger Meier | a6b6633 | 2015-05-15 15:21:50 +0200 | [diff] [blame] | 95 | # WITH_*THREADS selects which threading library to use |
| 96 | if(WITH_BOOSTTHREADS) |
| 97 | add_definitions("-DUSE_BOOST_THREAD=1") |
| 98 | elseif(WITH_STDTHREADS) |
| 99 | add_definitions("-DUSE_STD_THREAD=1") |
| 100 | endif() |
| 101 | |
James E. King, III | 43e959b | 2017-04-04 13:04:29 -0400 | [diff] [blame] | 102 | # C++ Language Level |
| 103 | set(CXX_LANGUAGE_LEVEL "C++${CMAKE_CXX_STANDARD}") |
| 104 | if (CMAKE_CXX_STANDARD_REQUIRED) |
| 105 | string(CONCAT CXX_LANGUAGE_LEVEL "${CXX_LANGUAGE_LEVEL} [compiler must support it]") |
| 106 | else() |
| 107 | string(CONCAT CXX_LANGUAGE_LEVEL "${CXX_LANGUAGE_LEVEL} [fallback to earlier if compiler does not support it]") |
| 108 | endif() |
| 109 | if (CMAKE_CXX_EXTENSIONS) |
| 110 | string(CONCAT CXX_LANGUAGE_LEVEL "${CXX_LANGUAGE_LEVEL} [with compiler-specific extensions]") |
| 111 | else() |
| 112 | if ((CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") AND NOT MINGW) |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 113 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-variadic-macros -Wno-long-long") |
| 114 | endif() |
| 115 | if ((CMAKE_CXX_COMPILER_ID MATCHES "Clang") AND NOT MINGW) |
| 116 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-c++11-long-long") |
Marco Molteni | 8349425 | 2015-04-16 13:50:20 +0200 | [diff] [blame] | 117 | endif() |
James E. King, III | 43e959b | 2017-04-04 13:04:29 -0400 | [diff] [blame] | 118 | endif() |
| 119 | |
| 120 | if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") |
| 121 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-register") |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 122 | endif() |
James E. King, III | c9877fb | 2016-11-14 10:20:52 -0500 | [diff] [blame] | 123 | |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 124 | # Building WITH_PLUGIN requires boost memory operations, for now, and gcc >= 4.8 |
| 125 | if (WITH_PLUGIN) |
| 126 | if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.8") |
| 127 | message(SEND_ERROR "Thrift compiler plug-in support is not possible with older gcc ( < 4.8 ) compiler") |
| 128 | endif() |
| 129 | message(STATUS "Forcing use of boost::smart_ptr to build WITH_PLUGIN") |
| 130 | add_definitions("-DFORCE_BOOST_SMART_PTR=1") |
James E. King, III | c9877fb | 2016-11-14 10:20:52 -0500 | [diff] [blame] | 131 | endif() |
| 132 | |