2017-01-02 14:18:57 +03:00
# Copyright 1999-2017 Gentoo Foundation
2011-11-09 11:33:19 +04:00
# Distributed under the terms of the GNU General Public License v2
# @ECLASS: cmake-utils.eclass
# @MAINTAINER:
# kde@gentoo.org
# @AUTHOR:
# Tomáš Chvátal <scarabeus@gentoo.org>
# Maciej Mrozowski <reavertm@gentoo.org>
# (undisclosed contributors)
# Original author: Zephyrus (zephyrus@mirach.it)
# @BLURB: common ebuild functions for cmake-based packages
# @DESCRIPTION:
2013-07-02 08:07:34 +04:00
# The cmake-utils eclass makes creating ebuilds for cmake-based packages much easier.
2011-11-09 11:33:19 +04:00
# It provides all inherited features (DOCS, HTML_DOCS, PATCHES) along with out-of-source
# builds (default), in-source builds and an implementation of the well-known use_enable
# and use_with functions for CMake.
2014-07-11 23:20:24 +04:00
if [ [ -z ${ _CMAKE_UTILS_ECLASS } ] ] ; then
_CMAKE_UTILS_ECLASS = 1
2013-04-08 04:43:17 +04:00
2014-08-13 18:55:29 +04:00
# @ECLASS-VARIABLE: BUILD_DIR
2011-11-09 11:33:19 +04:00
# @DESCRIPTION:
2014-08-13 18:55:29 +04:00
# Build directory where all cmake processed files should be generated.
# For in-source build it's fixed to ${CMAKE_USE_DIR}.
# For out-of-source build it can be overridden, by default it uses
# ${WORKDIR}/${P}_build.
#
# This variable has been called CMAKE_BUILD_DIR formerly.
# It is set under that name for compatibility.
# @ECLASS-VARIABLE: CMAKE_BINARY
# @DESCRIPTION:
# Eclass can use different cmake binary than the one provided in by system.
: ${ CMAKE_BINARY : =cmake }
# @ECLASS-VARIABLE: CMAKE_BUILD_TYPE
# @DESCRIPTION:
# Set to override default CMAKE_BUILD_TYPE. Only useful for packages
# known to make use of "if (CMAKE_BUILD_TYPE MATCHES xxx)".
# If about to be set - needs to be set before invoking cmake-utils_src_configure.
# You usualy do *NOT* want nor need to set it as it pulls CMake default build-type
# specific compiler flags overriding make.conf.
: ${ CMAKE_BUILD_TYPE : =Gentoo }
# @ECLASS-VARIABLE: CMAKE_IN_SOURCE_BUILD
# @DESCRIPTION:
# Set to enable in-source build.
# @ECLASS-VARIABLE: CMAKE_MAKEFILE_GENERATOR
# @DESCRIPTION:
# Specify a makefile generator to be used by cmake.
# At this point only "emake" and "ninja" are supported.
: ${ CMAKE_MAKEFILE_GENERATOR : =emake }
2011-11-09 11:33:19 +04:00
# @ECLASS-VARIABLE: CMAKE_MIN_VERSION
# @DESCRIPTION:
2013-02-09 21:04:21 +04:00
# Specify the minimum required CMake version.
2017-03-18 17:29:25 +03:00
: ${ CMAKE_MIN_VERSION : =3.7.2 }
2014-08-13 18:55:29 +04:00
# @ECLASS-VARIABLE: CMAKE_REMOVE_MODULES
# @DESCRIPTION:
# Do we want to remove anything? yes or whatever else for no
: ${ CMAKE_REMOVE_MODULES : =yes }
2011-11-09 11:33:19 +04:00
# @ECLASS-VARIABLE: CMAKE_REMOVE_MODULES_LIST
# @DESCRIPTION:
# Space-separated list of CMake modules that will be removed in $S during src_prepare,
# in order to force packages to use the system version.
2014-08-13 18:55:29 +04:00
: ${ CMAKE_REMOVE_MODULES_LIST : =FindBLAS FindLAPACK }
2011-11-09 11:33:19 +04:00
2014-08-13 18:55:29 +04:00
# @ECLASS-VARIABLE: CMAKE_USE_DIR
2011-11-09 11:33:19 +04:00
# @DESCRIPTION:
2014-08-13 18:55:29 +04:00
# 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.
# By default it uses ${S}.
2011-11-09 11:33:19 +04:00
2014-08-13 18:55:29 +04:00
# @ECLASS-VARIABLE: CMAKE_VERBOSE
2012-09-20 15:54:07 +04:00
# @DESCRIPTION:
2014-08-13 18:55:29 +04:00
# Set to OFF to disable verbose messages during compilation
: ${ CMAKE_VERBOSE : =ON }
2012-09-20 15:54:07 +04:00
2013-07-14 21:05:19 +04:00
# @ECLASS-VARIABLE: CMAKE_WARN_UNUSED_CLI
# @DESCRIPTION:
# Warn about variables that are declared on the command line
# but not used. Might give false-positives.
# "no" to disable (default) or anything else to enable.
2014-08-13 18:55:29 +04:00
2014-10-27 19:13:21 +03:00
# @ECLASS-VARIABLE: CMAKE_EXTRA_CACHE_FILE
# @DESCRIPTION:
# Specifies an extra cache file to pass to cmake. This is the analog of EXTRA_ECONF
# for econf and is needed to pass TRY_RUN results when cross-compiling.
# Should be set by user in a per-package basis in /etc/portage/package.env.
2013-07-14 21:05:19 +04:00
2016-01-26 08:39:27 +03:00
case ${ EAPI } in
2017-05-21 23:24:41 +03:00
5) : ${ CMAKE_WARN_UNUSED_CLI : =no } ; ;
2016-05-18 09:30:10 +03:00
6) : ${ CMAKE_WARN_UNUSED_CLI : =yes } ; ;
2016-01-26 08:39:27 +03:00
*) die " EAPI= ${ EAPI :- 0 } is not supported " ; ;
esac
2017-05-16 23:50:24 +03:00
inherit toolchain-funcs multilib ninja-utils flag-o-matic eutils \
multiprocessing versionator
2016-01-26 08:39:27 +03:00
EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install
2017-05-21 23:24:41 +03:00
[ [ ${ WANT_CMAKE } ] ] && eqawarn "\${WANT_CMAKE} has been removed and is a no-op now"
[ [ ${ PREFIX } ] ] && die "\${PREFIX} has been removed and is a no-op now"
2011-11-09 11:33:19 +04:00
2013-02-09 21:04:21 +04:00
case ${ CMAKE_MAKEFILE_GENERATOR } in
emake)
2017-05-21 23:24:41 +03:00
DEPEND = "sys-devel/make"
2013-02-09 21:04:21 +04:00
; ;
ninja)
2017-05-21 23:24:41 +03:00
DEPEND = "dev-util/ninja"
2013-02-09 21:04:21 +04:00
; ;
*)
eerror "Unknown value for \${CMAKE_MAKEFILE_GENERATOR}"
die " Value ${ CMAKE_MAKEFILE_GENERATOR } is not supported "
; ;
esac
2011-11-09 11:33:19 +04:00
if [ [ ${ PN } != cmake ] ] ; then
2017-05-21 23:24:41 +03:00
DEPEND += " >=dev-util/cmake- ${ CMAKE_MIN_VERSION } "
2011-11-09 11:33:19 +04:00
fi
# Internal functions used by cmake-utils_use_*
2016-01-26 08:39:27 +03:00
_cmake_use_me_now( ) {
2011-11-09 11:33:19 +04:00
debug-print-function ${ FUNCNAME } " $@ "
2016-01-26 08:39:27 +03:00
local arg = $2
[ [ ! -z $3 ] ] && arg = $3
2017-05-21 23:24:41 +03:00
[ [ ${ EAPI } = = 5 ] ] || die " ${ FUNCNAME [1] } is banned in EAPI 6 and later: use -D $1 <related_CMake_variable>=\"\$(usex $2 )\" instead "
2016-01-26 08:39:27 +03:00
2011-11-09 11:33:19 +04:00
local uper capitalised x
[ [ -z $2 ] ] && die " cmake-utils_use- $1 <USE flag> [<flag name>] "
if [ [ ! -z $3 ] ] ; then
# user specified the use name so use it
echo " -D $1 $3 = $( use $2 && echo ON || echo OFF) "
else
# use all various most used combinations
uper = $( echo ${ 2 } | tr '[:lower:]' '[:upper:]' )
capitalised = $( echo ${ 2 } | sed 's/\<\(.\)\([^ ]*\)/\u\1\L\2/g' )
for x in $2 $uper $capitalised ; do
echo " -D $1 $x = $( use $2 && echo ON || echo OFF) "
done
fi
}
2016-01-26 08:39:27 +03:00
_cmake_use_me_now_inverted( ) {
2011-11-09 11:33:19 +04:00
debug-print-function ${ FUNCNAME } " $@ "
2016-01-26 08:39:27 +03:00
local arg = $2
[ [ ! -z $3 ] ] && arg = $3
2017-05-21 23:24:41 +03:00
if [ [ ${ EAPI } != 5 && " ${ FUNCNAME [1] } " != cmake-utils_use_find_package ] ] ; then
2016-08-05 22:50:04 +03:00
die " ${ FUNCNAME [1] } is banned in EAPI 6 and later: use -D $1 <related_CMake_variable>=\"\$(usex $2 )\" instead "
2016-01-26 08:39:27 +03:00
fi
2011-11-09 11:33:19 +04:00
local uper capitalised x
[ [ -z $2 ] ] && die " cmake-utils_use- $1 <USE flag> [<flag name>] "
if [ [ ! -z $3 ] ] ; then
# user specified the use name so use it
echo " -D $1 $3 = $( use $2 && echo OFF || echo ON) "
else
# use all various most used combinations
uper = $( echo ${ 2 } | tr '[:lower:]' '[:upper:]' )
capitalised = $( echo ${ 2 } | sed 's/\<\(.\)\([^ ]*\)/\u\1\L\2/g' )
for x in $2 $uper $capitalised ; do
echo " -D $1 $x = $( use $2 && echo OFF || echo ON) "
done
fi
}
# Determine using IN or OUT source build
2016-01-26 08:39:27 +03:00
_cmake_check_build_dir( ) {
2011-11-09 11:33:19 +04:00
: ${ CMAKE_USE_DIR : = ${ S } }
if [ [ -n ${ CMAKE_IN_SOURCE_BUILD } ] ] ; then
# we build in source dir
2012-12-01 22:49:09 +04:00
BUILD_DIR = " ${ CMAKE_USE_DIR } "
2011-11-09 11:33:19 +04:00
else
2012-12-03 17:43:11 +04:00
# Respect both the old variable and the new one, depending
# on which one was set by the ebuild.
if [ [ ! ${ BUILD_DIR } && ${ CMAKE_BUILD_DIR } ] ] ; then
eqawarn "The CMAKE_BUILD_DIR variable has been renamed to BUILD_DIR."
eqawarn "Please migrate the ebuild to use the new one."
# In the next call, both variables will be set already
# and we'd have to know which one takes precedence.
_RESPECT_CMAKE_BUILD_DIR = 1
fi
if [ [ ${ _RESPECT_CMAKE_BUILD_DIR } ] ] ; then
BUILD_DIR = ${ CMAKE_BUILD_DIR :- ${ WORKDIR } / ${ P } _build }
else
: ${ BUILD_DIR : = ${ WORKDIR } / ${ P } _build }
fi
2011-11-09 11:33:19 +04:00
fi
2012-12-03 17:43:11 +04:00
# Backwards compatibility for getting the value.
2012-12-01 22:49:09 +04:00
CMAKE_BUILD_DIR = ${ BUILD_DIR }
2016-01-26 08:39:27 +03:00
mkdir -p " ${ BUILD_DIR } " || die
2012-12-01 22:49:09 +04:00
echo " >>> Working in BUILD_DIR: \" $BUILD_DIR \" "
2011-11-09 11:33:19 +04:00
}
2012-09-20 15:54:07 +04:00
# Determine which generator to use
2016-01-26 08:39:27 +03:00
_cmake_generator_to_use( ) {
2013-02-09 21:04:21 +04:00
local generator_name
case ${ CMAKE_MAKEFILE_GENERATOR } in
ninja)
2015-10-17 22:12:48 +03:00
# if ninja is enabled but not installed, the build could fail
# this could happen if ninja is manually enabled (eg. make.conf) but not installed
2016-04-03 00:47:04 +03:00
if ! ROOT = / has_version dev-util/ninja; then
2015-10-17 22:12:48 +03:00
die "CMAKE_MAKEFILE_GENERATOR is set to ninja, but ninja is not installed. Please install dev-util/ninja or unset CMAKE_MAKEFILE_GENERATOR."
fi
2013-02-09 21:04:21 +04:00
generator_name = "Ninja"
; ;
emake)
generator_name = "Unix Makefiles"
; ;
*)
eerror "Unknown value for \${CMAKE_MAKEFILE_GENERATOR}"
die " Value ${ CMAKE_MAKEFILE_GENERATOR } is not supported "
; ;
esac
echo ${ generator_name }
2012-09-20 15:54:07 +04:00
}
2016-01-26 08:39:27 +03:00
# @FUNCTION: cmake_comment_add_subdirectory
2014-10-15 23:19:12 +04:00
# @USAGE: <subdirectory>
# @DESCRIPTION:
2016-08-31 21:08:58 +03:00
# Comment out one or more add_subdirectory calls in CMakeLists.txt in the current directory
2016-01-26 08:39:27 +03:00
cmake_comment_add_subdirectory( ) {
2016-03-18 12:54:44 +03:00
if [ [ -z ${ 1 } ] ] ; then
2016-08-31 21:08:58 +03:00
die "comment_add_subdirectory must be passed at least one directory name to comment"
2016-03-18 12:54:44 +03:00
fi
if [ [ -e "CMakeLists.txt" ] ] ; then
2016-08-31 21:08:58 +03:00
local d
for d in $@ ; do
sed -e " /add_subdirectory[[:space:]]*([[:space:]]* ${ d // \/ / \\ / } [[:space:]]*)/I s/^/#DONOTCOMPILE / " \
-i CMakeLists.txt || die " failed to comment add_subdirectory( ${ d } ) "
done
2016-03-18 12:54:44 +03:00
fi
2014-10-15 23:19:12 +04:00
}
2016-01-26 08:39:27 +03:00
# @FUNCTION: comment_add_subdirectory
# @USAGE: <subdirectory>
# @DESCRIPTION:
# Comment out an add_subdirectory call in CMakeLists.txt in the current directory
# Banned in EAPI 6 and later - use cmake_comment_add_subdirectory instead.
comment_add_subdirectory( ) {
2017-05-21 23:24:41 +03:00
[ [ ${ EAPI } = = 5 ] ] || die "comment_add_subdirectory is banned in EAPI 6 and later - use cmake_comment_add_subdirectory instead"
2016-01-26 08:39:27 +03:00
cmake_comment_add_subdirectory " $@ "
}
2011-11-09 11:33:19 +04:00
# @FUNCTION: cmake-utils_use_with
# @USAGE: <USE flag> [flag name]
# @DESCRIPTION:
# Based on use_with. See ebuild(5).
#
# `cmake-utils_use_with foo FOO` echoes -DWITH_FOO=ON if foo is enabled
# and -DWITH_FOO=OFF if it is disabled.
2016-01-26 08:39:27 +03:00
cmake-utils_use_with( ) { _cmake_use_me_now WITH_ " $@ " ; }
2011-11-09 11:33:19 +04:00
# @FUNCTION: cmake-utils_use_enable
# @USAGE: <USE flag> [flag name]
# @DESCRIPTION:
# Based on use_enable. See ebuild(5).
#
# `cmake-utils_use_enable foo FOO` echoes -DENABLE_FOO=ON if foo is enabled
# and -DENABLE_FOO=OFF if it is disabled.
2016-01-26 08:39:27 +03:00
cmake-utils_use_enable( ) { _cmake_use_me_now ENABLE_ " $@ " ; }
2011-11-09 11:33:19 +04:00
2013-02-09 21:04:21 +04:00
# @FUNCTION: cmake-utils_use_find_package
2016-01-26 08:39:27 +03:00
# @USAGE: <USE flag> <package name>
2013-02-09 21:04:21 +04:00
# @DESCRIPTION:
# Based on use_enable. See ebuild(5).
#
2013-07-02 08:07:34 +04:00
# `cmake-utils_use_find_package foo LibFoo` echoes -DCMAKE_DISABLE_FIND_PACKAGE_LibFoo=OFF
# if foo is enabled and -DCMAKE_DISABLE_FIND_PACKAGE_LibFoo=ON if it is disabled.
2014-08-13 18:55:29 +04:00
# This can be used to make find_package optional.
2016-01-26 08:39:27 +03:00
cmake-utils_use_find_package( ) {
2017-05-21 23:24:41 +03:00
if [ [ ${ EAPI } != 5 && " $# " != 2 ] ] ; then
2016-01-26 08:39:27 +03:00
die "Usage: cmake-utils_use_find_package <USE flag> <package name>"
fi
_cmake_use_me_now_inverted CMAKE_DISABLE_FIND_PACKAGE_ " $@ " ;
}
2013-02-09 21:04:21 +04:00
2011-11-09 11:33:19 +04:00
# @FUNCTION: cmake-utils_use_disable
# @USAGE: <USE flag> [flag name]
# @DESCRIPTION:
# Based on inversion of use_enable. See ebuild(5).
#
# `cmake-utils_use_enable foo FOO` echoes -DDISABLE_FOO=OFF if foo is enabled
# and -DDISABLE_FOO=ON if it is disabled.
2016-01-26 08:39:27 +03:00
cmake-utils_use_disable( ) { _cmake_use_me_now_inverted DISABLE_ " $@ " ; }
2011-11-09 11:33:19 +04:00
# @FUNCTION: cmake-utils_use_no
# @USAGE: <USE flag> [flag name]
# @DESCRIPTION:
# Based on use_disable. See ebuild(5).
#
# `cmake-utils_use_no foo FOO` echoes -DNO_FOO=OFF if foo is enabled
# and -DNO_FOO=ON if it is disabled.
2016-01-26 08:39:27 +03:00
cmake-utils_use_no( ) { _cmake_use_me_now_inverted NO_ " $@ " ; }
2011-11-09 11:33:19 +04:00
# @FUNCTION: cmake-utils_use_want
# @USAGE: <USE flag> [flag name]
# @DESCRIPTION:
# Based on use_enable. See ebuild(5).
#
# `cmake-utils_use_want foo FOO` echoes -DWANT_FOO=ON if foo is enabled
# and -DWANT_FOO=OFF if it is disabled.
2016-01-26 08:39:27 +03:00
cmake-utils_use_want( ) { _cmake_use_me_now WANT_ " $@ " ; }
2011-11-09 11:33:19 +04:00
# @FUNCTION: cmake-utils_use_build
# @USAGE: <USE flag> [flag name]
# @DESCRIPTION:
# Based on use_enable. See ebuild(5).
#
# `cmake-utils_use_build foo FOO` echoes -DBUILD_FOO=ON if foo is enabled
# and -DBUILD_FOO=OFF if it is disabled.
2016-01-26 08:39:27 +03:00
cmake-utils_use_build( ) { _cmake_use_me_now BUILD_ " $@ " ; }
2011-11-09 11:33:19 +04:00
# @FUNCTION: cmake-utils_use_has
# @USAGE: <USE flag> [flag name]
# @DESCRIPTION:
# Based on use_enable. See ebuild(5).
#
# `cmake-utils_use_has foo FOO` echoes -DHAVE_FOO=ON if foo is enabled
# and -DHAVE_FOO=OFF if it is disabled.
2016-01-26 08:39:27 +03:00
cmake-utils_use_has( ) { _cmake_use_me_now HAVE_ " $@ " ; }
2011-11-09 11:33:19 +04:00
# @FUNCTION: cmake-utils_use_use
# @USAGE: <USE flag> [flag name]
# @DESCRIPTION:
# Based on use_enable. See ebuild(5).
#
# `cmake-utils_use_use foo FOO` echoes -DUSE_FOO=ON if foo is enabled
# and -DUSE_FOO=OFF if it is disabled.
2016-01-26 08:39:27 +03:00
cmake-utils_use_use( ) { _cmake_use_me_now USE_ " $@ " ; }
2011-11-09 11:33:19 +04:00
# @FUNCTION: cmake-utils_use
# @USAGE: <USE flag> [flag name]
# @DESCRIPTION:
# Based on use_enable. See ebuild(5).
#
# `cmake-utils_use foo FOO` echoes -DFOO=ON if foo is enabled
# and -DFOO=OFF if it is disabled.
2016-01-26 08:39:27 +03:00
cmake-utils_use( ) { _cmake_use_me_now "" " $@ " ; }
2011-11-09 11:33:19 +04:00
2013-12-26 11:28:15 +04:00
# @FUNCTION: cmake-utils_useno
# @USAGE: <USE flag> [flag name]
# @DESCRIPTION:
# Based on use_enable. See ebuild(5).
#
# `cmake-utils_useno foo NOFOO` echoes -DNOFOO=OFF if foo is enabled
# and -DNOFOO=ON if it is disabled.
2016-01-26 08:39:27 +03:00
cmake-utils_useno( ) { _cmake_use_me_now_inverted "" " $@ " ; }
2013-12-26 11:28:15 +04:00
2011-11-09 11:33:19 +04:00
# Internal function for modifying hardcoded definitions.
# Removes dangerous definitions that override Gentoo settings.
2016-01-26 08:39:27 +03:00
_cmake_modify-cmakelists( ) {
2011-11-09 11:33:19 +04:00
debug-print-function ${ FUNCNAME } " $@ "
# Only edit the files once
2012-10-25 20:53:04 +04:00
grep -qs "<<< Gentoo configuration >>>" " ${ CMAKE_USE_DIR } " /CMakeLists.txt && return 0
2011-11-09 11:33:19 +04:00
# Comment out all set (<some_should_be_user_defined_variable> value)
# TODO Add QA checker - inform when variable being checked for below is set in CMakeLists.txt
find " ${ CMAKE_USE_DIR } " -name CMakeLists.txt \
-exec sed -i -e '/^[[:space:]]*[sS][eE][tT][[:space:]]*([[:space:]]*CMAKE_BUILD_TYPE.*)/{s/^/#IGNORE /g}' { } + \
-exec sed -i -e '/^[[:space:]]*[sS][eE][tT][[:space:]]*([[:space:]]*CMAKE_COLOR_MAKEFILE.*)/{s/^/#IGNORE /g}' { } + \
-exec sed -i -e '/^[[:space:]]*[sS][eE][tT][[:space:]]*([[:space:]]*CMAKE_INSTALL_PREFIX.*)/{s/^/#IGNORE /g}' { } + \
-exec sed -i -e '/^[[:space:]]*[sS][eE][tT][[:space:]]*([[:space:]]*CMAKE_VERBOSE_MAKEFILE.*)/{s/^/#IGNORE /g}' { } + \
|| die " ${ LINENO } : failed to disable hardcoded settings "
# NOTE Append some useful summary here
2015-10-15 17:09:34 +03:00
cat >> " ${ CMAKE_USE_DIR } " /CMakeLists.txt <<- _EOF_ || die
2011-11-09 11:33:19 +04:00
MESSAGE( STATUS " <<< Gentoo configuration >>>
Build type \$ { CMAKE_BUILD_TYPE}
Install path \$ { CMAKE_INSTALL_PREFIX}
Compiler flags:
C \$ { CMAKE_C_FLAGS}
C++ \$ { CMAKE_CXX_FLAGS}
Linker flags:
Executable \$ { CMAKE_EXE_LINKER_FLAGS}
Module \$ { CMAKE_MODULE_LINKER_FLAGS}
Shared \$ { CMAKE_SHARED_LINKER_FLAGS} \n " )
_EOF_
}
2016-01-26 08:39:27 +03:00
# temporary function for moving cmake cleanups from from src_configure -> src_prepare.
# bug #378850
_cmake_cleanup_cmake( ) {
: ${ CMAKE_USE_DIR : = ${ S } }
if [ [ " ${ CMAKE_REMOVE_MODULES } " = = "yes" ] ] ; then
local name
for name in ${ CMAKE_REMOVE_MODULES_LIST } ; do
find " ${ S } " -name ${ name } .cmake -exec rm -v { } + || die
done
fi
# check if CMakeLists.txt exist and if no then die
if [ [ ! -e ${ CMAKE_USE_DIR } /CMakeLists.txt ] ] ; then
eerror "Unable to locate CMakeLists.txt under:"
eerror " \" ${ CMAKE_USE_DIR } /CMakeLists.txt\" "
eerror "Consider not inheriting the cmake eclass."
die "FATAL: Unable to find CMakeLists.txt"
fi
# Remove dangerous things.
_cmake_modify-cmakelists
}
2013-02-09 21:04:21 +04:00
enable_cmake-utils_src_prepare( ) {
debug-print-function ${ FUNCNAME } " $@ "
2015-10-26 22:20:41 +03:00
pushd " ${ S } " > /dev/null || die
2013-07-02 08:07:34 +04:00
2017-05-21 23:24:41 +03:00
if [ [ ${ EAPI } != 5 ] ] ; then
2016-01-26 08:39:27 +03:00
default_src_prepare
_cmake_cleanup_cmake
else
debug-print " $FUNCNAME : PATCHES= $PATCHES "
[ [ ${ PATCHES [@] } ] ] && epatch " ${ PATCHES [@] } "
2015-10-26 22:20:41 +03:00
2016-01-26 08:39:27 +03:00
debug-print " $FUNCNAME : applying user patches "
epatch_user
fi
2013-07-02 08:07:34 +04:00
2015-10-26 22:20:41 +03:00
popd > /dev/null || die
2013-02-09 21:04:21 +04:00
}
2013-06-14 09:25:40 +04:00
# @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-utils_use_with openconnect)
# )
2014-08-13 18:55:29 +04:00
#
2013-06-14 09:25:40 +04:00
# cmake-utils_src_configure
# }
2014-08-13 18:55:29 +04:00
# @CODE
2013-06-14 09:25:40 +04:00
2011-11-09 11:33:19 +04:00
enable_cmake-utils_src_configure( ) {
debug-print-function ${ FUNCNAME } " $@ "
2017-05-21 23:24:41 +03:00
[ [ ${ EAPI } = = 5 ] ] && _cmake_cleanup_cmake
2011-11-09 11:33:19 +04:00
2016-01-26 08:39:27 +03:00
_cmake_check_build_dir
2011-11-09 11:33:19 +04:00
# Fix xdg collision with sandbox
2016-01-26 08:39:27 +03:00
local -x XDG_CONFIG_HOME = " ${ T } "
2011-11-09 11:33:19 +04:00
# @SEE CMAKE_BUILD_TYPE
if [ [ ${ CMAKE_BUILD_TYPE } = Gentoo ] ] ; then
# Handle release builds
if ! has debug ${ IUSE //+ } || ! use debug; then
2014-12-20 01:20:36 +03:00
local CPPFLAGS = ${ CPPFLAGS }
2011-11-09 11:33:19 +04:00
append-cppflags -DNDEBUG
fi
fi
2012-10-18 10:07:05 +04:00
# Prepare Gentoo override rules (set valid compiler, append CPPFLAGS etc.)
2012-12-01 22:49:09 +04:00
local build_rules = ${ BUILD_DIR } /gentoo_rules.cmake
2015-11-05 09:25:41 +03:00
# Since cmake-3.4.0_rc1 "<FLAGS>" no longer contains includes and thus
# we need to add "<INCLUDES>"
local includes =
if [ [ ${ PN } = = cmake ] ] ; then
if $( version_is_at_least 3.4.0 $( get_version_component_range 1-3 ${ PV } ) ) ; then
includes = "<INCLUDES>"
fi
2015-12-10 09:47:20 +03:00
elif ROOT = / has_version \> = dev-util/cmake-3.4.0_rc1 ; then
2015-11-05 09:25:41 +03:00
includes = "<INCLUDES>"
fi
2015-10-15 17:09:34 +03:00
cat > " ${ build_rules } " <<- _EOF_ || die
2016-12-08 12:02:15 +03:00
SET ( CMAKE_ASM_COMPILE_OBJECT " <CMAKE_ASM_COMPILER> <DEFINES> ${ includes } ${ CPPFLAGS } <FLAGS> -o <OBJECT> -c <SOURCE> " CACHE STRING "ASM compile command" FORCE)
2015-11-05 09:25:41 +03:00
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_Fortran_COMPILE_OBJECT " <CMAKE_Fortran_COMPILER> <DEFINES> ${ includes } ${ FCFLAGS } <FLAGS> -o <OBJECT> -c <SOURCE> " CACHE STRING "Fortran compile command" FORCE)
2011-11-09 11:33:19 +04:00
_EOF_
2016-12-08 12:02:15 +03:00
local myCC = $( tc-getCC) myCXX = $( tc-getCXX) myFC = $( tc-getFC)
# !!! IMPORTANT NOTE !!!
# Single slash below is intentional. CMake is weird and wants the
# CMAKE_*_VARIABLES split into two elements: the first one with
# compiler path, and the second one with all command-line options,
# space separated.
2014-10-27 19:13:21 +03:00
local toolchain_file = ${ BUILD_DIR } /gentoo_toolchain.cmake
2015-10-15 17:09:34 +03:00
cat > ${ toolchain_file } <<- _EOF_ || die
2016-12-08 12:02:15 +03:00
SET ( CMAKE_ASM_COMPILER " ${ myCC / /; } " )
SET ( CMAKE_C_COMPILER " ${ myCC / /; } " )
SET ( CMAKE_CXX_COMPILER " ${ myCXX / /; } " )
SET ( CMAKE_Fortran_COMPILER " ${ myFC / /; } " )
2016-11-27 18:07:50 +03:00
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)
2017-02-07 12:44:31 +03:00
SET ( CMAKE_SYSTEM_PROCESSOR " ${ CHOST %%-* } " )
2014-10-27 19:13:21 +03:00
_EOF_
2016-12-08 12:02:15 +03:00
# We are using the C compiler for assembly by default.
local -x ASMFLAGS = ${ CFLAGS }
2016-11-27 18:07:50 +03:00
local -x PKG_CONFIG = $( tc-getPKG_CONFIG)
2014-10-27 19:13:21 +03:00
if tc-is-cross-compiler; then
local sysname
case " ${ KERNEL :- linux } " in
Cygwin) sysname = "CYGWIN_NT-5.1" ; ;
HPUX) sysname = "HP-UX" ; ;
linux) sysname = "Linux" ; ;
2015-10-15 17:09:34 +03:00
Winnt)
sysname = "Windows"
cat >> " ${ toolchain_file } " <<- _EOF_ || die
SET ( CMAKE_RC_COMPILER $( tc-getRC) )
_EOF_
; ;
2014-10-27 19:13:21 +03:00
*) sysname = " ${ KERNEL } " ; ;
esac
2015-10-15 17:09:34 +03:00
cat >> " ${ toolchain_file } " <<- _EOF_ || die
2014-10-27 19:13:21 +03:00
SET ( CMAKE_SYSTEM_NAME " ${ sysname } " )
_EOF_
if [ " ${ SYSROOT :- / } " != "/" ] ; then
# 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.
2015-10-15 17:09:34 +03:00
cat >> " ${ toolchain_file } " <<- _EOF_ || die
2014-10-27 19:13:21 +03:00
set( CMAKE_FIND_ROOT_PATH " ${ SYSROOT } " )
set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
_EOF_
fi
fi
2011-11-09 11:33:19 +04:00
if [ [ ${ EPREFIX } ] ] ; then
2015-10-15 17:09:34 +03:00
cat >> " ${ build_rules } " <<- _EOF_ || die
2011-11-09 11:33:19 +04:00
# in Prefix we need rpath and must ensure cmake gets our default linker path
# right ... except for Darwin hosts
IF ( NOT APPLE)
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) "
CACHE STRING "" FORCE)
ELSE ( )
2017-05-21 23:24:41 +03:00
SET( CMAKE_PREFIX_PATH " ${ EPREFIX } /usr " CACHE STRING "" FORCE)
2011-11-09 11:33:19 +04:00
SET( CMAKE_SKIP_BUILD_RPATH OFF CACHE BOOL "" FORCE)
SET( CMAKE_SKIP_RPATH OFF CACHE BOOL "" FORCE)
2012-02-08 10:13:10 +04:00
SET( CMAKE_BUILD_WITH_INSTALL_RPATH TRUE CACHE BOOL "" )
2017-05-21 23:24:41 +03:00
SET( CMAKE_INSTALL_RPATH " ${ EPREFIX } /usr/lib; ${ EPREFIX } /usr/ ${ CHOST } /lib/gcc; ${ EPREFIX } /usr/ ${ CHOST } /lib; ${ EPREFIX } /usr/ $( get_libdir) ; ${ EPREFIX } / $( get_libdir) " CACHE STRING "" FORCE)
2011-11-09 11:33:19 +04:00
SET( CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE CACHE BOOL "" FORCE)
2017-05-21 23:24:41 +03:00
SET( CMAKE_INSTALL_NAME_DIR " ${ EPREFIX } /usr/lib " CACHE STRING "" FORCE)
2011-11-09 11:33:19 +04:00
ENDIF ( NOT APPLE)
_EOF_
fi
# Common configure parameters (invariants)
2012-12-01 22:49:09 +04:00
local common_config = ${ BUILD_DIR } /gentoo_common_config.cmake
2011-11-09 11:33:19 +04:00
local libdir = $( get_libdir)
2015-10-15 17:09:34 +03:00
cat > " ${ common_config } " <<- _EOF_ || die
2016-11-30 14:14:23 +03:00
SET ( CMAKE_GENTOO_BUILD ON CACHE BOOL "Indicate Gentoo package build" )
2011-11-09 11:33:19 +04:00
SET ( LIB_SUFFIX ${ libdir /lib } CACHE STRING "library path suffix" FORCE)
2012-09-20 15:54:07 +04:00
SET ( CMAKE_INSTALL_LIBDIR ${ libdir } CACHE PATH "Output directory for libraries" )
2011-11-09 11:33:19 +04:00
_EOF_
[ [ " ${ NOCOLOR } " = true || " ${ NOCOLOR } " = yes ] ] && echo 'SET (CMAKE_COLOR_MAKEFILE OFF CACHE BOOL "pretty colors during make" FORCE)' >> " ${ common_config } "
2016-11-30 14:14:23 +03:00
# Wipe the default optimization flags out of CMake
2017-05-21 23:24:41 +03:00
if [ [ ${ CMAKE_BUILD_TYPE } != Gentoo && ${ EAPI } != 5 ] ] ; then
2016-11-30 14:14:23 +03:00
cat >> ${ common_config } <<- _EOF_ || die
2016-12-02 09:42:25 +03:00
SET ( CMAKE_ASM_FLAGS_${ CMAKE_BUILD_TYPE ^^ } "" CACHE STRING "" )
2016-11-30 14:14:23 +03:00
SET ( CMAKE_C_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_EXE_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_STATIC_LINKER_FLAGS_${ CMAKE_BUILD_TYPE ^^ } "" CACHE STRING "" )
_EOF_
fi
2011-11-09 11:33:19 +04:00
# Convert mycmakeargs to an array, for backwards compatibility
# Make the array a local variable since <=portage-2.1.6.x does not
# support global arrays (see bug #297255).
2015-12-16 00:36:24 +03:00
local mycmakeargstype = $( declare -p mycmakeargs 2>& -)
if [ [ " ${ mycmakeargstype } " != "declare -a mycmakeargs=" * ] ] ; then
if [ [ -n " ${ mycmakeargstype } " ] ] ; then
2017-05-21 23:24:41 +03:00
if [ [ ${ EAPI } = = 5 ] ] ; then
2016-01-26 08:39:27 +03:00
eqawarn "Declaring mycmakeargs as a variable is deprecated. Please use an array instead."
else
die " Declaring mycmakeargs as a variable is banned in EAPI= ${ EAPI } . Please use an array instead. "
fi
2015-12-16 00:36:24 +03:00
fi
2011-11-09 11:33:19 +04:00
local mycmakeargs_local = ( ${ mycmakeargs } )
else
local mycmakeargs_local = ( " ${ mycmakeargs [@] } " )
fi
2013-07-14 21:05:19 +04:00
if [ [ ${ CMAKE_WARN_UNUSED_CLI } = = no ] ] ; then
local warn_unused_cli = "--no-warn-unused-cli"
else
local warn_unused_cli = ""
fi
2011-11-09 11:33:19 +04:00
# Common configure parameters (overridable)
# NOTE CMAKE_BUILD_TYPE can be only overriden via CMAKE_BUILD_TYPE eclass variable
# No -DCMAKE_BUILD_TYPE=xxx definitions will be in effect.
local cmakeargs = (
2013-07-14 21:05:19 +04:00
${ warn_unused_cli }
2011-11-09 11:33:19 +04:00
-C " ${ common_config } "
2016-01-26 08:39:27 +03:00
-G " $( _cmake_generator_to_use) "
2017-05-21 23:24:41 +03:00
-DCMAKE_INSTALL_PREFIX= " ${ EPREFIX } /usr "
2011-11-09 11:33:19 +04:00
" ${ mycmakeargs_local [@] } "
-DCMAKE_BUILD_TYPE= " ${ CMAKE_BUILD_TYPE } "
2017-05-21 23:24:41 +03:00
$( [ [ ${ EAPI } = = 5 ] ] && echo -DCMAKE_INSTALL_DO_STRIP= OFF)
2011-11-09 11:33:19 +04:00
-DCMAKE_USER_MAKE_RULES_OVERRIDE= " ${ build_rules } "
2014-10-27 19:13:21 +03:00
-DCMAKE_TOOLCHAIN_FILE= " ${ toolchain_file } "
2011-11-09 11:33:19 +04:00
" ${ MYCMAKEARGS } "
)
2014-10-27 19:13:21 +03:00
if [ [ -n " ${ CMAKE_EXTRA_CACHE_FILE } " ] ] ; then
cmakeargs += ( -C " ${ CMAKE_EXTRA_CACHE_FILE } " )
fi
2015-10-26 22:20:41 +03:00
pushd " ${ BUILD_DIR } " > /dev/null || die
2011-11-09 11:33:19 +04:00
debug-print " ${ LINENO } ${ ECLASS } ${ FUNCNAME } : mycmakeargs is ${ mycmakeargs_local [*] } "
echo " ${ CMAKE_BINARY } " " ${ cmakeargs [@] } " " ${ CMAKE_USE_DIR } "
" ${ CMAKE_BINARY } " " ${ cmakeargs [@] } " " ${ CMAKE_USE_DIR } " || die "cmake failed"
2015-10-26 22:20:41 +03:00
popd > /dev/null || die
2011-11-09 11:33:19 +04:00
}
enable_cmake-utils_src_compile( ) {
debug-print-function ${ FUNCNAME } " $@ "
cmake-utils_src_make " $@ "
}
2016-01-26 08:39:27 +03:00
# @FUNCTION: _cmake_ninja_src_make
2013-02-09 21:04:21 +04:00
# @INTERNAL
2011-11-09 11:33:19 +04:00
# @DESCRIPTION:
2013-02-09 21:04:21 +04:00
# Build the package using ninja generator
2016-01-26 08:39:27 +03:00
_cmake_ninja_src_make( ) {
2011-11-09 11:33:19 +04:00
debug-print-function ${ FUNCNAME } " $@ "
2014-01-25 18:12:55 +04:00
[ [ -e build.ninja ] ] || die "build.ninja not found. Error during configure stage."
2017-05-16 23:50:24 +03:00
eninja " $@ "
2013-02-09 21:04:21 +04:00
}
2016-01-26 08:39:27 +03:00
# @FUNCTION: _cmake_emake_src_make
2013-02-09 21:04:21 +04:00
# @INTERNAL
# @DESCRIPTION:
# Build the package using make generator
2016-01-26 08:39:27 +03:00
_cmake_emake_src_make( ) {
2013-02-09 21:04:21 +04:00
debug-print-function ${ FUNCNAME } " $@ "
2014-01-25 18:12:55 +04:00
[ [ -e Makefile ] ] || die "Makefile not found. Error during configure stage."
2013-02-09 21:04:21 +04:00
2014-01-25 18:12:55 +04:00
if [ [ " ${ CMAKE_VERBOSE } " != "OFF" ] ] ; then
2013-02-09 21:04:21 +04:00
emake VERBOSE = 1 " $@ " || die
2014-01-25 18:12:55 +04:00
else
2013-02-09 21:04:21 +04:00
emake " $@ " || die
2011-11-09 11:33:19 +04:00
fi
2013-02-09 21:04:21 +04:00
}
# @FUNCTION: cmake-utils_src_make
# @DESCRIPTION:
# Function for building the package. Automatically detects the build type.
# All arguments are passed to emake.
cmake-utils_src_make( ) {
debug-print-function ${ FUNCNAME } " $@ "
2016-01-26 08:39:27 +03:00
_cmake_check_build_dir
2015-10-26 22:20:41 +03:00
pushd " ${ BUILD_DIR } " > /dev/null || die
2013-02-09 21:04:21 +04:00
2016-01-26 08:39:27 +03:00
_cmake_${ CMAKE_MAKEFILE_GENERATOR } _src_make " $@ "
2013-02-09 21:04:21 +04:00
2015-10-26 22:20:41 +03:00
popd > /dev/null || die
2011-11-09 11:33:19 +04:00
}
enable_cmake-utils_src_test( ) {
debug-print-function ${ FUNCNAME } " $@ "
2016-01-26 08:39:27 +03:00
_cmake_check_build_dir
2015-10-26 22:20:41 +03:00
pushd " ${ BUILD_DIR } " > /dev/null || die
2011-11-09 11:33:19 +04:00
[ [ -e CTestTestfile.cmake ] ] || { echo "No tests found. Skipping." ; return 0 ; }
2012-12-09 22:34:53 +04:00
[ [ -n ${ TEST_VERBOSE } ] ] && myctestargs += ( --extra-verbose --output-on-failure )
2011-11-09 11:33:19 +04:00
2017-01-07 22:19:54 +03:00
set -- ctest -j " $( makeopts_jobs) " --test-load " $( makeopts_loadavg) " " ${ myctestargs [@] } " " $@ "
echo " $@ " >& 2
if " $@ " ; then
2011-11-09 11:33:19 +04:00
einfo "Tests succeeded."
2015-10-26 22:20:41 +03:00
popd > /dev/null || die
2012-10-02 14:50:28 +04:00
return 0
2011-11-09 11:33:19 +04:00
else
if [ [ -n " ${ CMAKE_YES_I_WANT_TO_SEE_THE_TEST_LOG } " ] ] ; then
# on request from Diego
2012-12-01 22:49:09 +04:00
eerror " Tests failed. Test log ${ BUILD_DIR } /Testing/Temporary/LastTest.log follows: "
2011-11-09 11:33:19 +04:00
eerror "--START TEST LOG--------------------------------------------------------------"
2012-12-01 22:49:09 +04:00
cat " ${ BUILD_DIR } /Testing/Temporary/LastTest.log "
2011-11-09 11:33:19 +04:00
eerror "--END TEST LOG----------------------------------------------------------------"
die "Tests failed."
else
2012-12-01 22:49:09 +04:00
die " Tests failed. When you file a bug, please attach the following file: \n\t ${ BUILD_DIR } /Testing/Temporary/LastTest.log "
2011-11-09 11:33:19 +04:00
fi
2012-10-02 14:50:28 +04:00
# die might not die due to nonfatal
2015-10-26 22:20:41 +03:00
popd > /dev/null || die
2012-10-02 14:50:28 +04:00
return 1
2011-11-09 11:33:19 +04:00
fi
}
2014-08-13 18:55:29 +04:00
enable_cmake-utils_src_install( ) {
debug-print-function ${ FUNCNAME } " $@ "
2016-01-26 08:39:27 +03:00
_cmake_check_build_dir
2015-10-26 22:20:41 +03:00
pushd " ${ BUILD_DIR } " > /dev/null || die
2014-08-13 18:55:29 +04:00
DESTDIR = " ${ D } " ${ CMAKE_MAKEFILE_GENERATOR } install " $@ " || die " died running ${ CMAKE_MAKEFILE_GENERATOR } install "
2015-10-26 22:20:41 +03:00
popd > /dev/null || die
2014-08-13 18:55:29 +04:00
2015-10-26 22:20:41 +03:00
pushd " ${ S } " > /dev/null || die
2014-08-13 18:55:29 +04:00
einstalldocs
2015-10-26 22:20:41 +03:00
popd > /dev/null || die
2014-08-13 18:55:29 +04:00
}
2013-02-09 21:04:21 +04:00
# @FUNCTION: cmake-utils_src_prepare
# @DESCRIPTION:
2013-07-03 01:18:45 +04:00
# Apply ebuild and user patches.
2013-02-09 21:04:21 +04:00
cmake-utils_src_prepare( ) {
2017-05-21 23:24:41 +03:00
enable_cmake-utils_src_prepare " $@ "
2013-02-09 21:04:21 +04:00
}
2011-11-09 11:33:19 +04:00
# @FUNCTION: cmake-utils_src_configure
# @DESCRIPTION:
# General function for configuring with cmake. Default behaviour is to start an
# out-of-source build.
cmake-utils_src_configure( ) {
2017-05-21 23:24:41 +03:00
enable_cmake-utils_src_configure " $@ "
2011-11-09 11:33:19 +04:00
}
# @FUNCTION: cmake-utils_src_compile
# @DESCRIPTION:
2014-08-13 18:55:29 +04:00
# General function for compiling with cmake.
2011-11-09 11:33:19 +04:00
# Automatically detects the build type. All arguments are passed to emake.
cmake-utils_src_compile( ) {
2017-05-21 23:24:41 +03:00
enable_cmake-utils_src_compile " $@ "
2011-11-09 11:33:19 +04:00
}
# @FUNCTION: cmake-utils_src_test
# @DESCRIPTION:
# Function for testing the package. Automatically detects the build type.
cmake-utils_src_test( ) {
2017-05-21 23:24:41 +03:00
enable_cmake-utils_src_test " $@ "
2011-11-09 11:33:19 +04:00
}
2014-08-13 18:55:29 +04:00
# @FUNCTION: cmake-utils_src_install
# @DESCRIPTION:
# Function for installing the package. Automatically detects the build type.
cmake-utils_src_install( ) {
2017-05-21 23:24:41 +03:00
enable_cmake-utils_src_install " $@ "
2011-11-09 11:33:19 +04:00
}
2013-04-08 04:43:17 +04:00
fi