forked from rstudio/rstudio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeGlobals.txt
285 lines (254 loc) · 9.91 KB
/
CMakeGlobals.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
# vi: set ft=cmake:
#
# CMakeGlobals.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_GLOBALS_INCLUDED)
return()
endif()
set(RSTUDIO_CMAKE_GLOBALS_INCLUDED YES)
# version info
if ("$ENV{RSTUDIO_VERSION_MAJOR}" STREQUAL "")
set(CPACK_PACKAGE_VERSION_MAJOR "99")
set(RSTUDIO_UNVERSIONED_BUILD TRUE)
else()
set(CPACK_PACKAGE_VERSION_MAJOR $ENV{RSTUDIO_VERSION_MAJOR})
endif()
if ("$ENV{RSTUDIO_VERSION_MINOR}" STREQUAL "")
set(CPACK_PACKAGE_VERSION_MINOR "9")
else()
set(CPACK_PACKAGE_VERSION_MINOR $ENV{RSTUDIO_VERSION_MINOR})
endif()
if ("$ENV{RSTUDIO_VERSION_PATCH}" STREQUAL "")
set(CPACK_PACKAGE_VERSION_PATCH "9")
else()
set(CPACK_PACKAGE_VERSION_PATCH $ENV{RSTUDIO_VERSION_PATCH})
endif()
set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
string(TIMESTAMP CPACK_COPYRIGHT_YEAR "%Y")
string(TIMESTAMP CPACK_BUILD_DATE "%Y-%m-%d")
# pick up suffix if present
if(NOT "$ENV{RSTUDIO_VERSION_SUFFIX}" STREQUAL "" AND NOT "$ENV{RSTUDIO_VERSION_SUFFIX}" STREQUAL "0")
set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}-$ENV{RSTUDIO_VERSION_SUFFIX}")
endif()
# default to debug builds
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "CMake build type not set; defaulting to debug build")
set(CMAKE_BUILD_TYPE "Debug")
endif()
# enable testing on all builds unless explicitly disabled
if (NOT RSTUDIO_UNIT_TESTS_DISABLED)
set(RSTUDIO_UNIT_TESTS_ENABLED true)
add_definitions(-DRSTUDIO_UNIT_TESTS_ENABLED)
endif()
# platform specific default for targets
if(NOT RSTUDIO_TARGET)
set(RSTUDIO_TARGET "Development")
set(RSTUDIO_DEVELOPMENT TRUE)
endif()
# set desktop and server build flags
if( NOT WIN32 AND ( (${RSTUDIO_TARGET} STREQUAL "Development") OR
(${RSTUDIO_TARGET} STREQUAL "Server")) )
set(RSTUDIO_SERVER TRUE)
endif()
if( ${RSTUDIO_TARGET} STREQUAL "Development" OR ${RSTUDIO_TARGET} STREQUAL "Desktop" )
set(RSTUDIO_DESKTOP TRUE)
endif()
# set session32 if specified
if(RSTUDIO_TARGET STREQUAL "SessionWin32")
set(RSTUDIO_SESSION_WIN32 TRUE)
endif()
# record git revision hash (cache it since we don't use this in development
# mode and we don't want it to force rebuilds there)
if(NOT RSTUDIO_SESSION_WIN32 AND NOT RSTUDIO_GIT_REVISION_HASH)
find_program(GIT_EXECUTABLE git)
if(GIT_EXECUTABLE)
execute_process(
COMMAND git rev-parse HEAD
WORKING_DIRECTORY "${ROOT_SRC_DIR}"
OUTPUT_VARIABLE RSTUDIO_GIT_REVISION_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE)
SET(RSTUDIO_GIT_REVISION_HASH "${RSTUDIO_GIT_REVISION_HASH}" CACHE STRING "Git Revision Hash")
endif()
endif()
# record these from Jenkins if available
if("$ENV{GIT_COMMIT}" STREQUAL "")
string(LENGTH "${RSTUDIO_GIT_REVISION_HASH}" HASH_LENGTH)
if(HASH_LENGTH EQUAL 40)
# use the cached revision hash if we have one
set(RSTUDIO_GIT_COMMIT "${RSTUDIO_GIT_REVISION_HASH}")
else()
# make one up if we don't
set(RSTUDIO_GIT_COMMIT "99999999999999999999999999999999")
endif()
else()
# use the git commit from Jenkins
set(RSTUDIO_GIT_COMMIT $ENV{GIT_COMMIT})
endif()
if("$ENV{BUILD_ID}" STREQUAL "")
# no known build ID
set(RSTUDIO_BUILD_ID "unknown")
else()
# use build ID from Jenkins
set(RSTUDIO_BUILD_ID $ENV{BUILD_ID})
endif()
if("$ENV{PACKAGE_OS}" STREQUAL "")
# no known package OS
set(RSTUDIO_PACKAGE_OS "Unknown OS")
else()
set(RSTUDIO_PACKAGE_OS $ENV{PACKAGE_OS})
endif()
# required R version
set(RSTUDIO_R_MAJOR_VERSION_REQUIRED 3)
set(RSTUDIO_R_MINOR_VERSION_REQUIRED 0)
set(RSTUDIO_R_PATCH_VERSION_REQUIRED 1)
# allow opting out of version checking (for building on older distros)
if(NOT DEFINED RSTUDIO_VERIFY_R_VERSION)
if(RSTUDIO_PACKAGE_BUILD)
set(RSTUDIO_VERIFY_R_VERSION FALSE)
else()
set(RSTUDIO_VERIFY_R_VERSION TRUE)
endif()
endif()
# install freedesktop integration files if we are installing into /usr
if(NOT DEFINED RSTUDIO_INSTALL_FREEDESKTOP)
if(${CMAKE_INSTALL_PREFIX} MATCHES "/usr/.*")
set(RSTUDIO_INSTALL_WITH_PRIV TRUE)
else()
set(RSTUDIO_INSTALL_WITH_PRIV FALSE)
endif()
if(RSTUDIO_INSTALL_WITH_PRIV AND UNIX AND NOT APPLE)
set(RSTUDIO_INSTALL_FREEDESKTOP TRUE)
else()
set(RSTUDIO_INSTALL_FREEDESKTOP FALSE)
endif()
endif()
# cmake modules (compute path relative to this file)
get_filename_component(ROOT_SRC_DIR ${CMAKE_CURRENT_LIST_FILE} PATH)
set(CMAKE_MODULE_PATH "${ROOT_SRC_DIR}/cmake/modules/")
# dependencies
if(WIN32)
set(RSTUDIO_WINDOWS_DEPENDENCIES_DIR "${ROOT_SRC_DIR}/dependencies/windows")
else()
# look for system-wide (global) dependencies folder
if(EXISTS "/opt/rstudio-tools/dependencies")
set(RSTUDIO_DEPENDENCIES_DIR "/opt/rstudio-tools/dependencies")
endif()
endif()
# look for dependencies in the source folder if not installed globally
if(NOT EXISTS "${RSTUDIO_DEPENDENCIES_DIR}")
set(RSTUDIO_DEPENDENCIES_DIR "${ROOT_SRC_DIR}/dependencies")
endif()
# special install directories for apple desktop
if (APPLE AND RSTUDIO_DESKTOP)
set(RSTUDIO_INSTALL_BIN RStudio.app/Contents/MacOS)
set(RSTUDIO_INSTALL_SUPPORTING RStudio.app/Contents/Resources)
else()
if (RSTUDIO_SESSION_WIN32)
set(RSTUDIO_INSTALL_BIN x86)
else()
set(RSTUDIO_INSTALL_BIN bin)
endif()
set(RSTUDIO_INSTALL_SUPPORTING .)
endif()
# if the install prefix is /usr/local then tweak as appropriate
if(UNIX)
if(${CMAKE_INSTALL_PREFIX} STREQUAL "/usr/local")
if(APPLE AND RSTUDIO_DESKTOP)
set(CMAKE_INSTALL_PREFIX "/Applications")
else()
if(RSTUDIO_DESKTOP)
set(CMAKE_INSTALL_PREFIX "/usr/local/lib/rstudio")
else()
set(CMAKE_INSTALL_PREFIX "/usr/local/lib/rstudio-server")
endif()
endif()
endif()
endif()
# detect lsb release
if (UNIX AND NOT APPLE)
if(NOT RSTUDIO_LSB_RELEASE)
execute_process(COMMAND /usr/bin/lsb_release "--id" "--short"
OUTPUT_VARIABLE RSTUDIO_LSB_RELEASE)
if (RSTUDIO_LSB_RELEASE)
string(STRIP ${RSTUDIO_LSB_RELEASE} RSTUDIO_LSB_RELEASE)
string(TOLOWER ${RSTUDIO_LSB_RELEASE} RSTUDIO_LSB_RELEASE)
set(RSTUDIO_LSB_RELEASE ${RSTUDIO_LSB_RELEASE} CACHE STRING "LSB release")
message(STATUS "LSB release: ${RSTUDIO_LSB_RELEASE}")
endif()
endif()
endif()
# make sure the CMAKE_INSTALL_PREFIX uses a cmake style path
file(TO_CMAKE_PATH "${CMAKE_INSTALL_PREFIX}" CMAKE_INSTALL_PREFIX)
# embedded packages
# set(RSTUDIO_EMBEDDED_PACKAGES rstudioapi CACHE INTERNAL "Embedded R Packages")
# include utilities
include(RStudioCMakeUtils)
# define custom function to strip unnecessary path parts from binary filename
function(define_source_file_names targetname)
get_target_property(SOURCE_FILES "${targetname}" SOURCES)
foreach(SOURCE_FILE ${SOURCE_FILES})
# Get source file's current list of compile definitions.
get_property(SOURCE_DEFS SOURCE "${SOURCE_FILE}" PROPERTY COMPILE_DEFINITIONS)
# Add the stripped filename to the list
# Provided source paths can either be full paths or simply filenames
string(FIND "${SOURCE_FILE}" "/src/cpp" SOURCE_INDEX)
if (SOURCE_INDEX GREATER -1)
set(FULL_SOURCE_NAME "${SOURCE_FILE}")
MATH(EXPR SOURCE_INDEX "${SOURCE_INDEX}+1")
else()
string(FIND "${SOURCE_FILE}" "${CMAKE_BINARY_DIR}" SOURCE_INDEX)
if (SOURCE_INDEX GREATER -1)
set(FULL_SOURCE_NAME "${SOURCE_FILE}")
string(LENGTH "${CMAKE_BINARY_DIR}" BINARY_DIR_LENGTH)
MATH(EXPR SOURCE_INDEX "${SOURCE_INDEX}+${BINARY_DIR_LENGTH}+1")
else()
set(FULL_SOURCE_NAME "${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE_FILE}")
string(FIND "${FULL_SOURCE_NAME}" "/src/cpp" SOURCE_INDEX)
MATH(EXPR SOURCE_INDEX "${SOURCE_INDEX}+1")
endif()
endif()
string(SUBSTRING "${FULL_SOURCE_NAME}" "${SOURCE_INDEX}" -1 STRIPPED_SOURCE)
list(APPEND SOURCE_DEFS "STRIPPED_FILENAME=\"${STRIPPED_SOURCE}\"")
# Set the updated compile definitions on the source file.
set_property(
SOURCE "${SOURCE_FILE}"
PROPERTY COMPILE_DEFINITIONS ${SOURCE_DEFS})
endforeach()
endfunction()
# define custom installation macro to strip symbols from the binary
macro(add_stripped_executable _target)
add_executable(${_target} ${ARGN})
# only strip debug info in release package builds
if(RSTUDIO_PACKAGE_BUILD AND CMAKE_BUILD_TYPE STREQUAL RelWithDebInfo)
if(UNIX AND NOT APPLE)
# strip debug info
add_custom_command(TARGET ${_target} POST_BUILD
COMMAND objcopy --only-keep-debug ${_target} ${_target}.debug
COMMAND objcopy --strip-debug --strip-unneeded ${_target}
COMMAND objcopy --add-gnu-debuglink=${_target}.debug ${_target}
COMMENT "Stripping ${_target}")
elseif(APPLE)
if(${ARGV1} STREQUAL "MACOSX_BUNDLE")
set(STRIP_TARGET "${_target}.app/contents/MacOS/${_target}")
else()
set(STRIP_TARGET "${_target}")
endif()
add_custom_command(TARGET ${_target} POST_BUILD
COMMAND dsymutil -o ./${_target}.dSYM ${STRIP_TARGET}
COMMAND strip ${STRIP_TARGET}
COMMENT "Stripping ${STRIP_TARGET}")
endif()
endif()
define_source_file_names("${_target}")
endmacro(add_stripped_executable)