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 | |
James E. King III | 278528c | 2019-01-11 12:17:44 -0500 | [diff] [blame] | 23 | # For Debug build types, append a "d" to the library names. |
| 24 | set(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "Set debug library postfix" FORCE) |
| 25 | |
cyy | a6a3a78 | 2019-02-07 22:27:33 +0800 | [diff] [blame^] | 26 | # basic options |
| 27 | foreach(lang IN ITEMS C CXX) |
| 28 | if(CMAKE_${lang}_COMPILER_ID STREQUAL "Clang") |
| 29 | set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS} -Wall") |
| 30 | set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS} -ferror-limit=1") |
| 31 | elseif(CMAKE_${lang}_COMPILER_ID STREQUAL "GNU") |
| 32 | set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS} -Wall -Wextra") |
| 33 | set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS} -fmax-errors=1") |
| 34 | elseif(CMAKE_${lang}_COMPILER_ID STREQUAL "MSVC") |
| 35 | set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS} /MP") # parallel build |
| 36 | set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS} /W3") # warning level 3 |
| 37 | include(CheckCXXCompilerFlag) |
| 38 | set(CMAKE_REQUIRED_QUIET ON) |
| 39 | check_cxx_compiler_flag("/source-charset:utf-8" res_var) |
| 40 | if (res_var) |
| 41 | set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS} /source-charset:utf-8") |
| 42 | endif() |
| 43 | check_cxx_compiler_flag("/execution-charset:utf-8" res_var) |
| 44 | if (res_var) |
| 45 | set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS} /execution-charset:utf-8") |
| 46 | endif() |
| 47 | add_definitions("-DUNICODE -D_UNICODE") |
| 48 | endif() |
| 49 | endforeach() |
| 50 | |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 51 | # Visual Studio specific options |
| 52 | if(MSVC) |
James E. King III | 278528c | 2019-01-11 12:17:44 -0500 | [diff] [blame] | 53 | # Allow for shared library builds |
| 54 | if(BUILD_SHARED_LIBS) |
| 55 | set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON CACHE TYPE BOOL FORCE) |
| 56 | endif() |
| 57 | |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 58 | #For visual studio the library naming is as following: |
| 59 | # Dynamic libraries: |
Jim King | 9de9b1f | 2015-04-30 16:03:34 -0400 | [diff] [blame] | 60 | # - thrift.dll for release library |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 61 | # - thriftd.dll for debug library |
| 62 | # |
| 63 | # Static libraries: |
| 64 | # - thriftmd.lib for /MD release build |
| 65 | # - thriftmt.lib for /MT release build |
| 66 | # |
| 67 | # - thriftmdd.lib for /MD debug build |
| 68 | # - thriftmtd.lib for /MT debug build |
| 69 | # |
| 70 | # the same holds for other libraries like libthriftz etc. |
| 71 | |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 72 | # Build using /MT option instead of /MD if the WITH_MT options is set |
| 73 | if(WITH_MT) |
| 74 | set(CompilerFlags |
| 75 | CMAKE_CXX_FLAGS |
| 76 | CMAKE_CXX_FLAGS_DEBUG |
| 77 | CMAKE_CXX_FLAGS_RELEASE |
Jim King | 94d4f3e | 2016-11-10 16:31:28 -0500 | [diff] [blame] | 78 | CMAKE_CXX_FLAGS_RELWITHDEBINFO |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 79 | CMAKE_C_FLAGS |
| 80 | CMAKE_C_FLAGS_DEBUG |
| 81 | CMAKE_C_FLAGS_RELEASE |
Jim King | 94d4f3e | 2016-11-10 16:31:28 -0500 | [diff] [blame] | 82 | CMAKE_C_FLAGS_RELWITHDEBINFO |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 83 | ) |
| 84 | foreach(CompilerFlag ${CompilerFlags}) |
| 85 | string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}") |
| 86 | endforeach() |
James E. King III | 1735542 | 2019-01-11 23:06:08 -0500 | [diff] [blame] | 87 | set(THRIFT_RUNTIME_POSTFIX "mt" CACHE STRING "Set runtime library postfix" FORCE) |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 88 | else(WITH_MT) |
James E. King III | 1735542 | 2019-01-11 23:06:08 -0500 | [diff] [blame] | 89 | set(THRIFT_RUNTIME_POSTFIX "md" CACHE STRING "Set runtime library postfix" FORCE) |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 90 | endif(WITH_MT) |
Jim King | 1673adf | 2015-04-13 12:25:35 -0400 | [diff] [blame] | 91 | |
Jim King | 9de9b1f | 2015-04-30 16:03:34 -0400 | [diff] [blame] | 92 | # Disable boost auto linking pragmas - cmake includes the right files |
| 93 | add_definitions("-DBOOST_ALL_NO_LIB") |
Jim King | 1673adf | 2015-04-13 12:25:35 -0400 | [diff] [blame] | 94 | elseif(UNIX) |
Roger Meier | 446a319 | 2015-05-09 23:40:54 +0200 | [diff] [blame] | 95 | find_program( MEMORYCHECK_COMMAND valgrind ) |
| 96 | set( MEMORYCHECK_COMMAND_OPTIONS "--gen-suppressions=all --leak-check=full" ) |
| 97 | set( MEMORYCHECK_SUPPRESSIONS_FILE "${PROJECT_SOURCE_DIR}/test/valgrind.suppress" ) |
Jim King | 1673adf | 2015-04-13 12:25:35 -0400 | [diff] [blame] | 98 | endif() |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 99 | |
James E. King, III | 7edc8fa | 2017-01-20 10:11:41 -0500 | [diff] [blame] | 100 | add_definitions("-D__STDC_FORMAT_MACROS") |
James E. King III | 3ae3042 | 2018-03-12 07:33:22 -0400 | [diff] [blame] | 101 | add_definitions("-D__STDC_LIMIT_MACROS") |
James E. King, III | 7edc8fa | 2017-01-20 10:11:41 -0500 | [diff] [blame] | 102 | |
James E. King, III | 43e959b | 2017-04-04 13:04:29 -0400 | [diff] [blame] | 103 | # C++ Language Level |
cyy | 83b65f0 | 2019-01-05 11:06:50 +0800 | [diff] [blame] | 104 | set(CXX_LANGUAGE_LEVEL "C++${CMAKE_CXX_STANDARD}") |
| 105 | if (CMAKE_CXX_STANDARD_REQUIRED) |
| 106 | string(CONCAT CXX_LANGUAGE_LEVEL "${CXX_LANGUAGE_LEVEL} [compiler must support it]") |
| 107 | else() |
| 108 | string(CONCAT CXX_LANGUAGE_LEVEL "${CXX_LANGUAGE_LEVEL} [fallback to earlier if compiler does not support it]") |
| 109 | endif() |
| 110 | if (CMAKE_CXX_EXTENSIONS) |
| 111 | string(CONCAT CXX_LANGUAGE_LEVEL "${CXX_LANGUAGE_LEVEL} [with compiler-specific extensions]") |
James E. King, III | 43e959b | 2017-04-04 13:04:29 -0400 | [diff] [blame] | 112 | endif() |
| 113 | |
| 114 | if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") |
| 115 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-register") |
Pascal Bach | d5f87e1 | 2014-12-12 15:59:17 +0100 | [diff] [blame] | 116 | endif() |