forked from rstudio/rstudio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeCompiler.txt
112 lines (91 loc) · 3.59 KB
/
CMakeCompiler.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#
# CMakeCompiler.txt
#
# Copyright (C) 2020 by RStudio, PBC
#
# Unless you have received this program directly from RStudio pursuant
# to the terms of a commercial license agreement with RStudio, then
# this program is licensed to you under the terms of version 3 of the
# GNU Affero General Public License. This program is distributed WITHOUT
# ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
# MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
# AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
#
#
# include guard
if(RSTUDIO_CMAKE_COMPILER_INCLUDED)
return()
endif()
set(RSTUDIO_CMAKE_COMPILER_INCLUDED YES)
# require position independent code for CMake targets
set(CMAKE_POSITION_INDEPENDENT_CODE Yes)
# use clang on osx
if(APPLE)
if(NOT DEFINED CMAKE_C_COMPILER)
set(CMAKE_C_COMPILER /usr/bin/cc)
endif()
if(NOT DEFINED CMAKE_CXX_COMPILER)
set(CMAKE_CXX_COMPILER /usr/bin/c++)
endif()
endif()
# require C++11 (or C++14 for MSVC)
if(MSVC)
# use C++14 (MSVC doesn't support C++11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++14")
# disable C4800 warning; this is very noisy, rarely useful, and was completely removed
# in Visual Studio 2017 (we're currently using VS 2015).
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4800")
# disable C4091 warning: 'keyword' : ignored on left of 'type' when no variable is declared
# generates a lot of warning noise in files from clang
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4091")
# disable C4068 warning: unknown pragma
# these warnings are being triggered in the MSVC-supplied headers and we aren't touching those
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4068")
# embed debug information into the generated objects
# (otherwise we can run into annoying PDB errors during compilation)
string(REGEX REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
string(REGEX REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
# ensure that we're using linker flags compatible with
# the version of Boost that will be linked in
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
set(ITERATOR_DEBUG_LEVEL 0)
set(LINKER_FLAG "/MD")
else()
set(ITERATOR_DEBUG_LEVEL 2)
add_definitions(-D_DEBUG)
set(LINKER_FLAG "/MDd")
endif()
foreach(RELEASE_TYPE "" "_DEBUG" "_RELEASE" "_MINSIZEREL" "_RELWITHDEBINFO")
foreach(FLAG CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
string(REGEX REPLACE "/MDd?" "${LINKER_FLAG}" ${FLAG}${RELEASE_TYPE} "${${FLAG}${RELEASE_TYPE}}")
endforeach()
endforeach()
# disable CMake's automatic manifest generation (we always provide our own)
foreach(TYPE EXE MODULE SHARED)
set(CMAKE_${TYPE}_LINKER_FLAGS "${CMAKE_${TYPE}_LINKER_FLAGS} /MANIFEST:NO")
endforeach()
# multi-process compilation
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
# silence some warnings (mostly out of our control) + set debug level
add_definitions(
-D_CRT_NONSTDC_NO_DEPRECATE
-D_CRT_SECURE_NO_WARNINGS
-D_SCL_SECURE_NO_WARNINGS
-D_ITERATOR_DEBUG_LEVEL=${ITERATOR_DEBUG_LEVEL}
)
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
# Use --as-needed when RSTUDIO_CONFIG_MONITOR_ONLY
if(RSTUDIO_CONFIG_MONITOR_ONLY)
foreach(TYPE EXE MODULE SHARED)
set(CMAKE_${TYPE}_LINKER_FLAGS "${CMAKE_${TYPE}_LINKER_FLAGS} -Wl,--as-needed -Wl,--no-undefined -Wl,--no-allow-shlib-undefined")
endforeach()
endif()
endif()
if(NOT DEFINED WINDRES)
set(WINDRES windres.exe)
endif()
# avoid colored output (seems unreliable in cmd.exe terminal)
if(WIN32)
set(CMAKE_COLOR_MAKEFILE OFF)
endif()