Gentoo Archives: gentoo-commits

From: Andreas Sturmlechner <asturm@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: eclass/
Date: Sun, 29 Dec 2019 13:04:12
Message-Id: 1577624620.9053737a4e16fb1c9bcdd95373ef4e42d61404f4.asturm@gentoo
1 commit: 9053737a4e16fb1c9bcdd95373ef4e42d61404f4
2 Author: Andreas Sturmlechner <asturm <AT> gentoo <DOT> org>
3 AuthorDate: Sat Dec 21 10:50:29 2019 +0000
4 Commit: Andreas Sturmlechner <asturm <AT> gentoo <DOT> org>
5 CommitDate: Sun Dec 29 13:03:40 2019 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=9053737a
7
8 cmake.eclass: New eclass, EAPI-7 only cleanup of cmake-utils
9
10 - Drop all pre-EAPI-7 compatibility
11 - Drop CMAKE_MIN_VERSION
12 - Drop CMAKE_REMOVE_MODULES
13 - Array support for CMAKE_REMOVE_MODULES_LIST
14 - Drop pushd/popd from src_prepare
15 - Drop _cmake_generator_to_use()
16 CMAKE_MAKEFILE_GENERATOR validity is already checked in global scope.
17 Move the check for dev-util/ninja into src_prepare.
18 - Rename cmake_src_make() -> cmake_build()
19 - Drop _cmake_ninja_src_build and _cmake_emake_src_build, move into cmake_build
20
21 Signed-off-by: Andreas Sturmlechner <asturm <AT> gentoo.org>
22
23 eclass/cmake.eclass | 637 ++++++++++++++++++++++++++++++++++++++++++++++++++++
24 1 file changed, 637 insertions(+)
25
26 diff --git a/eclass/cmake.eclass b/eclass/cmake.eclass
27 new file mode 100644
28 index 00000000000..4a52cd9ea25
29 --- /dev/null
30 +++ b/eclass/cmake.eclass
31 @@ -0,0 +1,637 @@
32 +# Copyright 1999-2019 Gentoo Authors
33 +# Distributed under the terms of the GNU General Public License v2
34 +
35 +# @ECLASS: cmake.eclass
36 +# @MAINTAINER:
37 +# kde@g.o
38 +# @AUTHOR:
39 +# Tomáš Chvátal <scarabeus@g.o>
40 +# Maciej Mrozowski <reavertm@g.o>
41 +# (undisclosed contributors)
42 +# Original author: Zephyrus (zephyrus@××××××.it)
43 +# @SUPPORTED_EAPIS: 7
44 +# @BLURB: common ebuild functions for cmake-based packages
45 +# @DESCRIPTION:
46 +# The cmake eclass makes creating ebuilds for cmake-based packages much easier.
47 +# It provides all inherited features (DOCS, HTML_DOCS, PATCHES) along with
48 +# out-of-source builds (default), in-source builds and an implementation of the
49 +# well-known use_enable function for CMake.
50 +
51 +if [[ -z ${_CMAKE_ECLASS} ]]; then
52 +_CMAKE_ECLASS=1
53 +
54 +# @ECLASS-VARIABLE: BUILD_DIR
55 +# @DESCRIPTION:
56 +# Build directory where all cmake processed files should be generated.
57 +# For in-source build it's fixed to ${CMAKE_USE_DIR}.
58 +# For out-of-source build it can be overridden, by default it uses
59 +# ${WORKDIR}/${P}_build.
60 +: ${BUILD_DIR:=${WORKDIR}/${P}_build}
61 +
62 +# @ECLASS-VARIABLE: CMAKE_BINARY
63 +# @DESCRIPTION:
64 +# Eclass can use different cmake binary than the one provided in by system.
65 +: ${CMAKE_BINARY:=cmake}
66 +
67 +# @ECLASS-VARIABLE: CMAKE_BUILD_TYPE
68 +# @DESCRIPTION:
69 +# Set to override default CMAKE_BUILD_TYPE. Only useful for packages
70 +# known to make use of "if (CMAKE_BUILD_TYPE MATCHES xxx)".
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 +# @DEFAULT_UNSET
78 +# @DESCRIPTION:
79 +# Set to enable in-source build.
80 +
81 +# @ECLASS-VARIABLE: CMAKE_MAKEFILE_GENERATOR
82 +# @DEFAULT_UNSET
83 +# @DESCRIPTION:
84 +# Specify a makefile generator to be used by cmake.
85 +# At this point only "emake" and "ninja" are supported.
86 +# The default is set to "ninja".
87 +: ${CMAKE_MAKEFILE_GENERATOR:=ninja}
88 +
89 +# @ECLASS-VARIABLE: CMAKE_REMOVE_MODULES_LIST
90 +# @DESCRIPTION:
91 +# Array of CMake modules that will be removed in $S during src_prepare,
92 +# in order to force packages to use the system version.
93 +# Set to "none" to disable removing modules entirely.
94 +: ${CMAKE_REMOVE_MODULES_LIST:=FindBLAS FindLAPACK}
95 +
96 +# @ECLASS-VARIABLE: CMAKE_USE_DIR
97 +# @DESCRIPTION:
98 +# Sets the directory where we are working with cmake, for example when
99 +# application uses autotools and only one plugin needs to be done by cmake.
100 +# By default it uses ${S}.
101 +
102 +# @ECLASS-VARIABLE: CMAKE_VERBOSE
103 +# @DESCRIPTION:
104 +# Set to OFF to disable verbose messages during compilation
105 +: ${CMAKE_VERBOSE:=ON}
106 +
107 +# @ECLASS-VARIABLE: CMAKE_WARN_UNUSED_CLI
108 +# @DESCRIPTION:
109 +# Warn about variables that are declared on the command line
110 +# but not used. Might give false-positives.
111 +# "no" to disable (default) or anything else to enable.
112 +: ${CMAKE_WARN_UNUSED_CLI:=yes}
113 +
114 +# @ECLASS-VARIABLE: CMAKE_EXTRA_CACHE_FILE
115 +# @DEFAULT_UNSET
116 +# @DESCRIPTION:
117 +# Specifies an extra cache file to pass to cmake. This is the analog of EXTRA_ECONF
118 +# for econf and is needed to pass TRY_RUN results when cross-compiling.
119 +# Should be set by user in a per-package basis in /etc/portage/package.env.
120 +
121 +# @ECLASS-VARIABLE: CMAKE_QA_SRC_DIR_READONLY
122 +# @DEFAULT_UNSET
123 +# @DESCRIPTION:
124 +# After running cmake_src_prepare, sets ${S} to read-only. This is
125 +# a user flag and should under _no circumstances_ be set in the ebuild.
126 +# Helps in improving QA of build systems that write to source tree.
127 +
128 +case ${EAPI} in
129 + 7) ;;
130 + *) die "EAPI=${EAPI:-0} is not supported" ;;
131 +esac
132 +
133 +inherit toolchain-funcs ninja-utils flag-o-matic multiprocessing xdg-utils
134 +
135 +EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install
136 +
137 +[[ ${CMAKE_BUILD_DIR} ]] && die "The ebuild must be migrated to BUILD_DIR"
138 +[[ ${CMAKE_REMOVE_MODULES} ]] && die "CMAKE_REMOVE_MODULES is banned, set CMAKE_REMOVE_MODULES_LIST=\"\" instead"
139 +[[ ${CMAKE_UTILS_QA_SRC_DIR_READONLY} ]] && die "Use CMAKE_QA_SRC_DIR_READONLY instead"
140 +[[ ${WANT_CMAKE} ]] && die "WANT_CMAKE has been removed and is a no-op"
141 +[[ ${PREFIX} ]] && die "PREFIX has been removed and is a no-op"
142 +
143 +case ${CMAKE_MAKEFILE_GENERATOR} in
144 + emake)
145 + BDEPEND="sys-devel/make"
146 + ;;
147 + ninja)
148 + BDEPEND="dev-util/ninja"
149 + ;;
150 + *)
151 + eerror "Unknown value for \${CMAKE_MAKEFILE_GENERATOR}"
152 + die "Value ${CMAKE_MAKEFILE_GENERATOR} is not supported"
153 + ;;
154 +esac
155 +
156 +if [[ ${PN} != cmake ]]; then
157 + BDEPEND+=" dev-util/cmake"
158 +fi
159 +
160 +# @FUNCTION: _cmake_banned_func
161 +# @INTERNAL
162 +# @DESCRIPTION:
163 +# Banned functions are banned.
164 +_cmake_banned_func() {
165 + die "${FUNCNAME[1]} is banned. use -D$1<related_CMake_variable>=\"\$(usex $2)\" instead"
166 +}
167 +
168 +# Determine using IN or OUT source build
169 +_cmake_check_build_dir() {
170 + : ${CMAKE_USE_DIR:=${S}}
171 + if [[ -n ${CMAKE_IN_SOURCE_BUILD} ]]; then
172 + # we build in source dir
173 + BUILD_DIR="${CMAKE_USE_DIR}"
174 + fi
175 +
176 + mkdir -p "${BUILD_DIR}" || die
177 + einfo "Working in BUILD_DIR: \"$BUILD_DIR\""
178 +}
179 +
180 +# @FUNCTION: cmake_comment_add_subdirectory
181 +# @USAGE: <subdirectory>
182 +# @DESCRIPTION:
183 +# Comment out one or more add_subdirectory calls in CMakeLists.txt in the current directory
184 +cmake_comment_add_subdirectory() {
185 + if [[ -z ${1} ]]; then
186 + die "comment_add_subdirectory must be passed at least one directory name to comment"
187 + fi
188 +
189 + if [[ -e "CMakeLists.txt" ]]; then
190 + local d
191 + for d in $@; do
192 + sed -e "/add_subdirectory[[:space:]]*([[:space:]]*${d//\//\\/}[[:space:]]*)/I s/^/#DONOTCOMPILE /" \
193 + -i CMakeLists.txt || die "failed to comment add_subdirectory(${d})"
194 + done
195 + fi
196 +}
197 +
198 +# @FUNCTION: comment_add_subdirectory
199 +# @INTERNAL
200 +# @DESCRIPTION:
201 +# Banned. Use cmake_comment_add_subdirectory instead.
202 +comment_add_subdirectory() {
203 + die "comment_add_subdirectory is banned. Use cmake_comment_add_subdirectory instead"
204 +}
205 +
206 +# @FUNCTION: cmake-utils_use_with
207 +# @INTERNAL
208 +# @DESCRIPTION:
209 +# Banned. Use -DWITH_FOO=$(usex foo) instead.
210 +cmake-utils_use_with() { _cmake_banned_func WITH_ "$@" ; }
211 +
212 +# @FUNCTION: cmake-utils_use_enable
213 +# @INTERNAL
214 +# @DESCRIPTION:
215 +# Banned. Use -DENABLE_FOO=$(usex foo) instead.
216 +cmake-utils_use_enable() { _cmake_banned_func ENABLE_ "$@" ; }
217 +
218 +# @FUNCTION: cmake_use_find_package
219 +# @USAGE: <USE flag> <package name>
220 +# @DESCRIPTION:
221 +# Based on use_enable. See ebuild(5).
222 +#
223 +# `cmake_use_find_package foo LibFoo` echoes -DCMAKE_DISABLE_FIND_PACKAGE_LibFoo=OFF
224 +# if foo is enabled and -DCMAKE_DISABLE_FIND_PACKAGE_LibFoo=ON if it is disabled.
225 +# This can be used to make find_package optional.
226 +cmake_use_find_package() {
227 + debug-print-function ${FUNCNAME} "$@"
228 +
229 + if [[ "$#" != 2 || -z $1 ]] ; then
230 + die "Usage: cmake_use_find_package <USE flag> <package name>"
231 + fi
232 +
233 + echo "-DCMAKE_DISABLE_FIND_PACKAGE_$2=$(use $1 && echo OFF || echo ON)"
234 +}
235 +
236 +# @FUNCTION: cmake-utils_use_disable
237 +# @INTERNAL
238 +# @DESCRIPTION:
239 +# Banned. Use -DDISABLE_FOO=$(usex !foo) instead.
240 +cmake-utils_use_disable() { _cmake_banned_func DISABLE_ "$@" ; }
241 +
242 +# @FUNCTION: cmake-utils_use_no
243 +# @INTERNAL
244 +# @DESCRIPTION:
245 +# Banned. Use -DNO_FOO=$(usex !foo) instead.
246 +cmake-utils_use_no() { _cmake_banned_func NO_ "$@" ; }
247 +
248 +# @FUNCTION: cmake-utils_use_want
249 +# @INTERNAL
250 +# @DESCRIPTION:
251 +# Banned. Use -DWANT_FOO=$(usex foo) instead.
252 +cmake-utils_use_want() { _cmake_banned_func WANT_ "$@" ; }
253 +
254 +# @FUNCTION: cmake-utils_use_build
255 +# @INTERNAL
256 +# @DESCRIPTION:
257 +# Banned. Use -DBUILD_FOO=$(usex foo) instead.
258 +cmake-utils_use_build() { _cmake_banned_func BUILD_ "$@" ; }
259 +
260 +# @FUNCTION: cmake-utils_use_has
261 +# @INTERNAL
262 +# @DESCRIPTION:
263 +# Banned. Use -DHAVE_FOO=$(usex foo) instead.
264 +cmake-utils_use_has() { _cmake_banned_func HAVE_ "$@" ; }
265 +
266 +# @FUNCTION: cmake-utils_use_use
267 +# @INTERNAL
268 +# @DESCRIPTION:
269 +# Banned. Use -DUSE_FOO=$(usex foo) instead.
270 +cmake-utils_use_use() { _cmake_banned_func USE_ "$@" ; }
271 +
272 +# @FUNCTION: cmake-utils_use
273 +# @INTERNAL
274 +# @DESCRIPTION:
275 +# Banned. Use -DFOO=$(usex foo) instead.
276 +cmake-utils_use() { _cmake_banned_func "" "$@" ; }
277 +
278 +# @FUNCTION: cmake-utils_useno
279 +# @INTERNAL
280 +# @DESCRIPTION:
281 +# Banned. Use -DNOFOO=$(usex !foo) instead.
282 +cmake-utils_useno() { _cmake_banned_func "" "$@" ; }
283 +
284 +# Internal function for modifying hardcoded definitions.
285 +# Removes dangerous definitions that override Gentoo settings.
286 +_cmake_modify-cmakelists() {
287 + debug-print-function ${FUNCNAME} "$@"
288 +
289 + # Only edit the files once
290 + grep -qs "<<< Gentoo configuration >>>" "${CMAKE_USE_DIR}"/CMakeLists.txt && return 0
291 +
292 + # Comment out all set (<some_should_be_user_defined_variable> value)
293 + find "${CMAKE_USE_DIR}" -name CMakeLists.txt -exec sed \
294 + -e '/^[[:space:]]*set[[:space:]]*([[:space:]]*CMAKE_BUILD_TYPE\([[:space:]].*)\|)\)/I{s/^/#_cmake_modify_IGNORE /g}' \
295 + -e '/^[[:space:]]*set[[:space:]]*([[:space:]]*CMAKE_COLOR_MAKEFILE[[:space:]].*)/I{s/^/#_cmake_modify_IGNORE /g}' \
296 + -e '/^[[:space:]]*set[[:space:]]*([[:space:]]*CMAKE_INSTALL_PREFIX[[:space:]].*)/I{s/^/#_cmake_modify_IGNORE /g}' \
297 + -e '/^[[:space:]]*set[[:space:]]*([[:space:]]*CMAKE_VERBOSE_MAKEFILE[[:space:]].*)/I{s/^/#_cmake_modify_IGNORE /g}' \
298 + -i {} + || die "${LINENO}: failed to disable hardcoded settings"
299 + local x
300 + for x in $(find "${CMAKE_USE_DIR}" -name CMakeLists.txt -exec grep -l "^#_cmake_modify_IGNORE" {} +;); do
301 + einfo "Hardcoded definition(s) removed in $(echo "${x}" | cut -c $((${#CMAKE_USE_DIR}+2))-):"
302 + einfo "$(grep -se '^#_cmake_modify_IGNORE' ${x} | cut -c 22-99)"
303 + done
304 +
305 + # NOTE Append some useful summary here
306 + cat >> "${CMAKE_USE_DIR}"/CMakeLists.txt <<- _EOF_ || die
307 +
308 + MESSAGE(STATUS "<<< Gentoo configuration >>>
309 + Build type \${CMAKE_BUILD_TYPE}
310 + Install path \${CMAKE_INSTALL_PREFIX}
311 + Compiler flags:
312 + C \${CMAKE_C_FLAGS}
313 + C++ \${CMAKE_CXX_FLAGS}
314 + Linker flags:
315 + Executable \${CMAKE_EXE_LINKER_FLAGS}
316 + Module \${CMAKE_MODULE_LINKER_FLAGS}
317 + Shared \${CMAKE_SHARED_LINKER_FLAGS}\n")
318 + _EOF_
319 +}
320 +
321 +# @FUNCTION: cmake_src_prepare
322 +# @DESCRIPTION:
323 +# Apply ebuild and user patches.
324 +cmake_src_prepare() {
325 + debug-print-function ${FUNCNAME} "$@"
326 +
327 + default_src_prepare
328 + _cmake_check_build_dir
329 +
330 + # check if CMakeLists.txt exist and if no then die
331 + if [[ ! -e ${CMAKE_USE_DIR}/CMakeLists.txt ]] ; then
332 + eerror "Unable to locate CMakeLists.txt under:"
333 + eerror "\"${CMAKE_USE_DIR}/CMakeLists.txt\""
334 + eerror "Consider not inheriting the cmake eclass."
335 + die "FATAL: Unable to find CMakeLists.txt"
336 + fi
337 +
338 + # if ninja is enabled but not installed, the build could fail
339 + # this could happen if ninja is manually enabled (eg. make.conf) but not installed
340 + if [[ ${CMAKE_MAKEFILE_GENERATOR} == ninja ]] && ! has_version -b dev-util/ninja; then
341 + eerror "CMAKE_MAKEFILE_GENERATOR is set to ninja, but ninja is not installed."
342 + die "Please install dev-util/ninja or unset CMAKE_MAKEFILE_GENERATOR."
343 + fi
344 +
345 + local modules_list
346 + if [[ $(declare -p CMAKE_REMOVE_MODULES_LIST) == "declare -a"* ]]; then
347 + modules_list=( "${CMAKE_REMOVE_MODULES_LIST[@]}" )
348 + else
349 + modules_list=( ${CMAKE_REMOVE_MODULES_LIST} )
350 + fi
351 +
352 + local name
353 + for name in "${modules_list[@]}" ; do
354 + find "${S}" -name ${name}.cmake -exec rm -v {} + || die
355 + done
356 +
357 + # Remove dangerous things.
358 + _cmake_modify-cmakelists
359 +
360 + # make ${S} read-only in order to detect broken build-systems
361 + if [[ ${CMAKE_QA_SRC_DIR_READONLY} && ! ${CMAKE_IN_SOURCE_BUILD} ]]; then
362 + chmod -R a-w "${S}"
363 + fi
364 +
365 + _CMAKE_SRC_PREPARE_HAS_RUN=1
366 +}
367 +
368 +# @VARIABLE: mycmakeargs
369 +# @DEFAULT_UNSET
370 +# @DESCRIPTION:
371 +# Optional cmake defines as a bash array. Should be defined before calling
372 +# src_configure.
373 +# @CODE
374 +# src_configure() {
375 +# local mycmakeargs=(
376 +# $(cmake_use_with openconnect)
377 +# )
378 +#
379 +# cmake_src_configure
380 +# }
381 +# @CODE
382 +
383 +# @FUNCTION: cmake_src_configure
384 +# @DESCRIPTION:
385 +# General function for configuring with cmake. Default behaviour is to start an
386 +# out-of-source build.
387 +cmake_src_configure() {
388 + debug-print-function ${FUNCNAME} "$@"
389 +
390 + [[ ${_CMAKE_SRC_PREPARE_HAS_RUN} ]] || \
391 + die "FATAL: cmake_src_prepare has not been run"
392 +
393 + _cmake_check_build_dir
394 +
395 + # Fix xdg collision with sandbox
396 + xdg_environment_reset
397 +
398 + # @SEE CMAKE_BUILD_TYPE
399 + if [[ ${CMAKE_BUILD_TYPE} = Gentoo ]]; then
400 + # Handle release builds
401 + if ! in_iuse debug || ! use debug; then
402 + local CPPFLAGS=${CPPFLAGS}
403 + append-cppflags -DNDEBUG
404 + fi
405 + fi
406 +
407 + # Prepare Gentoo override rules (set valid compiler, append CPPFLAGS etc.)
408 + local build_rules=${BUILD_DIR}/gentoo_rules.cmake
409 +
410 + cat > "${build_rules}" <<- _EOF_ || die
411 + SET (CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> <DEFINES> <INCLUDES> ${CPPFLAGS} <FLAGS> -o <OBJECT> -c <SOURCE>" CACHE STRING "ASM compile command" FORCE)
412 + SET (CMAKE_ASM-ATT_COMPILE_OBJECT "<CMAKE_ASM-ATT_COMPILER> <DEFINES> <INCLUDES> ${CPPFLAGS} <FLAGS> -o <OBJECT> -c -x assembler <SOURCE>" CACHE STRING "ASM-ATT compile command" FORCE)
413 + SET (CMAKE_ASM-ATT_LINK_FLAGS "-nostdlib" CACHE STRING "ASM-ATT link flags" FORCE)
414 + SET (CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> <DEFINES> <INCLUDES> ${CPPFLAGS} <FLAGS> -o <OBJECT> -c <SOURCE>" CACHE STRING "C compile command" FORCE)
415 + SET (CMAKE_CXX_COMPILE_OBJECT "<CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> ${CPPFLAGS} <FLAGS> -o <OBJECT> -c <SOURCE>" CACHE STRING "C++ compile command" FORCE)
416 + SET (CMAKE_Fortran_COMPILE_OBJECT "<CMAKE_Fortran_COMPILER> <DEFINES> <INCLUDES> ${FCFLAGS} <FLAGS> -o <OBJECT> -c <SOURCE>" CACHE STRING "Fortran compile command" FORCE)
417 + _EOF_
418 +
419 + local myCC=$(tc-getCC) myCXX=$(tc-getCXX) myFC=$(tc-getFC)
420 +
421 + # !!! IMPORTANT NOTE !!!
422 + # Single slash below is intentional. CMake is weird and wants the
423 + # CMAKE_*_VARIABLES split into two elements: the first one with
424 + # compiler path, and the second one with all command-line options,
425 + # space separated.
426 + local toolchain_file=${BUILD_DIR}/gentoo_toolchain.cmake
427 + cat > ${toolchain_file} <<- _EOF_ || die
428 + SET (CMAKE_ASM_COMPILER "${myCC/ /;}")
429 + SET (CMAKE_ASM-ATT_COMPILER "${myCC/ /;}")
430 + SET (CMAKE_C_COMPILER "${myCC/ /;}")
431 + SET (CMAKE_CXX_COMPILER "${myCXX/ /;}")
432 + SET (CMAKE_Fortran_COMPILER "${myFC/ /;}")
433 + SET (CMAKE_AR $(type -P $(tc-getAR)) CACHE FILEPATH "Archive manager" FORCE)
434 + SET (CMAKE_RANLIB $(type -P $(tc-getRANLIB)) CACHE FILEPATH "Archive index generator" FORCE)
435 + SET (CMAKE_SYSTEM_PROCESSOR "${CHOST%%-*}")
436 + _EOF_
437 +
438 + # We are using the C compiler for assembly by default.
439 + local -x ASMFLAGS=${CFLAGS}
440 + local -x PKG_CONFIG=$(tc-getPKG_CONFIG)
441 +
442 + if tc-is-cross-compiler; then
443 + local sysname
444 + case "${KERNEL:-linux}" in
445 + Cygwin) sysname="CYGWIN_NT-5.1" ;;
446 + HPUX) sysname="HP-UX" ;;
447 + linux) sysname="Linux" ;;
448 + Winnt)
449 + sysname="Windows"
450 + cat >> "${toolchain_file}" <<- _EOF_ || die
451 + SET (CMAKE_RC_COMPILER $(tc-getRC))
452 + _EOF_
453 + ;;
454 + *) sysname="${KERNEL}" ;;
455 + esac
456 +
457 + cat >> "${toolchain_file}" <<- _EOF_ || die
458 + SET (CMAKE_SYSTEM_NAME "${sysname}")
459 + _EOF_
460 +
461 + if [ "${SYSROOT:-/}" != "/" ] ; then
462 + # When cross-compiling with a sysroot (e.g. with crossdev's emerge wrappers)
463 + # we need to tell cmake to use libs/headers from the sysroot but programs from / only.
464 + cat >> "${toolchain_file}" <<- _EOF_ || die
465 + SET (CMAKE_FIND_ROOT_PATH "${SYSROOT}")
466 + SET (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
467 + SET (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
468 + SET (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
469 + _EOF_
470 + fi
471 + fi
472 +
473 + if use prefix-guest; then
474 + cat >> "${build_rules}" <<- _EOF_ || die
475 + # in Prefix we need rpath and must ensure cmake gets our default linker path
476 + # right ... except for Darwin hosts
477 + IF (NOT APPLE)
478 + SET (CMAKE_SKIP_RPATH OFF CACHE BOOL "" FORCE)
479 + SET (CMAKE_PLATFORM_REQUIRED_RUNTIME_PATH "${EPREFIX}/usr/${CHOST}/lib/gcc;${EPREFIX}/usr/${CHOST}/lib;${EPREFIX}/usr/$(get_libdir);${EPREFIX}/$(get_libdir)"
480 + CACHE STRING "" FORCE)
481 +
482 + ELSE ()
483 +
484 + SET (CMAKE_PREFIX_PATH "${EPREFIX}/usr" CACHE STRING "" FORCE)
485 + SET (CMAKE_MACOSX_RPATH ON CACHE BOOL "" FORCE)
486 + SET (CMAKE_SKIP_BUILD_RPATH OFF CACHE BOOL "" FORCE)
487 + SET (CMAKE_SKIP_RPATH OFF CACHE BOOL "" FORCE)
488 + SET (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE CACHE BOOL "" FORCE)
489 +
490 + ENDIF (NOT APPLE)
491 + _EOF_
492 + fi
493 +
494 + # Common configure parameters (invariants)
495 + local common_config=${BUILD_DIR}/gentoo_common_config.cmake
496 + local libdir=$(get_libdir)
497 + cat > "${common_config}" <<- _EOF_ || die
498 + SET (CMAKE_GENTOO_BUILD ON CACHE BOOL "Indicate Gentoo package build")
499 + SET (LIB_SUFFIX ${libdir/lib} CACHE STRING "library path suffix" FORCE)
500 + SET (CMAKE_INSTALL_LIBDIR ${libdir} CACHE PATH "Output directory for libraries")
501 + SET (CMAKE_INSTALL_INFODIR "${EPREFIX}/usr/share/info" CACHE PATH "")
502 + SET (CMAKE_INSTALL_MANDIR "${EPREFIX}/usr/share/man" CACHE PATH "")
503 + SET (CMAKE_USER_MAKE_RULES_OVERRIDE "${build_rules}" CACHE FILEPATH "Gentoo override rules")
504 + SET (CMAKE_INSTALL_DOCDIR "${EPREFIX}/usr/share/doc/${PF}" CACHE PATH "")
505 + SET (BUILD_SHARED_LIBS ON CACHE BOOL "")
506 + _EOF_
507 + if [[ "${NOCOLOR}" = true || "${NOCOLOR}" = yes ]]; then
508 + echo 'SET (CMAKE_COLOR_MAKEFILE OFF CACHE BOOL "pretty colors during make" FORCE)' >> "${common_config}" || die
509 + fi
510 +
511 + # Wipe the default optimization flags out of CMake
512 + if [[ ${CMAKE_BUILD_TYPE} != Gentoo ]]; then
513 + cat >> ${common_config} <<- _EOF_ || die
514 + SET (CMAKE_ASM_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "")
515 + SET (CMAKE_ASM-ATT_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "")
516 + SET (CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "")
517 + SET (CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "")
518 + SET (CMAKE_Fortran_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "")
519 + SET (CMAKE_EXE_LINKER_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "")
520 + SET (CMAKE_MODULE_LINKER_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "")
521 + SET (CMAKE_SHARED_LINKER_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "")
522 + SET (CMAKE_STATIC_LINKER_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "")
523 + _EOF_
524 + fi
525 +
526 + # Make the array a local variable since <=portage-2.1.6.x does not support
527 + # global arrays (see bug #297255). But first make sure it is initialised.
528 + [[ -z ${mycmakeargs} ]] && declare -a mycmakeargs=()
529 + local mycmakeargstype=$(declare -p mycmakeargs 2>&-)
530 + if [[ "${mycmakeargstype}" != "declare -a mycmakeargs="* ]]; then
531 + die "mycmakeargs must be declared as array"
532 + fi
533 +
534 + local mycmakeargs_local=( "${mycmakeargs[@]}" )
535 +
536 + local warn_unused_cli=""
537 + if [[ ${CMAKE_WARN_UNUSED_CLI} == no ]] ; then
538 + warn_unused_cli="--no-warn-unused-cli"
539 + fi
540 +
541 + local generator_name
542 + case ${CMAKE_MAKEFILE_GENERATOR} in
543 + ninja) generator_name="Ninja" ;;
544 + emake) generator_name="Unix Makefiles" ;;
545 + esac
546 +
547 + # Common configure parameters (overridable)
548 + # NOTE CMAKE_BUILD_TYPE can be only overridden via CMAKE_BUILD_TYPE eclass variable
549 + # No -DCMAKE_BUILD_TYPE=xxx definitions will be in effect.
550 + local cmakeargs=(
551 + ${warn_unused_cli}
552 + -C "${common_config}"
553 + -G "${generator_name}"
554 + -DCMAKE_INSTALL_PREFIX="${EPREFIX}/usr"
555 + "${mycmakeargs_local[@]}"
556 + -DCMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}"
557 + -DCMAKE_TOOLCHAIN_FILE="${toolchain_file}"
558 + "${MYCMAKEARGS}"
559 + )
560 +
561 + if [[ -n "${CMAKE_EXTRA_CACHE_FILE}" ]] ; then
562 + cmakeargs+=( -C "${CMAKE_EXTRA_CACHE_FILE}" )
563 + fi
564 +
565 + pushd "${BUILD_DIR}" > /dev/null || die
566 + debug-print "${LINENO} ${ECLASS} ${FUNCNAME}: mycmakeargs is ${mycmakeargs_local[*]}"
567 + echo "${CMAKE_BINARY}" "${cmakeargs[@]}" "${CMAKE_USE_DIR}"
568 + "${CMAKE_BINARY}" "${cmakeargs[@]}" "${CMAKE_USE_DIR}" || die "cmake failed"
569 + popd > /dev/null || die
570 +}
571 +
572 +# @FUNCTION: cmake_src_compile
573 +# @DESCRIPTION:
574 +# General function for compiling with cmake.
575 +# Automatically detects the build type. All arguments are passed to emake.
576 +cmake_src_compile() {
577 + debug-print-function ${FUNCNAME} "$@"
578 +
579 + cmake_build "$@"
580 +}
581 +
582 +# @FUNCTION: cmake_build
583 +# @DESCRIPTION:
584 +# Function for building the package. Automatically detects the build type.
585 +# All arguments are passed to emake.
586 +cmake_build() {
587 + debug-print-function ${FUNCNAME} "$@"
588 +
589 + _cmake_check_build_dir
590 + pushd "${BUILD_DIR}" > /dev/null || die
591 +
592 + case ${CMAKE_MAKEFILE_GENERATOR} in
593 + emake)
594 + [[ -e Makefile ]] || die "Makefile not found. Error during configure stage."
595 + [[ "${CMAKE_VERBOSE}" != "OFF" ]] && local verbosity="VERBOSE=1"
596 + emake "${verbosity} ""$@"
597 + ;;
598 + ninja)
599 + [[ -e build.ninja ]] || die "build.ninja not found. Error during configure stage."
600 + eninja "$@"
601 + ;;
602 + esac
603 +
604 + popd > /dev/null || die
605 +}
606 +
607 +# @FUNCTION: cmake-utils_src_make
608 +# @INTERNAL
609 +# @DESCRIPTION:
610 +# Banned. Use cmake_build instead.
611 +cmake-utils_src_make() {
612 + die "cmake_src_make is banned. Use cmake_build instead"
613 +}
614 +
615 +# @FUNCTION: cmake_src_test
616 +# @DESCRIPTION:
617 +# Function for testing the package. Automatically detects the build type.
618 +cmake_src_test() {
619 + debug-print-function ${FUNCNAME} "$@"
620 +
621 + _cmake_check_build_dir
622 + pushd "${BUILD_DIR}" > /dev/null || die
623 + [[ -e CTestTestfile.cmake ]] || { echo "No tests found. Skipping."; return 0 ; }
624 +
625 + [[ -n ${TEST_VERBOSE} ]] && myctestargs+=( --extra-verbose --output-on-failure )
626 +
627 + set -- ctest -j "$(makeopts_jobs)" --test-load "$(makeopts_loadavg)" "${myctestargs[@]}" "$@"
628 + echo "$@" >&2
629 + if "$@" ; then
630 + einfo "Tests succeeded."
631 + popd > /dev/null || die
632 + return 0
633 + else
634 + if [[ -n "${CMAKE_YES_I_WANT_TO_SEE_THE_TEST_LOG}" ]] ; then
635 + # on request from Diego
636 + eerror "Tests failed. Test log ${BUILD_DIR}/Testing/Temporary/LastTest.log follows:"
637 + eerror "--START TEST LOG--------------------------------------------------------------"
638 + cat "${BUILD_DIR}/Testing/Temporary/LastTest.log"
639 + eerror "--END TEST LOG----------------------------------------------------------------"
640 + die "Tests failed."
641 + else
642 + die "Tests failed. When you file a bug, please attach the following file: \n\t${BUILD_DIR}/Testing/Temporary/LastTest.log"
643 + fi
644 +
645 + # die might not die due to nonfatal
646 + popd > /dev/null || die
647 + return 1
648 + fi
649 +}
650 +
651 +# @FUNCTION: cmake_src_install
652 +# @DESCRIPTION:
653 +# Function for installing the package. Automatically detects the build type.
654 +cmake_src_install() {
655 + debug-print-function ${FUNCNAME} "$@"
656 +
657 + _cmake_check_build_dir
658 + pushd "${BUILD_DIR}" > /dev/null || die
659 + DESTDIR="${D}" ${CMAKE_MAKEFILE_GENERATOR} install "$@" ||
660 + die "died running ${CMAKE_MAKEFILE_GENERATOR} install"
661 + popd > /dev/null || die
662 +
663 + pushd "${S}" > /dev/null || die
664 + einstalldocs
665 + popd > /dev/null || die
666 +}
667 +
668 +fi