blob: a78d80cac464373e4b524a7cb6dc451ffe413d9a [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
Mario Emmenlauer66d110b2019-04-15 13:36:02 +020023# For Debug build types, default to "d"-suffix in library names.
24set(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "Set debug library postfix")
James E. King III278528c2019-01-11 12:17:44 -050025
cyya6a3a782019-02-07 22:27:33 +080026# basic options
27foreach(lang IN ITEMS C CXX)
Mario Emmenlauerc5a5f792023-10-10 12:01:13 +020028 if("CMAKE_${lang}_COMPILER_ID" STREQUAL "MSVC")
29 # These flags are not supported (or needed) with Clang-Cl on Windows:
cyya6a3a782019-02-07 22:27:33 +080030 set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS} /MP") # parallel build
Mario Emmenlauerc5a5f792023-10-10 12:01:13 +020031 endif()
32
33 if("CMAKE_${lang}_COMPILER_ID" STREQUAL "MSVC" OR "${CMAKE_${lang}_SIMULATE_ID}" STREQUAL "MSVC")
cyya6a3a782019-02-07 22:27:33 +080034 set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS} /W3") # warning level 3
35 include(CheckCXXCompilerFlag)
36 set(CMAKE_REQUIRED_QUIET ON)
37 check_cxx_compiler_flag("/source-charset:utf-8" res_var)
38 if (res_var)
39 set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS} /source-charset:utf-8")
40 endif()
41 check_cxx_compiler_flag("/execution-charset:utf-8" res_var)
42 if (res_var)
43 set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS} /execution-charset:utf-8")
44 endif()
45 add_definitions("-DUNICODE -D_UNICODE")
Mario Emmenlauer7f9abb12020-10-20 15:44:42 +020046 elseif("CMAKE_${lang}_COMPILER_ID" STREQUAL "Clang")
47 set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS} -Wall")
48 set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS} -ferror-limit=1")
49 elseif("CMAKE_${lang}_COMPILER_ID" STREQUAL "GNU")
50 set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS} -Wall -Wextra")
51 set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS} -fmax-errors=1")
cyya6a3a782019-02-07 22:27:33 +080052 endif()
53endforeach()
54
Pascal Bachd5f87e12014-12-12 15:59:17 +010055# Visual Studio specific options
56if(MSVC)
James E. King III278528c2019-01-11 12:17:44 -050057 # Allow for shared library builds
58 if(BUILD_SHARED_LIBS)
59 set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON CACHE TYPE BOOL FORCE)
60 endif()
61
Pascal Bachd5f87e12014-12-12 15:59:17 +010062 #For visual studio the library naming is as following:
63 # Dynamic libraries:
Jim King9de9b1f2015-04-30 16:03:34 -040064 # - thrift.dll for release library
Pascal Bachd5f87e12014-12-12 15:59:17 +010065 # - thriftd.dll for debug library
66 #
67 # Static libraries:
68 # - thriftmd.lib for /MD release build
69 # - thriftmt.lib for /MT release build
70 #
71 # - thriftmdd.lib for /MD debug build
72 # - thriftmtd.lib for /MT debug build
73 #
74 # the same holds for other libraries like libthriftz etc.
75
Pascal Bachd5f87e12014-12-12 15:59:17 +010076 # Build using /MT option instead of /MD if the WITH_MT options is set
77 if(WITH_MT)
78 set(CompilerFlags
79 CMAKE_CXX_FLAGS
80 CMAKE_CXX_FLAGS_DEBUG
81 CMAKE_CXX_FLAGS_RELEASE
Jim King94d4f3e2016-11-10 16:31:28 -050082 CMAKE_CXX_FLAGS_RELWITHDEBINFO
Pascal Bachd5f87e12014-12-12 15:59:17 +010083 CMAKE_C_FLAGS
84 CMAKE_C_FLAGS_DEBUG
85 CMAKE_C_FLAGS_RELEASE
Jim King94d4f3e2016-11-10 16:31:28 -050086 CMAKE_C_FLAGS_RELWITHDEBINFO
Pascal Bachd5f87e12014-12-12 15:59:17 +010087 )
88 foreach(CompilerFlag ${CompilerFlags})
89 string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
90 endforeach()
James E. King III17355422019-01-11 23:06:08 -050091 set(THRIFT_RUNTIME_POSTFIX "mt" CACHE STRING "Set runtime library postfix" FORCE)
Pascal Bachd5f87e12014-12-12 15:59:17 +010092 else(WITH_MT)
James E. King III17355422019-01-11 23:06:08 -050093 set(THRIFT_RUNTIME_POSTFIX "md" CACHE STRING "Set runtime library postfix" FORCE)
Pascal Bachd5f87e12014-12-12 15:59:17 +010094 endif(WITH_MT)
Jim King1673adf2015-04-13 12:25:35 -040095
Jim King9de9b1f2015-04-30 16:03:34 -040096 # Disable boost auto linking pragmas - cmake includes the right files
97 add_definitions("-DBOOST_ALL_NO_LIB")
Jim King1673adf2015-04-13 12:25:35 -040098elseif(UNIX)
Roger Meier446a3192015-05-09 23:40:54 +020099 find_program( MEMORYCHECK_COMMAND valgrind )
100 set( MEMORYCHECK_COMMAND_OPTIONS "--gen-suppressions=all --leak-check=full" )
101 set( MEMORYCHECK_SUPPRESSIONS_FILE "${PROJECT_SOURCE_DIR}/test/valgrind.suppress" )
Jim King1673adf2015-04-13 12:25:35 -0400102endif()
Pascal Bachd5f87e12014-12-12 15:59:17 +0100103
James E. King, III7edc8fa2017-01-20 10:11:41 -0500104add_definitions("-D__STDC_FORMAT_MACROS")
James E. King III3ae30422018-03-12 07:33:22 -0400105add_definitions("-D__STDC_LIMIT_MACROS")
James E. King, III7edc8fa2017-01-20 10:11:41 -0500106
James E. King, III43e959b2017-04-04 13:04:29 -0400107# C++ Language Level
cyy83b65f02019-01-05 11:06:50 +0800108set(CXX_LANGUAGE_LEVEL "C++${CMAKE_CXX_STANDARD}")
109if (CMAKE_CXX_STANDARD_REQUIRED)
110 string(CONCAT CXX_LANGUAGE_LEVEL "${CXX_LANGUAGE_LEVEL} [compiler must support it]")
111else()
112 string(CONCAT CXX_LANGUAGE_LEVEL "${CXX_LANGUAGE_LEVEL} [fallback to earlier if compiler does not support it]")
113endif()
114if (CMAKE_CXX_EXTENSIONS)
115 string(CONCAT CXX_LANGUAGE_LEVEL "${CXX_LANGUAGE_LEVEL} [with compiler-specific extensions]")
James E. King, III43e959b2017-04-04 13:04:29 -0400116endif()
117
118if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
119 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-register")
Pascal Bachd5f87e12014-12-12 15:59:17 +0100120endif()