1 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
4 #-----------------------------------------------------------------------------
5 # set some special flags for different compilers
7 if(WIN32 AND CMAKE_C_COMPILER_ID STREQUAL "Intel")
11 if(WIN32 AND CMAKE_C_COMPILER_ID MATCHES "^(Clang|IntelLLVM)$"
12 AND "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC")
13 set(_CLANG_MSVC_WINDOWS 1)
16 # Disable deprecation warnings for standard C functions.
17 # really only needed for newer versions of VS, but should
18 # not hurt other versions, and this will work into the
20 if(MSVC OR _INTEL_WINDOWS OR _CLANG_MSVC_WINDOWS)
21 add_compile_definitions(_CRT_SECURE_NO_DEPRECATE _CRT_NONSTDC_NO_DEPRECATE)
25 # MSVC 14.28 enables C5105, but the Windows SDK 10.0.18362.0 triggers it.
26 if(CMAKE_C_COMPILER_ID STREQUAL "MSVC" AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 19.28)
27 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -wd5105")
28 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -wd5105")
31 # Use a stack size large enough for CMake_DEFAULT_RECURSION_LIMIT.
33 string(APPEND CMAKE_EXE_LINKER_FLAGS " ${CMAKE_CXX_LINKER_WRAPPER_FLAG}-stack:10000000")
34 elseif(MINGW OR MSYS OR CYGWIN)
35 string(APPEND CMAKE_EXE_LINKER_FLAGS " -Wl,--stack,10000000")
36 elseif(_CLANG_MSVC_WINDOWS AND "x${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "xGNU")
37 string(APPEND CMAKE_EXE_LINKER_FLAGS " -Xlinker -stack:20000000")
40 #silence duplicate symbol warnings on AIX
41 if(CMAKE_SYSTEM_NAME MATCHES "AIX")
42 if(NOT CMAKE_COMPILER_IS_GNUCXX)
43 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -bhalt:5 ")
47 if(CMAKE_SYSTEM MATCHES "OSF1-V")
48 if(NOT CMAKE_COMPILER_IS_GNUCXX)
49 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -timplicit_local -no_implicit_include ")
53 # Workaround for short jump tables on PA-RISC
54 if(CMAKE_SYSTEM_PROCESSOR MATCHES "^parisc")
55 if(CMAKE_COMPILER_IS_GNUCC)
56 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mlong-calls")
58 if(CMAKE_COMPILER_IS_GNUCXX)
59 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mlong-calls")
63 # Use 64-bit off_t on 32-bit Linux
64 if (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SIZEOF_VOID_P EQUAL 4)
65 # ensure 64bit offsets are used for filesystem accesses for 32bit compilation
66 add_compile_definitions(_FILE_OFFSET_BITS=64)
69 # Workaround for TOC Overflow on ppc64
71 if(CMAKE_SYSTEM_NAME STREQUAL "AIX" AND
72 CMAKE_SYSTEM_PROCESSOR MATCHES "powerpc")
73 set(bigTocFlag "-Wl,-bbigtoc")
74 elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND
75 CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64")
76 set(bigTocFlag "-Wl,--no-multi-toc")
79 include(CheckCXXLinkerFlag)
80 check_cxx_linker_flag(${bigTocFlag} BIG_TOC_FLAG_SUPPORTED)
81 if(BIG_TOC_FLAG_SUPPORTED)
82 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${bigTocFlag}")
86 if (CMAKE_CXX_COMPILER_ID STREQUAL SunPro AND
87 NOT DEFINED CMAKE_CXX${CMAKE_CXX_STANDARD}_STANDARD_COMPILE_OPTION)
88 if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.13)
89 if (NOT CMAKE_CXX_STANDARD OR CMAKE_CXX_STANDARD EQUAL 98)
90 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++03")
93 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -library=stlport4")
97 foreach(lang IN ITEMS C CXX)
98 # Suppress warnings from PGI compiler.
99 if (CMAKE_${lang}_COMPILER_ID STREQUAL "PGI")
100 set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS} -w")
104 # use the ansi CXX compile flag for building cmake
105 if (CMAKE_ANSI_CXXFLAGS)
106 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_ANSI_CXXFLAGS}")
109 if (CMAKE_ANSI_CFLAGS)
110 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_ANSI_CFLAGS}")
113 # Allow per-translation-unit parallel builds when using MSVC
114 if(CMAKE_GENERATOR MATCHES "Visual Studio" AND
115 (CMAKE_C_COMPILER_ID MATCHES "MSVC|Intel" OR
116 CMAKE_CXX_COMPILER_ID MATCHES "MSVC|Intel"))
118 set(CMake_MSVC_PARALLEL ON CACHE STRING "\
119 Enables /MP flag for parallel builds using MSVC. Specify an \
120 integer value to control the number of threads used (Only \
121 works on some older versions of Visual Studio). Setting to \
122 ON lets the toolchain decide how many threads to use. Set to \
123 OFF to disable /MP completely." )
125 if(CMake_MSVC_PARALLEL)
126 if(CMake_MSVC_PARALLEL GREATER 0)
127 string(APPEND CMAKE_C_FLAGS " /MP${CMake_MSVC_PARALLEL}")
128 string(APPEND CMAKE_CXX_FLAGS " /MP${CMake_MSVC_PARALLEL}")
130 string(APPEND CMAKE_C_FLAGS " /MP")
131 string(APPEND CMAKE_CXX_FLAGS " /MP")
136 # Get rid of excess -Wunused-but-set-variable on release builds with LCC >= 1.26
137 foreach(l IN ITEMS C CXX)
138 if(CMAKE_${l}_COMPILER_ID STREQUAL "LCC" AND NOT CMAKE_${l}_COMPILER_VERSION VERSION_LESS 1.26)
139 foreach(c IN ITEMS MINSIZEREL RELEASE RELWITHDEBINFO)
140 string(APPEND "CMAKE_${l}_FLAGS_${c}" " -Wno-unused-but-set-variable")