Imported Upstream version 3.15.0
[platform/upstream/cmake.git] / CompileFlags.cmake
1 # Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
3
4 #-----------------------------------------------------------------------------
5 # set some special flags for different compilers
6 #
7 if(WIN32 AND CMAKE_C_COMPILER_ID STREQUAL "Intel")
8   set(_INTEL_WINDOWS 1)
9 endif()
10
11 if(WIN32 AND CMAKE_C_COMPILER_ID STREQUAL "Clang"
12    AND "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC")
13   set(_CLANG_MSVC_WINDOWS 1)
14 endif()
15
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
19 # future
20 if(MSVC OR _INTEL_WINDOWS OR _CLANG_MSVC_WINDOWS)
21   add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
22 else()
23 endif()
24
25 if(MSVC)
26   set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stack:10000000")
27 endif()
28
29 if(_CLANG_MSVC_WINDOWS AND "x${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "xGNU")
30   set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Xlinker -stack:20000000")
31 endif()
32
33 #silence duplicate symbol warnings on AIX
34 if(CMAKE_SYSTEM_NAME MATCHES "AIX")
35   if(NOT CMAKE_COMPILER_IS_GNUCXX)
36     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -bhalt:5 ")
37   endif()
38 endif()
39
40 if(CMAKE_SYSTEM MATCHES "OSF1-V")
41   if(NOT CMAKE_COMPILER_IS_GNUCXX)
42     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -timplicit_local -no_implicit_include ")
43   endif()
44 endif()
45
46 # Workaround for short jump tables on PA-RISC
47 if(CMAKE_SYSTEM_PROCESSOR MATCHES "^parisc")
48   if(CMAKE_COMPILER_IS_GNUCC)
49     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mlong-calls")
50   endif()
51   if(CMAKE_COMPILER_IS_GNUCXX)
52     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mlong-calls")
53   endif()
54 endif()
55
56 # Workaround for TOC Overflow on ppc64
57 if(CMAKE_SYSTEM_NAME STREQUAL "AIX" AND
58    CMAKE_SYSTEM_PROCESSOR MATCHES "powerpc")
59   set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-bbigtoc")
60 elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND
61    CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64")
62   set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-multi-toc")
63 endif()
64
65 if (CMAKE_CXX_COMPILER_ID STREQUAL SunPro AND
66     NOT DEFINED CMAKE_CXX${CMAKE_CXX_STANDARD}_STANDARD_COMPILE_OPTION)
67   if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.13)
68     if (NOT CMAKE_CXX_STANDARD OR CMAKE_CXX_STANDARD EQUAL 98)
69       set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++03")
70     elseif(CMAKE_VERSION VERSION_LESS 3.8.20170502)
71       # CMake knows how to add this flag for compilation as C++11,
72       # but has not been taught that SunPro needs it for linking too.
73       # Add it in a place that will be used for both.
74       set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
75     endif()
76   else()
77     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -library=stlport4")
78   endif()
79 endif()
80
81 foreach(lang C CXX)
82   # Suppress warnings from PGI compiler.
83   if (CMAKE_${lang}_COMPILER_ID STREQUAL "PGI")
84     set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS} -w")
85   endif()
86 endforeach()
87
88 # use the ansi CXX compile flag for building cmake
89 if (CMAKE_ANSI_CXXFLAGS)
90   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_ANSI_CXXFLAGS}")
91 endif ()
92
93 if (CMAKE_ANSI_CFLAGS)
94   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_ANSI_CFLAGS}")
95 endif ()
96
97 # Allow per-translation-unit parallel builds when using MSVC
98 if(CMAKE_GENERATOR MATCHES "Visual Studio" AND
99    (CMAKE_C_COMPILER_ID MATCHES "MSVC|Intel" OR
100    CMAKE_CXX_COMPILER_ID MATCHES "MSVC|Intel"))
101
102   set(CMake_MSVC_PARALLEL ON CACHE STRING "\
103 Enables /MP flag for parallel builds using MSVC. Specify an \
104 integer value to control the number of threads used (Only \
105 works on some older versions of Visual Studio). Setting to \
106 ON lets the toolchain decide how many threads to use. Set to \
107 OFF to disable /MP completely." )
108
109   if(CMake_MSVC_PARALLEL)
110     if(CMake_MSVC_PARALLEL GREATER 0)
111       string(APPEND CMAKE_C_FLAGS " /MP${CMake_MSVC_PARALLEL}")
112       string(APPEND CMAKE_CXX_FLAGS " /MP${CMake_MSVC_PARALLEL}")
113     else()
114       string(APPEND CMAKE_C_FLAGS " /MP")
115       string(APPEND CMAKE_CXX_FLAGS " /MP")
116     endif()
117   endif()
118 endif()