Gentoo Archives: gentoo-dev

From: Andreas Sturmlechner <asturm@g.o>
To: gentoo-dev@l.g.o
Subject: [gentoo-dev] [PATCH 1/2] cmake.eclass: New eclass, a cmake-utils cleanup for >=EAPI-7
Date: Mon, 23 Dec 2019 23:09:08
Message-Id: 1777207.7Z3S40VBb9@tuxbrain
1 This will be a drop-in replacement for 99% of cmake-utils inheriting ebuilds that are already EAPI-7 based today, that is, at long last, a qualified majority. Besides the cleanup, the new name is correcting a historical mistake and will let overlays with old EAPI ebuilds keep working. Maybe then declaring cmake-utils.eclass deprecated and unmaintained will increase the pressure to port to EAPI-7++ and the new cmake.eclass a bit.
2
3 tl;dr:
4 - Drop all pre-EAPI-7 compatibility
5 - Drop CMAKE_MIN_VERSION
6 - Drop CMAKE_REMOVE_MODULES
7 - Array support for CMAKE_REMOVE_MODULES_LIST
8 - Drop pushd/popd from src_prepare
9 - Drop _cmake_generator_to_use()
10 CMAKE_MAKEFILE_GENERATOR validity is already checked in global scope.
11 Move the check for dev-util/ninja into src_prepare.
12 - Rename cmake_src_make() -> cmake_build()
13 - Drop _cmake_ninja_src_build and _cmake_emake_src_build, move into cmake_build
14
15
16 Below patch is for showing diff, of course cmake-utils.eclass will not be dropped just yet.
17
18 --- eclass/cmake-utils.eclass
19 +++ eclass/cmake.eclass
20 @@ -1,7 +1,7 @@
21 # Copyright 1999-2019 Gentoo Authors
22 # Distributed under the terms of the GNU General Public License v2
23
24 -# @ECLASS: cmake-utils.eclass
25 +# @ECLASS: cmake.eclass
26 # @MAINTAINER:
27 # kde@g.o
28 # @AUTHOR:
29 @@ -9,16 +9,16 @@
30 # Maciej Mrozowski <reavertm@g.o>
31 # (undisclosed contributors)
32 # Original author: Zephyrus (zephyrus@××××××.it)
33 -# @SUPPORTED_EAPIS: 5 6 7
34 +# @SUPPORTED_EAPIS: 7
35 # @BLURB: common ebuild functions for cmake-based packages
36 # @DESCRIPTION:
37 -# The cmake-utils eclass makes creating ebuilds for cmake-based packages much easier.
38 -# It provides all inherited features (DOCS, HTML_DOCS, PATCHES) along with out-of-source
39 -# builds (default), in-source builds and an implementation of the well-known use_enable
40 -# and use_with functions for CMake.
41 +# The cmake eclass makes creating ebuilds for cmake-based packages much easier.
42 +# It provides all inherited features (DOCS, HTML_DOCS, PATCHES) along with
43 +# out-of-source builds (default), in-source builds and an implementation of the
44 +# well-known use_enable function for CMake.
45
46 -if [[ -z ${_CMAKE_UTILS_ECLASS} ]]; then
47 -_CMAKE_UTILS_ECLASS=1
48 +if [[ -z ${_CMAKE_ECLASS} ]]; then
49 +_CMAKE_ECLASS=1
50
51 # @ECLASS-VARIABLE: BUILD_DIR
52 # @DESCRIPTION:
53 @@ -26,9 +26,7 @@
54 # For in-source build it's fixed to ${CMAKE_USE_DIR}.
55 # For out-of-source build it can be overridden, by default it uses
56 # ${WORKDIR}/${P}_build.
57 -#
58 -# This variable has been called CMAKE_BUILD_DIR formerly.
59 -# It is set under that name for compatibility.
60 +: ${BUILD_DIR:=${WORKDIR}/${P}_build}
61
62 # @ECLASS-VARIABLE: CMAKE_BINARY
63 # @DESCRIPTION:
64 @@ -39,9 +37,9 @@
65 # @DESCRIPTION:
66 # Set to override default CMAKE_BUILD_TYPE. Only useful for packages
67 # known to make use of "if (CMAKE_BUILD_TYPE MATCHES xxx)".
68 -# If about to be set - needs to be set before invoking cmake-utils_src_configure.
69 -# You usualy do *NOT* want nor need to set it as it pulls CMake default build-type
70 -# specific compiler flags overriding make.conf.
71 +# If about to be set - needs to be set before invoking cmake_src_configure.
72 +# You usually do *NOT* want nor need to set it as it pulls CMake default
73 +# build-type specific compiler flags overriding make.conf.
74 : ${CMAKE_BUILD_TYPE:=Gentoo}
75
76 # @ECLASS-VARIABLE: CMAKE_IN_SOURCE_BUILD
77 @@ -54,30 +52,20 @@
78 # @DESCRIPTION:
79 # Specify a makefile generator to be used by cmake.
80 # At this point only "emake" and "ninja" are supported.
81 -# In EAPI 7 and above, the default is set to "ninja",
82 -# whereas in EAPIs below 7, it is set to "emake".
83 -
84 -# @ECLASS-VARIABLE: CMAKE_MIN_VERSION
85 -# @DESCRIPTION:
86 -# Specify the minimum required CMake version.
87 -: ${CMAKE_MIN_VERSION:=3.9.6}
88 -
89 -# @ECLASS-VARIABLE: CMAKE_REMOVE_MODULES
90 -# @DESCRIPTION:
91 -# Do we want to remove anything? yes or whatever else for no
92 -: ${CMAKE_REMOVE_MODULES:=yes}
93 +# The default is set to "ninja".
94 +: ${CMAKE_MAKEFILE_GENERATOR:=ninja}
95
96 # @ECLASS-VARIABLE: CMAKE_REMOVE_MODULES_LIST
97 # @DESCRIPTION:
98 -# Space-separated list of CMake modules that will be removed in $S during src_prepare,
99 +# Array of CMake modules that will be removed in $S during src_prepare,
100 # in order to force packages to use the system version.
101 +# Set to "none" to disable removing modules entirely.
102 : ${CMAKE_REMOVE_MODULES_LIST:=FindBLAS FindLAPACK}
103
104 # @ECLASS-VARIABLE: CMAKE_USE_DIR
105 # @DESCRIPTION:
106 -# Sets the directory where we are working with cmake.
107 -# For example when application uses autotools and only one
108 -# plugin needs to be done by cmake.
109 +# Sets the directory where we are working with cmake, for example when
110 +# application uses autotools and only one plugin needs to be done by cmake.
111 # By default it uses ${S}.
112
113 # @ECLASS-VARIABLE: CMAKE_VERBOSE
114 @@ -90,6 +78,7 @@
115 # Warn about variables that are declared on the command line
116 # but not used. Might give false-positives.
117 # "no" to disable (default) or anything else to enable.
118 +: ${CMAKE_WARN_UNUSED_CLI:=yes}
119
120 # @ECLASS-VARIABLE: CMAKE_EXTRA_CACHE_FILE
121 # @DEFAULT_UNSET
122 @@ -98,41 +87,27 @@
123 # for econf and is needed to pass TRY_RUN results when cross-compiling.
124 # Should be set by user in a per-package basis in /etc/portage/package.env.
125
126 -# @ECLASS-VARIABLE: CMAKE_UTILS_QA_SRC_DIR_READONLY
127 +# @ECLASS-VARIABLE: CMAKE_QA_SRC_DIR_READONLY
128 # @DEFAULT_UNSET
129 # @DESCRIPTION:
130 -# After running cmake-utils_src_prepare, sets ${S} to read-only. This is
131 +# After running cmake_src_prepare, sets ${S} to read-only. This is
132 # a user flag and should under _no circumstances_ be set in the ebuild.
133 # Helps in improving QA of build systems that write to source tree.
134
135 case ${EAPI} in
136 - 5) : ${CMAKE_WARN_UNUSED_CLI:=no} ;;
137 - 6|7) : ${CMAKE_WARN_UNUSED_CLI:=yes} ;;
138 + 7) ;;
139 *) die "EAPI=${EAPI:-0} is not supported" ;;
140 esac
141
142 inherit toolchain-funcs ninja-utils flag-o-matic multiprocessing xdg-utils
143
144 -case ${EAPI} in
145 - [56])
146 - : ${CMAKE_MAKEFILE_GENERATOR:=emake}
147 - inherit eutils multilib
148 - ;;
149 - *)
150 - : ${CMAKE_MAKEFILE_GENERATOR:=ninja}
151 - ;;
152 -esac
153 -
154 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install
155
156 -if [[ ${WANT_CMAKE} ]]; then
157 - if [[ ${EAPI} != [56] ]]; then
158 - die "\${WANT_CMAKE} has been removed and is a no-op now"
159 - else
160 - eqawarn "\${WANT_CMAKE} has been removed and is a no-op now"
161 - fi
162 -fi
163 -[[ ${PREFIX} ]] && die "\${PREFIX} has been removed and is a no-op now"
164 +[[ ${CMAKE_BUILD_DIR} ]] && die "The ebuild must be migrated to BUILD_DIR"
165 +[[ ${CMAKE_REMOVE_MODULES} ]] && die "CMAKE_REMOVE_MODULES is banned, set CMAKE_REMOVE_MODULES_LIST=\"\" instead"
166 +[[ ${CMAKE_UTILS_QA_SRC_DIR_READONLY} ]] && die "Use CMAKE_QA_SRC_DIR_READONLY instead"
167 +[[ ${WANT_CMAKE} ]] && die "WANT_CMAKE has been removed and is a no-op"
168 +[[ ${PREFIX} ]] && die "PREFIX has been removed and is a no-op"
169
170 case ${CMAKE_MAKEFILE_GENERATOR} in
171 emake)
172 @@ -148,60 +123,15 @@
173 esac
174
175 if [[ ${PN} != cmake ]]; then
176 - BDEPEND+=" >=dev-util/cmake-${CMAKE_MIN_VERSION}"
177 + BDEPEND+=" dev-util/cmake"
178 fi
179
180 -case ${EAPI} in
181 - 7) ;;
182 - *) DEPEND=" ${BDEPEND}" ;;
183 -esac
184 -
185 -# Internal functions used by cmake-utils_use_*
186 -_cmake_use_me_now() {
187 - debug-print-function ${FUNCNAME} "$@"
188 -
189 - local arg=$2
190 - [[ ! -z $3 ]] && arg=$3
191 -
192 - [[ ${EAPI} == 5 ]] || die "${FUNCNAME[1]} is banned in EAPI 6 and later: use -D$1<related_CMake_variable>=\"\$(usex $2)\" instead"
193 -
194 - local uper capitalised x
195 - [[ -z $2 ]] && die "cmake-utils_use-$1 <USE flag> [<flag name>]"
196 - if [[ ! -z $3 ]]; then
197 - # user specified the use name so use it
198 - echo "-D$1$3=$(use $2 && echo ON || echo OFF)"
199 - else
200 - # use all various most used combinations
201 - uper=$(echo ${2} | tr '[:lower:]' '[:upper:]')
202 - capitalised=$(echo ${2} | sed 's/\<\(.\)\([^ ]*\)/\u\1\L\2/g')
203 - for x in $2 $uper $capitalised; do
204 - echo "-D$1$x=$(use $2 && echo ON || echo OFF) "
205 - done
206 - fi
207 -}
208 -_cmake_use_me_now_inverted() {
209 - debug-print-function ${FUNCNAME} "$@"
210 -
211 - local arg=$2
212 - [[ ! -z $3 ]] && arg=$3
213 -
214 - if [[ ${EAPI} != 5 && "${FUNCNAME[1]}" != cmake-utils_use_find_package ]] ; then
215 - die "${FUNCNAME[1]} is banned in EAPI 6 and later: use -D$1<related_CMake_variable>=\"\$(usex $2)\" instead"
216 - fi
217 -
218 - local uper capitalised x
219 - [[ -z $2 ]] && die "cmake-utils_use-$1 <USE flag> [<flag name>]"
220 - if [[ ! -z $3 ]]; then
221 - # user specified the use name so use it
222 - echo "-D$1$3=$(use $2 && echo OFF || echo ON)"
223 - else
224 - # use all various most used combinations
225 - uper=$(echo ${2} | tr '[:lower:]' '[:upper:]')
226 - capitalised=$(echo ${2} | sed 's/\<\(.\)\([^ ]*\)/\u\1\L\2/g')
227 - for x in $2 $uper $capitalised; do
228 - echo "-D$1$x=$(use $2 && echo OFF || echo ON) "
229 - done
230 - fi
231 +# @FUNCTION: _cmake_banned_func
232 +# @INTERNAL
233 +# @DESCRIPTION:
234 +# Banned functions are banned.
235 +_cmake_banned_func() {
236 + die "${FUNCNAME[1]} is banned. use -D$1<related_CMake_variable>=\"\$(usex $2)\" instead"
237 }
238
239 # Determine using IN or OUT source build
240 @@ -210,69 +140,10 @@
241 if [[ -n ${CMAKE_IN_SOURCE_BUILD} ]]; then
242 # we build in source dir
243 BUILD_DIR="${CMAKE_USE_DIR}"
244 - else
245 - # Respect both the old variable and the new one, depending
246 - # on which one was set by the ebuild.
247 - if [[ ! ${BUILD_DIR} && ${CMAKE_BUILD_DIR} ]]; then
248 - if [[ ${EAPI} != [56] ]]; then
249 - eerror "The CMAKE_BUILD_DIR variable has been renamed to BUILD_DIR."
250 - die "The ebuild must be migrated to BUILD_DIR."
251 - else
252 - eqawarn "The CMAKE_BUILD_DIR variable has been renamed to BUILD_DIR."
253 - eqawarn "Please migrate the ebuild to use the new one."
254 - fi
255 -
256 - # In the next call, both variables will be set already
257 - # and we'd have to know which one takes precedence.
258 - _RESPECT_CMAKE_BUILD_DIR=1
259 - fi
260 -
261 - if [[ ${_RESPECT_CMAKE_BUILD_DIR} ]]; then
262 - BUILD_DIR=${CMAKE_BUILD_DIR:-${WORKDIR}/${P}_build}
263 - else
264 - : ${BUILD_DIR:=${WORKDIR}/${P}_build}
265 - fi
266 fi
267
268 - # Backwards compatibility for getting the value.
269 - [[ ${EAPI} == [56] ]] && CMAKE_BUILD_DIR=${BUILD_DIR}
270 -
271 mkdir -p "${BUILD_DIR}" || die
272 - echo ">>> Working in BUILD_DIR: \"$BUILD_DIR\""
273 -}
274 -
275 -# Determine which generator to use
276 -_cmake_generator_to_use() {
277 - local generator_name
278 -
279 - case ${CMAKE_MAKEFILE_GENERATOR} in
280 - ninja)
281 - # if ninja is enabled but not installed, the build could fail
282 - # this could happen if ninja is manually enabled (eg. make.conf) but not installed
283 - case ${EAPI} in
284 - 5|6)
285 - if ! ROOT=/ has_version dev-util/ninja; then
286 - die "CMAKE_MAKEFILE_GENERATOR is set to ninja, but ninja is not installed. Please install dev-util/ninja or unset CMAKE_MAKEFILE_GENERATOR."
287 - fi
288 - ;;
289 - *)
290 - if ! has_version -b dev-util/ninja; then
291 - die "CMAKE_MAKEFILE_GENERATOR is set to ninja, but ninja is not installed. Please install dev-util/ninja or unset CMAKE_MAKEFILE_GENERATOR."
292 - fi
293 - ;;
294 - esac
295 - generator_name="Ninja"
296 - ;;
297 - emake)
298 - generator_name="Unix Makefiles"
299 - ;;
300 - *)
301 - eerror "Unknown value for \${CMAKE_MAKEFILE_GENERATOR}"
302 - die "Value ${CMAKE_MAKEFILE_GENERATOR} is not supported"
303 - ;;
304 - esac
305 -
306 - echo ${generator_name}
307 + einfo "Working in BUILD_DIR: \"$BUILD_DIR\""
308 }
309
310 # @FUNCTION: cmake_comment_add_subdirectory
311 @@ -294,133 +165,90 @@
312 }
313
314 # @FUNCTION: comment_add_subdirectory
315 -# @USAGE: <subdirectory>
316 +# @INTERNAL
317 # @DESCRIPTION:
318 -# Comment out an add_subdirectory call in CMakeLists.txt in the current directory
319 -# Banned in EAPI 6 and later - use cmake_comment_add_subdirectory instead.
320 +# Banned. Use cmake_comment_add_subdirectory instead.
321 comment_add_subdirectory() {
322 - [[ ${EAPI} == 5 ]] || die "comment_add_subdirectory is banned in EAPI 6 and later - use cmake_comment_add_subdirectory instead"
323 -
324 - cmake_comment_add_subdirectory "$@"
325 + die "comment_add_subdirectory is banned. Use cmake_comment_add_subdirectory instead"
326 }
327
328 # @FUNCTION: cmake-utils_use_with
329 -# @USAGE: <USE flag> [flag name]
330 +# @INTERNAL
331 # @DESCRIPTION:
332 -# Based on use_with. See ebuild(5).
333 -#
334 -# `cmake-utils_use_with foo FOO` echoes -DWITH_FOO=ON if foo is enabled
335 -# and -DWITH_FOO=OFF if it is disabled.
336 -cmake-utils_use_with() { _cmake_use_me_now WITH_ "$@" ; }
337 +# Banned. Use -DWITH_FOO=$(usex foo) instead.
338 +cmake-utils_use_with() { _cmake_banned_func WITH_ "$@" ; }
339
340 # @FUNCTION: cmake-utils_use_enable
341 -# @USAGE: <USE flag> [flag name]
342 +# @INTERNAL
343 # @DESCRIPTION:
344 -# Based on use_enable. See ebuild(5).
345 -#
346 -# `cmake-utils_use_enable foo FOO` echoes -DENABLE_FOO=ON if foo is enabled
347 -# and -DENABLE_FOO=OFF if it is disabled.
348 -cmake-utils_use_enable() { _cmake_use_me_now ENABLE_ "$@" ; }
349 +# Banned. Use -DENABLE_FOO=$(usex foo) instead.
350 +cmake-utils_use_enable() { _cmake_banned_func ENABLE_ "$@" ; }
351
352 -# @FUNCTION: cmake-utils_use_find_package
353 +# @FUNCTION: cmake_use_find_package
354 # @USAGE: <USE flag> <package name>
355 # @DESCRIPTION:
356 # Based on use_enable. See ebuild(5).
357 #
358 -# `cmake-utils_use_find_package foo LibFoo` echoes -DCMAKE_DISABLE_FIND_PACKAGE_LibFoo=OFF
359 +# `cmake_use_find_package foo LibFoo` echoes -DCMAKE_DISABLE_FIND_PACKAGE_LibFoo=OFF
360 # if foo is enabled and -DCMAKE_DISABLE_FIND_PACKAGE_LibFoo=ON if it is disabled.
361 # This can be used to make find_package optional.
362 -cmake-utils_use_find_package() {
363 - if [[ ${EAPI} != 5 && "$#" != 2 ]] ; then
364 - die "Usage: cmake-utils_use_find_package <USE flag> <package name>"
365 - fi
366 -
367 - _cmake_use_me_now_inverted CMAKE_DISABLE_FIND_PACKAGE_ "$@" ;
368 -}
369 -
370 -# @FUNCTION: cmake_use_find_package
371 -# @USAGE: <USE flag> <package name>
372 -# @DESCRIPTION:
373 -# Alias for cmake-utils_use_find_package.
374 cmake_use_find_package() {
375 - if [[ "$#" != 2 ]] ; then
376 + debug-print-function ${FUNCNAME} "$@"
377 +
378 + if [[ "$#" != 2 || -z $1 ]] ; then
379 die "Usage: cmake_use_find_package <USE flag> <package name>"
380 fi
381
382 - cmake-utils_use_find_package "$@" ;
383 + echo "-DCMAKE_DISABLE_FIND_PACKAGE_$2=$(use $1 && echo OFF || echo ON)"
384 }
385
386 # @FUNCTION: cmake-utils_use_disable
387 -# @USAGE: <USE flag> [flag name]
388 +# @INTERNAL
389 # @DESCRIPTION:
390 -# Based on inversion of use_enable. See ebuild(5).
391 -#
392 -# `cmake-utils_use_enable foo FOO` echoes -DDISABLE_FOO=OFF if foo is enabled
393 -# and -DDISABLE_FOO=ON if it is disabled.
394 -cmake-utils_use_disable() { _cmake_use_me_now_inverted DISABLE_ "$@" ; }
395 +# Banned. Use -DDISABLE_FOO=$(usex !foo) instead.
396 +cmake-utils_use_disable() { _cmake_banned_func DISABLE_ "$@" ; }
397
398 # @FUNCTION: cmake-utils_use_no
399 -# @USAGE: <USE flag> [flag name]
400 +# @INTERNAL
401 # @DESCRIPTION:
402 -# Based on use_disable. See ebuild(5).
403 -#
404 -# `cmake-utils_use_no foo FOO` echoes -DNO_FOO=OFF if foo is enabled
405 -# and -DNO_FOO=ON if it is disabled.
406 -cmake-utils_use_no() { _cmake_use_me_now_inverted NO_ "$@" ; }
407 +# Banned. Use -DNO_FOO=$(usex !foo) instead.
408 +cmake-utils_use_no() { _cmake_banned_func NO_ "$@" ; }
409
410 # @FUNCTION: cmake-utils_use_want
411 -# @USAGE: <USE flag> [flag name]
412 +# @INTERNAL
413 # @DESCRIPTION:
414 -# Based on use_enable. See ebuild(5).
415 -#
416 -# `cmake-utils_use_want foo FOO` echoes -DWANT_FOO=ON if foo is enabled
417 -# and -DWANT_FOO=OFF if it is disabled.
418 -cmake-utils_use_want() { _cmake_use_me_now WANT_ "$@" ; }
419 +# Banned. Use -DWANT_FOO=$(usex foo) instead.
420 +cmake-utils_use_want() { _cmake_banned_func WANT_ "$@" ; }
421
422 # @FUNCTION: cmake-utils_use_build
423 -# @USAGE: <USE flag> [flag name]
424 +# @INTERNAL
425 # @DESCRIPTION:
426 -# Based on use_enable. See ebuild(5).
427 -#
428 -# `cmake-utils_use_build foo FOO` echoes -DBUILD_FOO=ON if foo is enabled
429 -# and -DBUILD_FOO=OFF if it is disabled.
430 -cmake-utils_use_build() { _cmake_use_me_now BUILD_ "$@" ; }
431 +# Banned. Use -DBUILD_FOO=$(usex foo) instead.
432 +cmake-utils_use_build() { _cmake_banned_func BUILD_ "$@" ; }
433
434 # @FUNCTION: cmake-utils_use_has
435 -# @USAGE: <USE flag> [flag name]
436 +# @INTERNAL
437 # @DESCRIPTION:
438 -# Based on use_enable. See ebuild(5).
439 -#
440 -# `cmake-utils_use_has foo FOO` echoes -DHAVE_FOO=ON if foo is enabled
441 -# and -DHAVE_FOO=OFF if it is disabled.
442 -cmake-utils_use_has() { _cmake_use_me_now HAVE_ "$@" ; }
443 +# Banned. Use -DHAVE_FOO=$(usex foo) instead.
444 +cmake-utils_use_has() { _cmake_banned_func HAVE_ "$@" ; }
445
446 # @FUNCTION: cmake-utils_use_use
447 -# @USAGE: <USE flag> [flag name]
448 +# @INTERNAL
449 # @DESCRIPTION:
450 -# Based on use_enable. See ebuild(5).
451 -#
452 -# `cmake-utils_use_use foo FOO` echoes -DUSE_FOO=ON if foo is enabled
453 -# and -DUSE_FOO=OFF if it is disabled.
454 -cmake-utils_use_use() { _cmake_use_me_now USE_ "$@" ; }
455 +# Banned. Use -DUSE_FOO=$(usex foo) instead.
456 +cmake-utils_use_use() { _cmake_banned_func USE_ "$@" ; }
457
458 # @FUNCTION: cmake-utils_use
459 -# @USAGE: <USE flag> [flag name]
460 +# @INTERNAL
461 # @DESCRIPTION:
462 -# Based on use_enable. See ebuild(5).
463 -#
464 -# `cmake-utils_use foo FOO` echoes -DFOO=ON if foo is enabled
465 -# and -DFOO=OFF if it is disabled.
466 -cmake-utils_use() { _cmake_use_me_now "" "$@" ; }
467 +# Banned. Use -DFOO=$(usex foo) instead.
468 +cmake-utils_use() { _cmake_banned_func "" "$@" ; }
469
470 # @FUNCTION: cmake-utils_useno
471 -# @USAGE: <USE flag> [flag name]
472 +# @INTERNAL
473 # @DESCRIPTION:
474 -# Based on use_enable. See ebuild(5).
475 -#
476 -# `cmake-utils_useno foo NOFOO` echoes -DNOFOO=OFF if foo is enabled
477 -# and -DNOFOO=ON if it is disabled.
478 -cmake-utils_useno() { _cmake_use_me_now_inverted "" "$@" ; }
479 +# Banned. Use -DNOFOO=$(usex !foo) instead.
480 +cmake-utils_useno() { _cmake_banned_func "" "$@" ; }
481
482 # Internal function for modifying hardcoded definitions.
483 # Removes dangerous definitions that override Gentoo settings.
484 @@ -459,17 +287,14 @@
485 _EOF_
486 }
487
488 -# temporary function for moving cmake cleanups from from src_configure -> src_prepare.
489 -# bug #378850
490 -_cmake_cleanup_cmake() {
491 - : ${CMAKE_USE_DIR:=${S}}
492 +# @FUNCTION: cmake_src_prepare
493 +# @DESCRIPTION:
494 +# Apply ebuild and user patches.
495 +cmake_src_prepare() {
496 + debug-print-function ${FUNCNAME} "$@"
497
498 - if [[ "${CMAKE_REMOVE_MODULES}" == "yes" ]] ; then
499 - local name
500 - for name in ${CMAKE_REMOVE_MODULES_LIST} ; do
501 - find "${S}" -name ${name}.cmake -exec rm -v {} + || die
502 - done
503 - fi
504 + default_src_prepare
505 + _cmake_check_build_dir
506
507 # check if CMakeLists.txt exist and if no then die
508 if [[ ! -e ${CMAKE_USE_DIR}/CMakeLists.txt ]] ; then
509 @@ -479,37 +304,34 @@
510 die "FATAL: Unable to find CMakeLists.txt"
511 fi
512
513 - # Remove dangerous things.
514 - _cmake_modify-cmakelists
515 -}
516 -
517 -# @FUNCTION: cmake-utils_src_prepare
518 -# @DESCRIPTION:
519 -# Apply ebuild and user patches.
520 -cmake-utils_src_prepare() {
521 - debug-print-function ${FUNCNAME} "$@"
522 -
523 - pushd "${S}" > /dev/null || die
524 + # if ninja is enabled but not installed, the build could fail
525 + # this could happen if ninja is manually enabled (eg. make.conf) but not installed
526 + if [[ ${CMAKE_MAKEFILE_GENERATOR} == ninja ]] && ! has_version -b dev-util/ninja; then
527 + eerror "CMAKE_MAKEFILE_GENERATOR is set to ninja, but ninja is not installed."
528 + die "Please install dev-util/ninja or unset CMAKE_MAKEFILE_GENERATOR."
529 + fi
530
531 - if [[ ${EAPI} != 5 ]]; then
532 - default_src_prepare
533 - _cmake_cleanup_cmake
534 + local modules_list
535 + if [[ $(declare -p CMAKE_REMOVE_MODULES_LIST) == "declare -a"* ]]; then
536 + modules_list=( "${CMAKE_REMOVE_MODULES_LIST[@]}" )
537 else
538 - debug-print "$FUNCNAME: PATCHES=$PATCHES"
539 - [[ ${PATCHES[@]} ]] && epatch "${PATCHES[@]}"
540 -
541 - debug-print "$FUNCNAME: applying user patches"
542 - epatch_user
543 + modules_list=( ${CMAKE_REMOVE_MODULES_LIST} )
544 fi
545
546 - popd > /dev/null || die
547 + local name
548 + for name in "${modules_list[@]}" ; do
549 + find "${S}" -name ${name}.cmake -exec rm -v {} + || die
550 + done
551 +
552 + # Remove dangerous things.
553 + _cmake_modify-cmakelists
554
555 # make ${S} read-only in order to detect broken build-systems
556 - if [[ ${CMAKE_UTILS_QA_SRC_DIR_READONLY} && ! ${CMAKE_IN_SOURCE_BUILD} ]]; then
557 + if [[ ${CMAKE_QA_SRC_DIR_READONLY} && ! ${CMAKE_IN_SOURCE_BUILD} ]]; then
558 chmod -R a-w "${S}"
559 fi
560
561 - _CMAKE_UTILS_SRC_PREPARE_HAS_RUN=1
562 + _CMAKE_SRC_PREPARE_HAS_RUN=1
563 }
564
565 # @VARIABLE: mycmakeargs
566 @@ -520,29 +342,22 @@
567 # @CODE
568 # src_configure() {
569 # local mycmakeargs=(
570 -# $(cmake-utils_use_with openconnect)
571 +# $(cmake_use_with openconnect)
572 # )
573 #
574 -# cmake-utils_src_configure
575 +# cmake_src_configure
576 # }
577 # @CODE
578
579 -# @FUNCTION: cmake-utils_src_configure
580 +# @FUNCTION: cmake_src_configure
581 # @DESCRIPTION:
582 # General function for configuring with cmake. Default behaviour is to start an
583 # out-of-source build.
584 -cmake-utils_src_configure() {
585 +cmake_src_configure() {
586 debug-print-function ${FUNCNAME} "$@"
587
588 - if [[ ! ${_CMAKE_UTILS_SRC_PREPARE_HAS_RUN} ]]; then
589 - if [[ ${EAPI} != [56] ]]; then
590 - die "FATAL: cmake-utils_src_prepare has not been run"
591 - else
592 - eqawarn "cmake-utils_src_prepare has not been run, please open a bug on https://bugs.gentoo.org/"
593 - fi
594 - fi
595 -
596 - [[ ${EAPI} == 5 ]] && _cmake_cleanup_cmake
597 + [[ ${_CMAKE_SRC_PREPARE_HAS_RUN} ]] || \
598 + die "FATAL: cmake_src_prepare has not been run"
599
600 _cmake_check_build_dir
601
602 @@ -552,7 +367,7 @@
603 # @SEE CMAKE_BUILD_TYPE
604 if [[ ${CMAKE_BUILD_TYPE} = Gentoo ]]; then
605 # Handle release builds
606 - if ! has debug ${IUSE//+} || ! use debug; then
607 + if ! in_iuse debug || ! use debug; then
608 local CPPFLAGS=${CPPFLAGS}
609 append-cppflags -DNDEBUG
610 fi
611 @@ -655,18 +470,15 @@
612 SET (CMAKE_INSTALL_INFODIR "${EPREFIX}/usr/share/info" CACHE PATH "")
613 SET (CMAKE_INSTALL_MANDIR "${EPREFIX}/usr/share/man" CACHE PATH "")
614 SET (CMAKE_USER_MAKE_RULES_OVERRIDE "${build_rules}" CACHE FILEPATH "Gentoo override rules")
615 + SET (CMAKE_INSTALL_DOCDIR "${EPREFIX}/usr/share/doc/${PF}" CACHE PATH "")
616 + SET (BUILD_SHARED_LIBS ON CACHE BOOL "")
617 _EOF_
618 - [[ "${NOCOLOR}" = true || "${NOCOLOR}" = yes ]] && echo 'SET (CMAKE_COLOR_MAKEFILE OFF CACHE BOOL "pretty colors during make" FORCE)' >> "${common_config}"
619 -
620 - if [[ ${EAPI} != [56] ]]; then
621 - cat >> "${common_config}" <<- _EOF_ || die
622 - SET (CMAKE_INSTALL_DOCDIR "${EPREFIX}/usr/share/doc/${PF}" CACHE PATH "")
623 - SET (BUILD_SHARED_LIBS ON CACHE BOOL "")
624 - _EOF_
625 + if [[ "${NOCOLOR}" = true || "${NOCOLOR}" = yes ]]; then
626 + echo 'SET (CMAKE_COLOR_MAKEFILE OFF CACHE BOOL "pretty colors during make" FORCE)' >> "${common_config}" || die
627 fi
628
629 # Wipe the default optimization flags out of CMake
630 - if [[ ${CMAKE_BUILD_TYPE} != Gentoo && ${EAPI} != 5 ]]; then
631 + if [[ ${CMAKE_BUILD_TYPE} != Gentoo ]]; then
632 cat >> ${common_config} <<- _EOF_ || die
633 SET (CMAKE_ASM_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "")
634 SET (CMAKE_ASM-ATT_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "")
635 @@ -680,40 +492,36 @@
636 _EOF_
637 fi
638
639 - # Convert mycmakeargs to an array, for backwards compatibility
640 # Make the array a local variable since <=portage-2.1.6.x does not
641 # support global arrays (see bug #297255).
642 local mycmakeargstype=$(declare -p mycmakeargs 2>&-)
643 if [[ "${mycmakeargstype}" != "declare -a mycmakeargs="* ]]; then
644 - if [[ -n "${mycmakeargstype}" ]] ; then
645 - if [[ ${EAPI} == 5 ]]; then
646 - eqawarn "Declaring mycmakeargs as a variable is deprecated. Please use an array instead."
647 - else
648 - die "Declaring mycmakeargs as a variable is banned in EAPI=${EAPI}. Please use an array instead."
649 - fi
650 - fi
651 - local mycmakeargs_local=(${mycmakeargs})
652 - else
653 - local mycmakeargs_local=("${mycmakeargs[@]}")
654 + die "mycmakeargs must be declared as array"
655 fi
656
657 + local mycmakeargs_local=( "${mycmakeargs[@]}" )
658 +
659 + local warn_unused_cli=""
660 if [[ ${CMAKE_WARN_UNUSED_CLI} == no ]] ; then
661 - local warn_unused_cli="--no-warn-unused-cli"
662 - else
663 - local warn_unused_cli=""
664 + warn_unused_cli="--no-warn-unused-cli"
665 fi
666
667 + local generator_name
668 + case ${CMAKE_MAKEFILE_GENERATOR} in
669 + ninja) generator_name="Ninja" ;;
670 + emake) generator_name="Unix Makefiles" ;;
671 + esac
672 +
673 # Common configure parameters (overridable)
674 # NOTE CMAKE_BUILD_TYPE can be only overridden via CMAKE_BUILD_TYPE eclass variable
675 # No -DCMAKE_BUILD_TYPE=xxx definitions will be in effect.
676 local cmakeargs=(
677 ${warn_unused_cli}
678 -C "${common_config}"
679 - -G "$(_cmake_generator_to_use)"
680 + -G "${generator_name}"
681 -DCMAKE_INSTALL_PREFIX="${EPREFIX}/usr"
682 "${mycmakeargs_local[@]}"
683 -DCMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}"
684 - $([[ ${EAPI} == 5 ]] && echo -DCMAKE_INSTALL_DO_STRIP=OFF)
685 -DCMAKE_TOOLCHAIN_FILE="${toolchain_file}"
686 "${MYCMAKEARGS}"
687 )
688 @@ -729,64 +537,53 @@
689 popd > /dev/null || die
690 }
691
692 -# @FUNCTION: cmake-utils_src_compile
693 +# @FUNCTION: cmake_src_compile
694 # @DESCRIPTION:
695 # General function for compiling with cmake.
696 # Automatically detects the build type. All arguments are passed to emake.
697 -cmake-utils_src_compile() {
698 +cmake_src_compile() {
699 debug-print-function ${FUNCNAME} "$@"
700
701 - cmake-utils_src_make "$@"
702 + cmake_build "$@"
703 }
704
705 -# @FUNCTION: _cmake_ninja_src_make
706 -# @INTERNAL
707 -# @DESCRIPTION:
708 -# Build the package using ninja generator
709 -_cmake_ninja_src_make() {
710 - debug-print-function ${FUNCNAME} "$@"
711 -
712 - [[ -e build.ninja ]] || die "build.ninja not found. Error during configure stage."
713 -
714 - eninja "$@"
715 -}
716 -
717 -# @FUNCTION: _cmake_emake_src_make
718 -# @INTERNAL
719 -# @DESCRIPTION:
720 -# Build the package using make generator
721 -_cmake_emake_src_make() {
722 - debug-print-function ${FUNCNAME} "$@"
723 -
724 - [[ -e Makefile ]] || die "Makefile not found. Error during configure stage."
725 -
726 - if [[ "${CMAKE_VERBOSE}" != "OFF" ]]; then
727 - emake VERBOSE=1 "$@" || die
728 - else
729 - emake "$@" || die
730 - fi
731 -
732 -}
733 -
734 -# @FUNCTION: cmake-utils_src_make
735 +# @FUNCTION: cmake_build
736 # @DESCRIPTION:
737 # Function for building the package. Automatically detects the build type.
738 # All arguments are passed to emake.
739 -cmake-utils_src_make() {
740 +cmake_build() {
741 debug-print-function ${FUNCNAME} "$@"
742
743 _cmake_check_build_dir
744 pushd "${BUILD_DIR}" > /dev/null || die
745
746 - _cmake_${CMAKE_MAKEFILE_GENERATOR}_src_make "$@"
747 + case ${CMAKE_MAKEFILE_GENERATOR} in
748 + emake)
749 + [[ -e Makefile ]] || die "Makefile not found. Error during configure stage."
750 + [[ "${CMAKE_VERBOSE}" != "OFF" ]] && local verbosity="VERBOSE=1"
751 + emake "${verbosity} ""$@"
752 + ;;
753 + ninja)
754 + [[ -e build.ninja ]] || die "build.ninja not found. Error during configure stage."
755 + eninja "$@"
756 + ;;
757 + esac
758
759 popd > /dev/null || die
760 }
761
762 -# @FUNCTION: cmake-utils_src_test
763 +# @FUNCTION: cmake-utils_src_make
764 +# @INTERNAL
765 +# @DESCRIPTION:
766 +# Banned. Use cmake_build instead.
767 +cmake-utils_src_make() {
768 + die "cmake_src_make is banned. Use cmake_build instead"
769 +}
770 +
771 +# @FUNCTION: cmake_src_test
772 # @DESCRIPTION:
773 # Function for testing the package. Automatically detects the build type.
774 -cmake-utils_src_test() {
775 +cmake_src_test() {
776 debug-print-function ${FUNCNAME} "$@"
777
778 _cmake_check_build_dir
779 @@ -819,15 +616,16 @@
780 fi
781 }
782
783 -# @FUNCTION: cmake-utils_src_install
784 +# @FUNCTION: cmake_src_install
785 # @DESCRIPTION:
786 # Function for installing the package. Automatically detects the build type.
787 -cmake-utils_src_install() {
788 +cmake_src_install() {
789 debug-print-function ${FUNCNAME} "$@"
790
791 _cmake_check_build_dir
792 pushd "${BUILD_DIR}" > /dev/null || die
793 - DESTDIR="${D}" ${CMAKE_MAKEFILE_GENERATOR} install "$@" || die "died running ${CMAKE_MAKEFILE_GENERATOR} install"
794 + DESTDIR="${D}" ${CMAKE_MAKEFILE_GENERATOR} install "$@" ||
795 + die "died running ${CMAKE_MAKEFILE_GENERATOR} install"
796 popd > /dev/null || die
797
798 pushd "${S}" > /dev/null || die

Replies

Subject Author
[gentoo-dev] [PATCH 2/2] cmake-multilib.eclass: Add CMAKE_ECLASS switch Andreas Sturmlechner <asturm@g.o>