eclass/cmake: Sync with gentoo

It's from gentoo commit 3a93d23f14886170b0c33a416aaad7bb70f15256.
This commit is contained in:
Krzesimir Nowak 2021-12-21 09:41:42 +01:00
parent 6d921008d6
commit 84dd601560

View File

@ -1,4 +1,4 @@
# Copyright 1999-2020 Gentoo Authors # Copyright 1999-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2 # Distributed under the terms of the GNU General Public License v2
# @ECLASS: cmake.eclass # @ECLASS: cmake.eclass
@ -9,7 +9,8 @@
# Maciej Mrozowski <reavertm@gentoo.org> # Maciej Mrozowski <reavertm@gentoo.org>
# (undisclosed contributors) # (undisclosed contributors)
# Original author: Zephyrus (zephyrus@mirach.it) # Original author: Zephyrus (zephyrus@mirach.it)
# @SUPPORTED_EAPIS: 7 # @SUPPORTED_EAPIS: 7 8
# @PROVIDES: ninja-utils
# @BLURB: common ebuild functions for cmake-based packages # @BLURB: common ebuild functions for cmake-based packages
# @DESCRIPTION: # @DESCRIPTION:
# The cmake eclass makes creating ebuilds for cmake-based packages much easier. # The cmake eclass makes creating ebuilds for cmake-based packages much easier.
@ -17,30 +18,44 @@
# out-of-source builds (default), in-source builds and an implementation of the # out-of-source builds (default), in-source builds and an implementation of the
# well-known use_enable function for CMake. # well-known use_enable function for CMake.
case ${EAPI} in
7|8) ;;
*) die "${ECLASS}: EAPI=${EAPI:-0} is not supported" ;;
esac
if [[ -z ${_CMAKE_ECLASS} ]]; then if [[ -z ${_CMAKE_ECLASS} ]]; then
_CMAKE_ECLASS=1 _CMAKE_ECLASS=1
inherit flag-o-matic multiprocessing ninja-utils toolchain-funcs xdg-utils
# @ECLASS-VARIABLE: BUILD_DIR # @ECLASS-VARIABLE: BUILD_DIR
# @DEFAULT_UNSET
# @DESCRIPTION: # @DESCRIPTION:
# Build directory where all cmake processed files should be generated. # Build directory where all cmake processed files should be generated.
# For in-source build it's fixed to ${CMAKE_USE_DIR}. # For in-source build it's fixed to ${CMAKE_USE_DIR}.
# For out-of-source build it can be overridden, by default it uses # For out-of-source build it can be overridden, by default it uses
# ${WORKDIR}/${P}_build. # ${CMAKE_USE_DIR}_build (in EAPI-7: ${WORKDIR}/${P}_build).
: ${BUILD_DIR:=${WORKDIR}/${P}_build} [[ ${EAPI} == 7 ]] && : ${BUILD_DIR:=${WORKDIR}/${P}_build}
# EAPI-8: set inside _cmake_check_build_dir
# @ECLASS-VARIABLE: CMAKE_BINARY # @ECLASS-VARIABLE: CMAKE_BINARY
# @DESCRIPTION: # @DESCRIPTION:
# Eclass can use different cmake binary than the one provided in by system. # Eclass can use different cmake binary than the one provided in by system.
: ${CMAKE_BINARY:=cmake} : ${CMAKE_BINARY:=cmake}
[[ ${EAPI} == 7 ]] && : ${CMAKE_BUILD_TYPE:=Gentoo}
# @ECLASS-VARIABLE: CMAKE_BUILD_TYPE # @ECLASS-VARIABLE: CMAKE_BUILD_TYPE
# @DESCRIPTION: # @DESCRIPTION:
# Set to override default CMAKE_BUILD_TYPE. Only useful for packages # Set to override default CMAKE_BUILD_TYPE. Only useful for packages
# known to make use of "if (CMAKE_BUILD_TYPE MATCHES xxx)". # known to make use of "if (CMAKE_BUILD_TYPE MATCHES xxx)".
# If about to be set - needs to be set before invoking cmake_src_configure. # If about to be set - needs to be set before invoking cmake_src_configure.
# You usually do *NOT* want nor need to set it as it pulls CMake default #
# build-type specific compiler flags overriding make.conf. # The default is RelWithDebInfo as that is least likely to append undesirable
: ${CMAKE_BUILD_TYPE:=Gentoo} # flags. However, you may still need to sed CMake files or choose a different
# build type to achieve desirable results.
#
# In EAPI 7, the default was non-standard build type of Gentoo.
: ${CMAKE_BUILD_TYPE:=RelWithDebInfo}
# @ECLASS-VARIABLE: CMAKE_IN_SOURCE_BUILD # @ECLASS-VARIABLE: CMAKE_IN_SOURCE_BUILD
# @DEFAULT_UNSET # @DEFAULT_UNSET
@ -48,6 +63,7 @@ _CMAKE_ECLASS=1
# Set to enable in-source build. # Set to enable in-source build.
# @ECLASS-VARIABLE: CMAKE_MAKEFILE_GENERATOR # @ECLASS-VARIABLE: CMAKE_MAKEFILE_GENERATOR
# @PRE_INHERIT
# @DEFAULT_UNSET # @DEFAULT_UNSET
# @DESCRIPTION: # @DESCRIPTION:
# Specify a makefile generator to be used by cmake. # Specify a makefile generator to be used by cmake.
@ -56,17 +72,29 @@ _CMAKE_ECLASS=1
: ${CMAKE_MAKEFILE_GENERATOR:=ninja} : ${CMAKE_MAKEFILE_GENERATOR:=ninja}
# @ECLASS-VARIABLE: CMAKE_REMOVE_MODULES_LIST # @ECLASS-VARIABLE: CMAKE_REMOVE_MODULES_LIST
# @PRE_INHERIT
# @DEFAULT_UNSET
# @DESCRIPTION: # @DESCRIPTION:
# Array of CMake modules that will be removed in $S during src_prepare, # Array of .cmake modules to be removed in ${CMAKE_USE_DIR} (in EAPI-7: ${S})
# in order to force packages to use the system version. # during src_prepare, in order to force packages to use the system version.
# Set to "none" to disable removing modules entirely. # By default, contains "FindBLAS" and "FindLAPACK".
: ${CMAKE_REMOVE_MODULES_LIST:=FindBLAS FindLAPACK} # Set to empty to disable removing modules entirely.
if [[ ${CMAKE_REMOVE_MODULES_LIST} ]]; then
if [[ ${EAPI} != 7 ]]; then
[[ ${CMAKE_REMOVE_MODULES_LIST@a} == *a* ]] ||
die "CMAKE_REMOVE_MODULES_LIST must be an array"
fi
else
if ! [[ ${CMAKE_REMOVE_MODULES_LIST@a} == *a* && ${#CMAKE_REMOVE_MODULES_LIST[@]} -eq 0 ]]; then
CMAKE_REMOVE_MODULES_LIST=( FindBLAS FindLAPACK )
fi
fi
# @ECLASS-VARIABLE: CMAKE_USE_DIR # @ECLASS-VARIABLE: CMAKE_USE_DIR
# @DESCRIPTION: # @DESCRIPTION:
# Sets the directory where we are working with cmake, for example when # Sets the directory where we are working with cmake, for example when
# application uses autotools and only one plugin needs to be done by cmake. # application uses autotools and only one plugin needs to be done by cmake.
# By default it uses ${S}. # By default it uses current working directory (in EAPI-7: ${S}).
# @ECLASS-VARIABLE: CMAKE_VERBOSE # @ECLASS-VARIABLE: CMAKE_VERBOSE
# @DESCRIPTION: # @DESCRIPTION:
@ -81,6 +109,7 @@ _CMAKE_ECLASS=1
: ${CMAKE_WARN_UNUSED_CLI:=yes} : ${CMAKE_WARN_UNUSED_CLI:=yes}
# @ECLASS-VARIABLE: CMAKE_EXTRA_CACHE_FILE # @ECLASS-VARIABLE: CMAKE_EXTRA_CACHE_FILE
# @USER_VARIABLE
# @DEFAULT_UNSET # @DEFAULT_UNSET
# @DESCRIPTION: # @DESCRIPTION:
# Specifies an extra cache file to pass to cmake. This is the analog of EXTRA_ECONF # Specifies an extra cache file to pass to cmake. This is the analog of EXTRA_ECONF
@ -88,24 +117,16 @@ _CMAKE_ECLASS=1
# Should be set by user in a per-package basis in /etc/portage/package.env. # Should be set by user in a per-package basis in /etc/portage/package.env.
# @ECLASS-VARIABLE: CMAKE_QA_SRC_DIR_READONLY # @ECLASS-VARIABLE: CMAKE_QA_SRC_DIR_READONLY
# @USER_VARIABLE
# @DEFAULT_UNSET # @DEFAULT_UNSET
# @DESCRIPTION: # @DESCRIPTION:
# After running cmake_src_prepare, sets ${S} to read-only. This is # After running cmake_src_prepare, sets ${CMAKE_USE_DIR} (in EAPI-7: ${S}) to
# a user flag and should under _no circumstances_ be set in the ebuild. # read-only. This is a user flag and should under _no circumstances_ be set in
# Helps in improving QA of build systems that write to source tree. # the ebuild. Helps in improving QA of build systems that write to source tree.
case ${EAPI} in
7) ;;
*) die "EAPI=${EAPI:-0} is not supported" ;;
esac
inherit toolchain-funcs ninja-utils flag-o-matic multiprocessing xdg-utils
EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install
[[ ${CMAKE_MIN_VERSION} ]] && die "CMAKE_MIN_VERSION is banned; if necessary, set BDEPEND=\">=dev-util/cmake-${CMAKE_MIN_VERSION}\" directly" [[ ${CMAKE_MIN_VERSION} ]] && die "CMAKE_MIN_VERSION is banned; if necessary, set BDEPEND=\">=dev-util/cmake-${CMAKE_MIN_VERSION}\" directly"
[[ ${CMAKE_BUILD_DIR} ]] && die "The ebuild must be migrated to BUILD_DIR" [[ ${CMAKE_BUILD_DIR} ]] && die "The ebuild must be migrated to BUILD_DIR"
[[ ${CMAKE_REMOVE_MODULES} ]] && die "CMAKE_REMOVE_MODULES is banned, set CMAKE_REMOVE_MODULES_LIST=\"\" instead" [[ ${CMAKE_REMOVE_MODULES} ]] && die "CMAKE_REMOVE_MODULES is banned, set CMAKE_REMOVE_MODULES_LIST array instead"
[[ ${CMAKE_UTILS_QA_SRC_DIR_READONLY} ]] && die "Use CMAKE_QA_SRC_DIR_READONLY instead" [[ ${CMAKE_UTILS_QA_SRC_DIR_READONLY} ]] && die "Use CMAKE_QA_SRC_DIR_READONLY instead"
[[ ${WANT_CMAKE} ]] && die "WANT_CMAKE has been removed and is a no-op" [[ ${WANT_CMAKE} ]] && die "WANT_CMAKE has been removed and is a no-op"
[[ ${PREFIX} ]] && die "PREFIX has been removed and is a no-op" [[ ${PREFIX} ]] && die "PREFIX has been removed and is a no-op"
@ -124,27 +145,23 @@ case ${CMAKE_MAKEFILE_GENERATOR} in
esac esac
if [[ ${PN} != cmake ]]; then if [[ ${PN} != cmake ]]; then
BDEPEND+=" dev-util/cmake" BDEPEND+=" >=dev-util/cmake-3.20.5"
fi fi
# @FUNCTION: _cmake_banned_func # @FUNCTION: cmake_run_in
# @INTERNAL # @USAGE: <working dir> <run command>
# @DESCRIPTION: # @DESCRIPTION:
# Banned functions are banned. # Set the desired working dir for a function or command.
_cmake_banned_func() { cmake_run_in() {
die "${FUNCNAME[1]} is banned. use -D$1<related_CMake_variable>=\"\$(usex $2)\" instead" if [[ -z ${2} ]]; then
} die "${FUNCNAME[0]} must be passed at least two arguments"
# Determine using IN or OUT source build
_cmake_check_build_dir() {
: ${CMAKE_USE_DIR:=${S}}
if [[ -n ${CMAKE_IN_SOURCE_BUILD} ]]; then
# we build in source dir
BUILD_DIR="${CMAKE_USE_DIR}"
fi fi
mkdir -p "${BUILD_DIR}" || die [[ -e ${1} ]] || die "${FUNCNAME[0]}: Nonexistent path: ${1}"
einfo "Working in BUILD_DIR: \"$BUILD_DIR\""
pushd ${1} > /dev/null || die
"${@:2}"
popd > /dev/null || die
} }
# @FUNCTION: cmake_comment_add_subdirectory # @FUNCTION: cmake_comment_add_subdirectory
@ -153,16 +170,17 @@ _cmake_check_build_dir() {
# Comment out one or more add_subdirectory calls in CMakeLists.txt in the current directory # Comment out one or more add_subdirectory calls in CMakeLists.txt in the current directory
cmake_comment_add_subdirectory() { cmake_comment_add_subdirectory() {
if [[ -z ${1} ]]; then if [[ -z ${1} ]]; then
die "comment_add_subdirectory must be passed at least one directory name to comment" die "${FUNCNAME[0]} must be passed at least one directory name to comment"
fi fi
if [[ -e "CMakeLists.txt" ]]; then [[ -e "CMakeLists.txt" ]] || return
local d
for d in $@; do local d
sed -e "/add_subdirectory[[:space:]]*([[:space:]]*${d//\//\\/}[[:space:]]*)/I s/^/#DONOTCOMPILE /" \ for d in $@; do
-i CMakeLists.txt || die "failed to comment add_subdirectory(${d})" d=${d//\//\\/}
done sed -e "/add_subdirectory[[:space:]]*([[:space:]]*${d}[[:space:]]*)/I s/^/#DONOTCOMPILE /" \
fi -i CMakeLists.txt || die "failed to comment add_subdirectory(${d})"
done
} }
# @FUNCTION: comment_add_subdirectory # @FUNCTION: comment_add_subdirectory
@ -173,18 +191,6 @@ comment_add_subdirectory() {
die "comment_add_subdirectory is banned. Use cmake_comment_add_subdirectory instead" die "comment_add_subdirectory is banned. Use cmake_comment_add_subdirectory instead"
} }
# @FUNCTION: cmake-utils_use_with
# @INTERNAL
# @DESCRIPTION:
# Banned. Use -DWITH_FOO=$(usex foo) instead.
cmake-utils_use_with() { _cmake_banned_func WITH_ "$@" ; }
# @FUNCTION: cmake-utils_use_enable
# @INTERNAL
# @DESCRIPTION:
# Banned. Use -DENABLE_FOO=$(usex foo) instead.
cmake-utils_use_enable() { _cmake_banned_func ENABLE_ "$@" ; }
# @FUNCTION: cmake_use_find_package # @FUNCTION: cmake_use_find_package
# @USAGE: <USE flag> <package name> # @USAGE: <USE flag> <package name>
# @DESCRIPTION: # @DESCRIPTION:
@ -203,6 +209,26 @@ cmake_use_find_package() {
echo "-DCMAKE_DISABLE_FIND_PACKAGE_$2=$(use $1 && echo OFF || echo ON)" echo "-DCMAKE_DISABLE_FIND_PACKAGE_$2=$(use $1 && echo OFF || echo ON)"
} }
# @FUNCTION: _cmake_banned_func
# @INTERNAL
# @DESCRIPTION:
# Banned functions are banned.
_cmake_banned_func() {
die "${FUNCNAME[1]} is banned. use -D$1<related_CMake_variable>=\"\$(usex $2)\" instead"
}
# @FUNCTION: cmake-utils_use_with
# @INTERNAL
# @DESCRIPTION:
# Banned. Use -DWITH_FOO=$(usex foo) instead.
cmake-utils_use_with() { _cmake_banned_func WITH_ "$@" ; }
# @FUNCTION: cmake-utils_use_enable
# @INTERNAL
# @DESCRIPTION:
# Banned. Use -DENABLE_FOO=$(usex foo) instead.
cmake-utils_use_enable() { _cmake_banned_func ENABLE_ "$@" ; }
# @FUNCTION: cmake-utils_use_disable # @FUNCTION: cmake-utils_use_disable
# @INTERNAL # @INTERNAL
# @DESCRIPTION: # @DESCRIPTION:
@ -251,6 +277,32 @@ cmake-utils_use() { _cmake_banned_func "" "$@" ; }
# Banned. Use -DNOFOO=$(usex !foo) instead. # Banned. Use -DNOFOO=$(usex !foo) instead.
cmake-utils_useno() { _cmake_banned_func "" "$@" ; } cmake-utils_useno() { _cmake_banned_func "" "$@" ; }
# @FUNCTION: _cmake_check_build_dir
# @INTERNAL
# @DESCRIPTION:
# Determine using IN or OUT source build
_cmake_check_build_dir() {
if [[ ${EAPI} == 7 ]]; then
: ${CMAKE_USE_DIR:=${S}}
else
: ${CMAKE_USE_DIR:=${PWD}}
fi
if [[ -n ${CMAKE_IN_SOURCE_BUILD} ]]; then
# we build in source dir
BUILD_DIR="${CMAKE_USE_DIR}"
else
: ${BUILD_DIR:=${CMAKE_USE_DIR}_build}
fi
einfo "Source directory (CMAKE_USE_DIR): \"${CMAKE_USE_DIR}\""
einfo "Build directory (BUILD_DIR): \"${BUILD_DIR}\""
mkdir -p "${BUILD_DIR}" || die
}
# @FUNCTION: _cmake_modify-cmakelists
# @INTERNAL
# @DESCRIPTION:
# Internal function for modifying hardcoded definitions. # Internal function for modifying hardcoded definitions.
# Removes dangerous definitions that override Gentoo settings. # Removes dangerous definitions that override Gentoo settings.
_cmake_modify-cmakelists() { _cmake_modify-cmakelists() {
@ -275,7 +327,7 @@ _cmake_modify-cmakelists() {
# NOTE Append some useful summary here # NOTE Append some useful summary here
cat >> "${CMAKE_USE_DIR}"/CMakeLists.txt <<- _EOF_ || die cat >> "${CMAKE_USE_DIR}"/CMakeLists.txt <<- _EOF_ || die
MESSAGE(STATUS "<<< Gentoo configuration >>> message(STATUS "<<< Gentoo configuration >>>
Build type \${CMAKE_BUILD_TYPE} Build type \${CMAKE_BUILD_TYPE}
Install path \${CMAKE_INSTALL_PREFIX} Install path \${CMAKE_INSTALL_PREFIX}
Compiler flags: Compiler flags:
@ -290,16 +342,18 @@ _cmake_modify-cmakelists() {
# @FUNCTION: cmake_src_prepare # @FUNCTION: cmake_src_prepare
# @DESCRIPTION: # @DESCRIPTION:
# Apply ebuild and user patches. # Apply ebuild and user patches. *MUST* be run or cmake_src_configure will fail.
cmake_src_prepare() { cmake_src_prepare() {
debug-print-function ${FUNCNAME} "$@" debug-print-function ${FUNCNAME} "$@"
# FIXME: workaround from cmake-utils; use current working directory instead, bug #704524 if [[ ${EAPI} == 7 ]]; then
# esp. test with 'special' pkgs like: app-arch/brotli, media-gfx/gmic, net-libs/quiche pushd "${S}" > /dev/null || die # workaround from cmake-utils
pushd "${S}" > /dev/null || die # in EAPI-8, we use current working directory instead, bug #704524
# esp. test with 'special' pkgs like: app-arch/brotli, media-gfx/gmic, net-libs/quiche
fi
_cmake_check_build_dir
default_src_prepare default_src_prepare
_cmake_check_build_dir
# check if CMakeLists.txt exist and if no then die # check if CMakeLists.txt exist and if no then die
if [[ ! -e ${CMAKE_USE_DIR}/CMakeLists.txt ]] ; then if [[ ! -e ${CMAKE_USE_DIR}/CMakeLists.txt ]] ; then
@ -317,49 +371,55 @@ cmake_src_prepare() {
fi fi
local modules_list local modules_list
if [[ $(declare -p CMAKE_REMOVE_MODULES_LIST) == "declare -a"* ]]; then if [[ ${EAPI} == 7 && $(declare -p CMAKE_REMOVE_MODULES_LIST) != "declare -a"* ]]; then
modules_list=( "${CMAKE_REMOVE_MODULES_LIST[@]}" )
else
modules_list=( ${CMAKE_REMOVE_MODULES_LIST} ) modules_list=( ${CMAKE_REMOVE_MODULES_LIST} )
else
modules_list=( "${CMAKE_REMOVE_MODULES_LIST[@]}" )
fi fi
local name local name
for name in "${modules_list[@]}" ; do for name in "${modules_list[@]}" ; do
find "${S}" -name ${name}.cmake -exec rm -v {} + || die if [[ ${EAPI} == 7 ]]; then
find "${S}" -name ${name}.cmake -exec rm -v {} + || die
else
find -name "${name}.cmake" -exec rm -v {} + || die
fi
done done
# Remove dangerous things. # Remove dangerous things.
_cmake_modify-cmakelists _cmake_modify-cmakelists
popd > /dev/null || die if [[ ${EAPI} == 7 ]]; then
popd > /dev/null || die
fi
# make ${S} read-only in order to detect broken build-systems # Make ${CMAKE_USE_DIR} (in EAPI-7: ${S}) read-only in order to detect
# broken build systems.
if [[ ${CMAKE_QA_SRC_DIR_READONLY} && ! ${CMAKE_IN_SOURCE_BUILD} ]]; then if [[ ${CMAKE_QA_SRC_DIR_READONLY} && ! ${CMAKE_IN_SOURCE_BUILD} ]]; then
chmod -R a-w "${S}" if [[ ${EAPI} == 7 ]]; then
chmod -R a-w "${S}"
else
chmod -R a-w "${CMAKE_USE_DIR}"
fi
fi fi
_CMAKE_SRC_PREPARE_HAS_RUN=1 _CMAKE_SRC_PREPARE_HAS_RUN=1
} }
# @VARIABLE: mycmakeargs
# @DEFAULT_UNSET
# @DESCRIPTION:
# Optional cmake defines as a bash array. Should be defined before calling
# src_configure.
# @CODE
# src_configure() {
# local mycmakeargs=(
# $(cmake_use_with openconnect)
# )
#
# cmake_src_configure
# }
# @CODE
# @FUNCTION: cmake_src_configure # @FUNCTION: cmake_src_configure
# @DESCRIPTION: # @DESCRIPTION:
# General function for configuring with cmake. Default behaviour is to start an # General function for configuring with cmake. Default behaviour is to start an
# out-of-source build. # out-of-source build.
# Passes arguments to cmake by reading from an optionally pre-defined local
# mycmakeargs bash array.
# @CODE
# src_configure() {
# local mycmakeargs=(
# $(cmake_use_find_package foo LibFoo)
# )
# cmake_src_configure
# }
# @CODE
cmake_src_configure() { cmake_src_configure() {
debug-print-function ${FUNCNAME} "$@" debug-print-function ${FUNCNAME} "$@"
@ -375,12 +435,12 @@ cmake_src_configure() {
local build_rules=${BUILD_DIR}/gentoo_rules.cmake local build_rules=${BUILD_DIR}/gentoo_rules.cmake
cat > "${build_rules}" <<- _EOF_ || die cat > "${build_rules}" <<- _EOF_ || die
SET (CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> <DEFINES> <INCLUDES> ${CPPFLAGS} <FLAGS> -o <OBJECT> -c <SOURCE>" CACHE STRING "ASM compile command" FORCE) set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> <DEFINES> <INCLUDES> ${CPPFLAGS} <FLAGS> -o <OBJECT> -c <SOURCE>" CACHE STRING "ASM compile command" FORCE)
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) 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)
SET (CMAKE_ASM-ATT_LINK_FLAGS "-nostdlib" CACHE STRING "ASM-ATT link flags" FORCE) set(CMAKE_ASM-ATT_LINK_FLAGS "-nostdlib" CACHE STRING "ASM-ATT link flags" FORCE)
SET (CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> <DEFINES> <INCLUDES> ${CPPFLAGS} <FLAGS> -o <OBJECT> -c <SOURCE>" CACHE STRING "C compile command" FORCE) set(CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> <DEFINES> <INCLUDES> ${CPPFLAGS} <FLAGS> -o <OBJECT> -c <SOURCE>" CACHE STRING "C compile command" FORCE)
SET (CMAKE_CXX_COMPILE_OBJECT "<CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> ${CPPFLAGS} <FLAGS> -o <OBJECT> -c <SOURCE>" CACHE STRING "C++ compile command" FORCE) set(CMAKE_CXX_COMPILE_OBJECT "<CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> ${CPPFLAGS} <FLAGS> -o <OBJECT> -c <SOURCE>" CACHE STRING "C++ compile command" FORCE)
SET (CMAKE_Fortran_COMPILE_OBJECT "<CMAKE_Fortran_COMPILER> <DEFINES> <INCLUDES> ${FCFLAGS} <FLAGS> -o <OBJECT> -c <SOURCE>" CACHE STRING "Fortran compile command" FORCE) set(CMAKE_Fortran_COMPILE_OBJECT "<CMAKE_Fortran_COMPILER> <DEFINES> <INCLUDES> ${FCFLAGS} <FLAGS> -o <OBJECT> -c <SOURCE>" CACHE STRING "Fortran compile command" FORCE)
_EOF_ _EOF_
local myCC=$(tc-getCC) myCXX=$(tc-getCXX) myFC=$(tc-getFC) local myCC=$(tc-getCC) myCXX=$(tc-getCXX) myFC=$(tc-getFC)
@ -392,14 +452,14 @@ cmake_src_configure() {
# space separated. # space separated.
local toolchain_file=${BUILD_DIR}/gentoo_toolchain.cmake local toolchain_file=${BUILD_DIR}/gentoo_toolchain.cmake
cat > ${toolchain_file} <<- _EOF_ || die cat > ${toolchain_file} <<- _EOF_ || die
SET (CMAKE_ASM_COMPILER "${myCC/ /;}") set(CMAKE_ASM_COMPILER "${myCC/ /;}")
SET (CMAKE_ASM-ATT_COMPILER "${myCC/ /;}") set(CMAKE_ASM-ATT_COMPILER "${myCC/ /;}")
SET (CMAKE_C_COMPILER "${myCC/ /;}") set(CMAKE_C_COMPILER "${myCC/ /;}")
SET (CMAKE_CXX_COMPILER "${myCXX/ /;}") set(CMAKE_CXX_COMPILER "${myCXX/ /;}")
SET (CMAKE_Fortran_COMPILER "${myFC/ /;}") set(CMAKE_Fortran_COMPILER "${myFC/ /;}")
SET (CMAKE_AR $(type -P $(tc-getAR)) CACHE FILEPATH "Archive manager" FORCE) set(CMAKE_AR $(type -P $(tc-getAR)) CACHE FILEPATH "Archive manager" FORCE)
SET (CMAKE_RANLIB $(type -P $(tc-getRANLIB)) CACHE FILEPATH "Archive index generator" FORCE) set(CMAKE_RANLIB $(type -P $(tc-getRANLIB)) CACHE FILEPATH "Archive index generator" FORCE)
SET (CMAKE_SYSTEM_PROCESSOR "${CHOST%%-*}") set(CMAKE_SYSTEM_PROCESSOR "${CHOST%%-*}")
_EOF_ _EOF_
# We are using the C compiler for assembly by default. # We are using the C compiler for assembly by default.
@ -415,24 +475,24 @@ cmake_src_configure() {
Winnt) Winnt)
sysname="Windows" sysname="Windows"
cat >> "${toolchain_file}" <<- _EOF_ || die cat >> "${toolchain_file}" <<- _EOF_ || die
SET (CMAKE_RC_COMPILER $(tc-getRC)) set(CMAKE_RC_COMPILER $(tc-getRC))
_EOF_ _EOF_
;; ;;
*) sysname="${KERNEL}" ;; *) sysname="${KERNEL}" ;;
esac esac
cat >> "${toolchain_file}" <<- _EOF_ || die cat >> "${toolchain_file}" <<- _EOF_ || die
SET (CMAKE_SYSTEM_NAME "${sysname}") set(CMAKE_SYSTEM_NAME "${sysname}")
_EOF_ _EOF_
if [ "${SYSROOT:-/}" != "/" ] ; then if [ "${SYSROOT:-/}" != "/" ] ; then
# When cross-compiling with a sysroot (e.g. with crossdev's emerge wrappers) # When cross-compiling with a sysroot (e.g. with crossdev's emerge wrappers)
# we need to tell cmake to use libs/headers from the sysroot but programs from / only. # we need to tell cmake to use libs/headers from the sysroot but programs from / only.
cat >> "${toolchain_file}" <<- _EOF_ || die cat >> "${toolchain_file}" <<- _EOF_ || die
SET (CMAKE_FIND_ROOT_PATH "${SYSROOT}") set(CMAKE_FIND_ROOT_PATH "${SYSROOT}")
SET (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
_EOF_ _EOF_
fi fi
fi fi
@ -441,20 +501,16 @@ cmake_src_configure() {
cat >> "${build_rules}" <<- _EOF_ || die cat >> "${build_rules}" <<- _EOF_ || die
# in Prefix we need rpath and must ensure cmake gets our default linker path # in Prefix we need rpath and must ensure cmake gets our default linker path
# right ... except for Darwin hosts # right ... except for Darwin hosts
IF (NOT APPLE) if(NOT APPLE)
SET (CMAKE_SKIP_RPATH OFF CACHE BOOL "" FORCE) set(CMAKE_SKIP_RPATH OFF CACHE BOOL "" FORCE)
SET (CMAKE_PLATFORM_REQUIRED_RUNTIME_PATH "${EPREFIX}/usr/${CHOST}/lib/gcc;${EPREFIX}/usr/${CHOST}/lib;${EPREFIX}/usr/$(get_libdir);${EPREFIX}/$(get_libdir)" set(CMAKE_PLATFORM_REQUIRED_RUNTIME_PATH "${EPREFIX}/usr/${CHOST}/lib/gcc;${EPREFIX}/usr/${CHOST}/lib;${EPREFIX}/usr/$(get_libdir);${EPREFIX}/$(get_libdir)" CACHE STRING "" FORCE)
CACHE STRING "" FORCE) else()
set(CMAKE_PREFIX_PATH "${EPREFIX}/usr" CACHE STRING "" FORCE)
ELSE () set(CMAKE_MACOSX_RPATH ON CACHE BOOL "" FORCE)
set(CMAKE_SKIP_BUILD_RPATH OFF CACHE BOOL "" FORCE)
SET (CMAKE_PREFIX_PATH "${EPREFIX}/usr" CACHE STRING "" FORCE) set(CMAKE_SKIP_RPATH OFF CACHE BOOL "" FORCE)
SET (CMAKE_MACOSX_RPATH ON CACHE BOOL "" FORCE) set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE CACHE BOOL "" FORCE)
SET (CMAKE_SKIP_BUILD_RPATH OFF CACHE BOOL "" FORCE) endif()
SET (CMAKE_SKIP_RPATH OFF CACHE BOOL "" FORCE)
SET (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE CACHE BOOL "" FORCE)
ENDIF (NOT APPLE)
_EOF_ _EOF_
fi fi
@ -462,31 +518,46 @@ cmake_src_configure() {
local common_config=${BUILD_DIR}/gentoo_common_config.cmake local common_config=${BUILD_DIR}/gentoo_common_config.cmake
local libdir=$(get_libdir) local libdir=$(get_libdir)
cat > "${common_config}" <<- _EOF_ || die cat > "${common_config}" <<- _EOF_ || die
SET (CMAKE_GENTOO_BUILD ON CACHE BOOL "Indicate Gentoo package build") set(CMAKE_GENTOO_BUILD ON CACHE BOOL "Indicate Gentoo package build")
SET (LIB_SUFFIX ${libdir/lib} CACHE STRING "library path suffix" FORCE) set(LIB_SUFFIX ${libdir/lib} CACHE STRING "library path suffix" FORCE)
SET (CMAKE_INSTALL_LIBDIR ${libdir} CACHE PATH "Output directory for libraries") set(CMAKE_INSTALL_LIBDIR ${libdir} CACHE PATH "Output directory for libraries")
SET (CMAKE_INSTALL_INFODIR "${EPREFIX}/usr/share/info" CACHE PATH "") set(CMAKE_INSTALL_INFODIR "${EPREFIX}/usr/share/info" CACHE PATH "")
SET (CMAKE_INSTALL_MANDIR "${EPREFIX}/usr/share/man" CACHE PATH "") set(CMAKE_INSTALL_MANDIR "${EPREFIX}/usr/share/man" CACHE PATH "")
SET (CMAKE_USER_MAKE_RULES_OVERRIDE "${build_rules}" CACHE FILEPATH "Gentoo override rules") set(CMAKE_USER_MAKE_RULES_OVERRIDE "${build_rules}" CACHE FILEPATH "Gentoo override rules")
SET (CMAKE_INSTALL_DOCDIR "${EPREFIX}/usr/share/doc/${PF}" CACHE PATH "") set(CMAKE_INSTALL_DOCDIR "${EPREFIX}/usr/share/doc/${PF}" CACHE PATH "")
SET (BUILD_SHARED_LIBS ON CACHE BOOL "") set(BUILD_SHARED_LIBS ON CACHE BOOL "")
_EOF_ _EOF_
if [[ -n ${_ECM_ECLASS} ]]; then
echo 'set(ECM_DISABLE_QMLPLUGINDUMP ON CACHE BOOL "")' >> "${common_config}" || die
fi
# See bug 689410
if [[ "${ARCH}" == riscv ]]; then
echo 'set(CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX '"${libdir#lib}"' CACHE STRING "library search suffix" FORCE)' >> "${common_config}" || die
fi
if [[ "${NOCOLOR}" = true || "${NOCOLOR}" = yes ]]; then if [[ "${NOCOLOR}" = true || "${NOCOLOR}" = yes ]]; then
echo 'SET (CMAKE_COLOR_MAKEFILE OFF CACHE BOOL "pretty colors during make" FORCE)' >> "${common_config}" || die echo 'set(CMAKE_COLOR_MAKEFILE OFF CACHE BOOL "pretty colors during make" FORCE)' >> "${common_config}" || die
fi
# See bug 735820
if [[ ${EAPI} != 7 ]]; then
echo 'set(CMAKE_INSTALL_ALWAYS 1)' >> "${common_config}" || die
fi fi
# Wipe the default optimization flags out of CMake # Wipe the default optimization flags out of CMake
if [[ ${CMAKE_BUILD_TYPE} != Gentoo ]]; then if [[ ${CMAKE_BUILD_TYPE} != Gentoo ]]; then
cat >> ${common_config} <<- _EOF_ || die cat >> ${common_config} <<- _EOF_ || die
SET (CMAKE_ASM_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "") set(CMAKE_ASM_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "")
SET (CMAKE_ASM-ATT_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "") set(CMAKE_ASM-ATT_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "")
SET (CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "") set(CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "")
SET (CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "") set(CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "")
SET (CMAKE_Fortran_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "") set(CMAKE_Fortran_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "")
SET (CMAKE_EXE_LINKER_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "") set(CMAKE_EXE_LINKER_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "")
SET (CMAKE_MODULE_LINKER_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "") set(CMAKE_MODULE_LINKER_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "")
SET (CMAKE_SHARED_LINKER_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "") set(CMAKE_SHARED_LINKER_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "")
SET (CMAKE_STATIC_LINKER_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "") set(CMAKE_STATIC_LINKER_FLAGS_${CMAKE_BUILD_TYPE^^} "" CACHE STRING "")
_EOF_ _EOF_
fi fi
@ -538,8 +609,8 @@ cmake_src_configure() {
# @FUNCTION: cmake_src_compile # @FUNCTION: cmake_src_compile
# @DESCRIPTION: # @DESCRIPTION:
# General function for compiling with cmake. # General function for compiling with cmake. All arguments are passed
# Automatically detects the build type. All arguments are passed to emake. # to cmake_build.
cmake_src_compile() { cmake_src_compile() {
debug-print-function ${FUNCNAME} "$@" debug-print-function ${FUNCNAME} "$@"
@ -549,7 +620,8 @@ cmake_src_compile() {
# @FUNCTION: cmake_build # @FUNCTION: cmake_build
# @DESCRIPTION: # @DESCRIPTION:
# Function for building the package. Automatically detects the build type. # Function for building the package. Automatically detects the build type.
# All arguments are passed to emake. # All arguments are passed to eninja (default) or emake depending on the value
# of CMAKE_MAKEFILE_GENERATOR.
cmake_build() { cmake_build() {
debug-print-function ${FUNCNAME} "$@" debug-print-function ${FUNCNAME} "$@"
@ -629,9 +701,17 @@ cmake_src_install() {
die "died running ${CMAKE_MAKEFILE_GENERATOR} install" die "died running ${CMAKE_MAKEFILE_GENERATOR} install"
popd > /dev/null || die popd > /dev/null || die
pushd "${S}" > /dev/null || die if [[ ${EAPI} == 7 ]]; then
einstalldocs pushd "${S}" > /dev/null || die
popd > /dev/null || die einstalldocs
popd > /dev/null || die
else
pushd "${CMAKE_USE_DIR}" > /dev/null || die
einstalldocs
popd > /dev/null || die
fi
} }
fi fi
EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install