-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCetCMakeEnv.cmake
More file actions
395 lines (342 loc) · 11.7 KB
/
Copy pathCetCMakeEnv.cmake
File metadata and controls
395 lines (342 loc) · 11.7 KB
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
#[================================================================[.rst:
CetCMakeEnv
-----------
This module defines the principal initialization function
:command:`cet_cmake_env` defining the cetmodules build environment for
the current project.
#]================================================================]
# Avoid unnecessary repeat inclusion.
include_guard()
cmake_minimum_required(VERSION 3.19...4.1 FATAL_ERROR)
# Escape characters for literal use in regular expressions.
include(CetRegexEscape)
# Handle setting of versions with a non-numeric component:
include(private/CetHandleExtendedVersion)
# Project variables.
include(ProjectVariable)
# ##############################################################################
# OPTIONS
# ##############################################################################
# What kind of things can we build?
option(BUILD_SHARED_LIBS "Build shared libraries (all projects)." ON)
option(BUILD_STATIC_LIBS "Build static libraries (all projects)." OFF)
option(BUILD_DOCS "Build documentation (all_projects)." OFF)
# RPATH management.
option(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON)
mark_as_advanced(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON)
# ##############################################################################
# ##############################################################################
# Configure installation subdirectories.
# ##############################################################################
# Default subdirectory for libraries.
if(NOT CMAKE_INSTALL_LIBDIR)
set(CMAKE_INSTALL_LIBDIR lib) # Don't use lib64 for installation dir.
endif()
define_property(
TARGET
PROPERTY CET_EXEC_LOCATION
BRIEF_DOCS "Saved location of the executable represented by a target"
FULL_DOCS "Saved location of the executable represented by a target"
)
#[================================================================[.rst:
.. command:: cet_cmake_env
Set up the cetmodules build environment for the current project.
.. code-block:: cmake
cet_cmake_env([NO_INSTALL_PKGMETA])
Options
^^^^^^^
``NO_INSTALL_PKGMETA``
Under normal circumstances, :command:`!cet_cmake_env` will call
:command:`install_pkgmeta` to automatically find ``LICENSE`` and
``README`` files and install them. Specify ``NO_INSTALL_PKGMETA``
if you wish to call :command:`install_pkgmeta` yourself (or not
at all).
Notes
^^^^^
.. note::
Prior to calling :command:`cet_cmake_env`:
* The current project must have been initialized via
:command:`project() <cmake-ref-current:command:project>`
* Any initial or override values for
:manual:`project variables <cetmodules-project-variables(7)>` should be set.
.. seealso:: :command:`cet_finalize`
Variables affecting behavior
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
* :variable:`BUILD_SHARED_LIBS <cmake-ref-current:variable:BUILD_SHARED_LIBS>`
* :variable:`BUILD_STATIC_LIBS`
* :variable:`CMAKE_INSTALL_RPATH_USE_LINK_PATH <cmake-ref-current:variable:CMAKE_INSTALL_RPATH_USE_LINK_PATH>`
#]================================================================]
macro(cet_cmake_env)
# project() must have been called first.
if(NOT CMAKE_PROJECT_NAME)
message(
FATAL_ERROR
"CMake project() command must have been invoked prior to cet_cmake_env()."
"\nIt must be invoked from the project's top level CMakeLists.txt, not in an included .cmake file."
)
endif()
# ##############################################################################
# See https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html.
#
# We suppress developer warnings for this `include()` to silence
# complaints from CMake >=4 when no `LANGUAGES` are enabled for this
# project.
set(_cce_suppress_dev_warnings "$CACHE{CMAKE_SUPPRESS_DEVELOP_WARNINGS}")
set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS ON CACHE INTERNAL "" FORCE)
include(GNUInstallDirs)
set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS "${_cce_suppress_dev_warnings}" CACHE INTERNAL "" FORCE)
unset(_cce_suppress_dev_warnings)
# ##############################################################################
set(CETMODULES_CURRENT_PROJECT_NAME ${PROJECT_NAME})
# ############################################################################
# Policy settings
# ############################################################################
# Required to ensure correct installation location with
# cetbuildtools-compatible installations.
#
# * Since these cmake_policy() commands are in the *implementation* of a
# macro, they are effective within the entire policy stack active at the
# time of invocation.
#
# See https://cmake.org/cmake/help/latest/policy/CMP0082.html
cmake_policy(SET CMP0082 NEW)
# ############################################################################
# Remove unwanted information from any previous run.
# ############################################################################
_clean_internal_cache_entries()
# ############################################################################
# Project variables - see ProjectVariable.cmake. See especially the
# explanation of initialization and default semantics.
# ############################################################################
# Enable the config file generator to detect whether we're being built and
# imported in the same run. Note that this variable is *not* exported to
# external dependents.
project_variable(
IN_TREE
TRUE
TYPE
BOOL
DOCSTRING
"Signifies whether ${CETMODULES_CURRENT_PROJECT_NAME} is currently being built"
)
# Defined first, as PATH_FRAGMENT and FILEPATH_FRAGMENT project variables take
# this into account.
project_variable(EXEC_PREFIX TYPE STRING)
# Enable projects to specify an extended version with a non-numeric trailing
# component (e.g. -rc1, or -alpha, or -p03), and deal with it in the right
# places.
project_variable(
CMAKE_PROJECT_VERSION_STRING
${PROJECT_VERSION}
TYPE
STRING
DOCSTRING
"Extended project version, with optional non-numeric trailing \
component(M[.m[.p[.t]]][-X])\
"
)
# Ensure we have version settings.
_cet_handle_extended_version()
# Should we generate plugin registration libraries of type MODULE_LIBRARY
# (recommended), or SHARED_LIBRARY (prone to ODR violations)?
project_variable(
MODULE_PLUGINS
TRUE
TYPE
BOOL
DOCSTRING
"\
Whether plugin registration libraries for project \
${CETMODULES_CURRENT_PROJECT_NAME} should be of type MODULE_LIBRARY (TRUE) or \
SHARED_LIBRARY (FALSE)"
)
# Determine whether we are attempting to support extended version semantics
# (non-numeric version components).
if("${PROJECT_VERSION_EXTRA}" STREQUAL "")
set(_cce_ext_v_def FALSE)
else()
set(_cce_ext_v_def TRUE)
endif()
project_variable(
EXTENDED_VERSION_SEMANTICS
${_cce_ext_v_def}
TYPE
BOOL
DOCSTRING
"Use extended version semantics permitting a non-numeric trailing \
component, with sensible comparison semantics for alpha, rc and other \
recognized version formats\
"
)
if(_cce_ext_v_def
AND NOT ${CETMODULES_CURRENT_PROJECT_NAME}_EXTENDED_VERSION_SEMANTICS
)
message(
SEND_ERROR
"Extended semantics for CMAKE_PROJECT_VERSION (${PROJECT_VERSION}) for project ${CETMODULES_CURRENT_PROJECT_NAME} prohibited by ${CETMODULES_CURRENT_PROJECT_NAME}_EXTENDED_VERSION_SEMANTICS"
)
endif()
unset(_cce_ext_v_def)
# ############################################################################
# Avoid confusion with nested subprojects.
foreach(
_cce_v IN
ITEMS BINARY_DIR
DESCRIPTION
HOMEPAGE_URL
SOURCE_DIR
VERSION
VERSION_MAJOR
VERSION_MINOR
VERSION_PATCH
VERSION_TWEAK
VERSION_EXTRA
VERSION_EXTRA_TYPE
VERSION_EXTRA_TEXT
VERSION_EXTRA_NUM
)
set(CETMODULES_CURRENT_PROJECT_${_cce_v} ${PROJECT_${_cce_v}})
endforeach()
unset(_cce_v)
# Check for obsolete arguments.
if(NOT "${ARGV}" STREQUAL "")
warn_deprecated(
"cet_cmake_env(${ARGV})" " - remove unneeded legacy arguments ${ARGV}"
)
endif()
# Disable package registry use as confusing and not best practice.
set(CMAKE_EXPORT_PACKAGE_REGISTRY FALSE)
set(CMAKE_EXPORT_NO_PACKAGE_REGISTRY TRUE)
set(CMAKE_FIND_USE_PACKAGE_REGISTRY FALSE)
set(CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY TRUE)
# Ask CMake to exit on error at install time if it is asked to install files
# in an absolute location.
set(CMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION TRUE)
project_variable(
NAMESPACE
"${CETMODULES_CURRENT_PROJECT_NAME}"
TYPE
STRING
CONFIG
OMIT_IF_NULL
DOCSTRING
"Top-level prefix for targets and aliases when imported"
)
project_variable(
INCLUDE_DIR
"${CMAKE_INSTALL_INCLUDEDIR}"
CONFIG
OMIT_IF_EMPTY
OMIT_IF_MISSING
OMIT_IF_NULL
DOCSTRING
"Directory below prefix to install headers"
)
project_variable(
LIBRARY_DIR
"${CMAKE_INSTALL_LIBDIR}"
CONFIG
OMIT_IF_EMPTY
OMIT_IF_MISSING
OMIT_IF_NULL
DOCSTRING
"Directory below prefix to install libraries"
)
project_variable(
BIN_DIR
"${CMAKE_INSTALL_BINDIR}"
CONFIG
OMIT_IF_EMPTY
OMIT_IF_MISSING
OMIT_IF_NULL
DOCSTRING
"Directory below prefix to install executables"
)
project_variable(
SCRIPTS_DIR
${${CETMODULES_CURRENT_PROJECT_NAME}_BIN_DIR}
NO_WARN_REDUNDANT
BACKUP_DEFAULT
scripts
OMIT_IF_EMPTY
OMIT_IF_MISSING
OMIT_IF_NULL
DOCSTRING
"Directory below prefix to install scripts"
)
project_variable(
TEST_DIR
"test"
NO_WARN_REDUNDANT
OMIT_IF_EMPTY
OMIT_IF_MISSING
OMIT_IF_NULL
DOCSTRING
"Directory below prefix to install tests"
)
project_variable(
DATA_ROOT_DIR
${CMAKE_INSTALL_DATAROOTDIR}
NO_WARN_REDUNDANT
OMIT_IF_EMPTY
OMIT_IF_MISSING
OMIT_IF_NULL
DOCSTRING
"Architecture-independent data directory"
)
# ############################################################################
# Default locations for libraries and executables.
# ############################################################################
# Override on a per-target, per config or per-scope basis if necessary (should
# be rare).
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY
${PROJECT_BINARY_DIR}/${${CETMODULES_CURRENT_PROJECT_NAME}_LIBRARY_DIR}
)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY
${PROJECT_BINARY_DIR}/${${CETMODULES_CURRENT_PROJECT_NAME}_LIBRARY_DIR}
)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY
${PROJECT_BINARY_DIR}/${${CETMODULES_CURRENT_PROJECT_NAME}_BIN_DIR}
)
# ############################################################################
# Avoid warnings about some variables that are likely to have been set on the
# command line but that may not be used.
_use_maybe_unused()
endmacro(cet_cmake_env)
function(_clean_internal_cache_entries)
get_property(
cache_vars
DIRECTORY
PROPERTY CACHE_VARIABLES
)
cet_regex_escape("${CETMODULES_CURRENT_PROJECT_NAME}" e_proj)
list(FILTER cache_vars INCLUDE REGEX
"^_?CETMODULES(_[^_]+)*_PROJECT_${e_proj}$"
)
foreach(entry IN LISTS cache_vars)
get_property(
type
CACHE "${entry}"
PROPERTY TYPE
)
if(type STREQUAL "INTERNAL")
unset("${entry}" CACHE)
endif()
endforeach()
endfunction()
function(_use_maybe_unused)
get_property(
cache_vars
DIRECTORY
PROPERTY CACHE_VARIABLES
)
list(FILTER cache_vars INCLUDE REGEX "_INIT$")
foreach(
var IN
LISTS cache_vars
ITEMS CMAKE_WARN_DEPRECATED
)
if(${var})
endif()
endforeach()
endfunction()