2012-01-20 16:10:28 +01:00
|
|
|
|
addCMakeParams() {
|
2010-02-12 22:58:27 +01:00
|
|
|
|
addToSearchPath CMAKE_PREFIX_PATH $1
|
2007-08-05 15:54:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-20 16:10:28 +01:00
|
|
|
|
fixCmakeFiles() {
|
2012-01-23 14:16:51 +01:00
|
|
|
|
# Replace occurences of /usr and /opt by /var/empty.
|
2012-01-20 16:10:28 +01:00
|
|
|
|
echo "fixing cmake files..."
|
|
|
|
|
find "$1" \( -type f -name "*.cmake" -o -name "*.cmake.in" -o -name CMakeLists.txt \) -print |
|
|
|
|
|
while read fn; do
|
2012-01-23 14:16:51 +01:00
|
|
|
|
sed -e 's^/usr\([ /]\|$\)^/var/empty\1^g' -e 's^/opt\([ /]\|$\)^/var/empty\1^g' < "$fn" > "$fn.tmp"
|
2012-01-20 16:10:28 +01:00
|
|
|
|
mv "$fn.tmp" "$fn"
|
|
|
|
|
done
|
2007-08-05 15:54:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-01-20 16:10:28 +01:00
|
|
|
|
cmakeConfigurePhase() {
|
2016-01-24 19:18:56 +01:00
|
|
|
|
runHook preConfigure
|
2009-04-17 15:48:11 +02:00
|
|
|
|
|
2018-11-19 23:16:16 +01:00
|
|
|
|
export CTEST_OUTPUT_ON_FAILURE=1
|
2018-11-20 01:14:44 +01:00
|
|
|
|
if [ -n "${enableParallelChecking-1}" ]; then
|
|
|
|
|
export CTEST_PARALLEL_LEVEL=$NIX_BUILD_CORES
|
|
|
|
|
fi
|
2018-11-19 23:16:16 +01:00
|
|
|
|
|
2019-10-30 16:16:20 +01:00
|
|
|
|
if [ -z "${dontFixCmake-}" ]; then
|
2008-02-21 00:02:41 +01:00
|
|
|
|
fixCmakeFiles .
|
|
|
|
|
fi
|
|
|
|
|
|
2019-10-30 16:16:20 +01:00
|
|
|
|
if [ -z "${dontUseCmakeBuildDir-}" ]; then
|
2009-02-13 15:43:01 +01:00
|
|
|
|
mkdir -p build
|
|
|
|
|
cd build
|
2018-06-03 14:28:28 +02:00
|
|
|
|
cmakeDir=${cmakeDir:-..}
|
2008-02-21 00:02:41 +01:00
|
|
|
|
fi
|
2009-02-13 15:43:01 +01:00
|
|
|
|
|
2019-10-30 16:16:20 +01:00
|
|
|
|
if [ -z "${dontAddPrefix-}" ]; then
|
2009-02-13 15:43:01 +01:00
|
|
|
|
cmakeFlags="-DCMAKE_INSTALL_PREFIX=$prefix $cmakeFlags"
|
2008-02-21 00:02:41 +01:00
|
|
|
|
fi
|
2007-08-05 15:54:42 +02:00
|
|
|
|
|
2018-05-13 17:31:24 +02:00
|
|
|
|
# We should set the proper `CMAKE_SYSTEM_NAME`.
|
|
|
|
|
# http://www.cmake.org/Wiki/CMake_Cross_Compiling
|
|
|
|
|
#
|
|
|
|
|
# Unfortunately cmake seems to expect absolute paths for ar, ranlib, and
|
|
|
|
|
# strip. Otherwise they are taken to be relative to the source root of the
|
|
|
|
|
# package being built.
|
|
|
|
|
cmakeFlags="-DCMAKE_CXX_COMPILER=$CXX $cmakeFlags"
|
|
|
|
|
cmakeFlags="-DCMAKE_C_COMPILER=$CC $cmakeFlags"
|
|
|
|
|
cmakeFlags="-DCMAKE_AR=$(command -v $AR) $cmakeFlags"
|
2018-05-15 21:24:22 +02:00
|
|
|
|
cmakeFlags="-DCMAKE_RANLIB=$(command -v $RANLIB) $cmakeFlags"
|
2018-05-13 17:31:24 +02:00
|
|
|
|
cmakeFlags="-DCMAKE_STRIP=$(command -v $STRIP) $cmakeFlags"
|
Big fixes in the cross build:
- Before this changes, cflags and ldflags for the native and the cross compiler
got mixed. Not all the gcc-wrapper/gcc-cross-wrapper variables are
independant now, but enough, I think.
- Fixed the generic stdenv expression, which did a big mess on buildInputs and
buildNativeInputs. Now it distinguishes when there is a stdenvCross or not.
Maybe we should have a single stdenv and forget about the stdenvCross
adapter - this could end in a stdenv a bit complex, but simpler than the
generic stdenv + adapter.
- Added basic support in pkgconfig for cross-builds: a single PKG_CONFIG_PATH
now works for both the cross and the native compilers, but I think this
should work well for most cases I can think of.
- I tried to fix the guile expression to cross-biuld; guile is built, but not
its manual, so the derivation still fails. Guile requires patching to
cross-build, as far as I understnad.
- Made the glibcCross build to be done through the usage of a
gcc-cross-wrapper over the gcc-cross-stage-static, instead of using it
directly.
- Trying to make physfs (a neverball dependency) cross build.
- Updated the gcc expression to support building a cross compiler without getting
derivation variables mixed with those of the stdenvCross.
svn path=/nixpkgs/branches/stdenv-updates/; revision=18534
2009-11-22 20:51:45 +01:00
|
|
|
|
|
2018-03-14 20:20:07 +01:00
|
|
|
|
# on macOS we want to prefer Unix-style headers to Frameworks
|
|
|
|
|
# because we usually do not package the framework
|
|
|
|
|
cmakeFlags="-DCMAKE_FIND_FRAMEWORK=last $cmakeFlags"
|
|
|
|
|
|
2020-01-14 12:43:54 +01:00
|
|
|
|
# on macOS i686 was only relevant for 10.5 or earlier.
|
|
|
|
|
cmakeFlags="-DCMAKE_OSX_ARCHITECTURES=x86_64 $cmakeFlags"
|
|
|
|
|
|
2018-03-14 20:30:10 +01:00
|
|
|
|
# we never want to use the global macOS SDK
|
|
|
|
|
cmakeFlags="-DCMAKE_OSX_SYSROOT= $cmakeFlags"
|
|
|
|
|
|
2018-03-14 20:36:27 +01:00
|
|
|
|
# correctly detect our clang compiler
|
|
|
|
|
cmakeFlags="-DCMAKE_POLICY_DEFAULT_CMP0025=NEW $cmakeFlags"
|
|
|
|
|
|
2015-03-23 13:54:39 +01:00
|
|
|
|
# This installs shared libraries with a fully-specified install
|
|
|
|
|
# name. By default, cmake installs shared libraries with just the
|
|
|
|
|
# basename as the install name, which means that, on Darwin, they
|
|
|
|
|
# can only be found by an executable at runtime if the shared
|
|
|
|
|
# libraries are in a system path or in the same directory as the
|
|
|
|
|
# executable. This flag makes the shared library accessible from its
|
|
|
|
|
# nix/store directory.
|
2018-01-02 20:18:41 +01:00
|
|
|
|
cmakeFlags="-DCMAKE_INSTALL_NAME_DIR=${!outputLib}/lib $cmakeFlags"
|
2018-12-25 20:35:43 +01:00
|
|
|
|
|
|
|
|
|
# This ensures correct paths with multiple output derivations
|
|
|
|
|
# It requires the project to use variables from GNUInstallDirs module
|
|
|
|
|
# https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html
|
|
|
|
|
cmakeFlags="-DCMAKE_INSTALL_BINDIR=${!outputBin}/bin $cmakeFlags"
|
|
|
|
|
cmakeFlags="-DCMAKE_INSTALL_SBINDIR=${!outputBin}/sbin $cmakeFlags"
|
|
|
|
|
cmakeFlags="-DCMAKE_INSTALL_INCLUDEDIR=${!outputInclude}/include $cmakeFlags"
|
|
|
|
|
cmakeFlags="-DCMAKE_INSTALL_OLDINCLUDEDIR=${!outputInclude}/include $cmakeFlags"
|
|
|
|
|
cmakeFlags="-DCMAKE_INSTALL_MANDIR=${!outputMan}/share/man $cmakeFlags"
|
|
|
|
|
cmakeFlags="-DCMAKE_INSTALL_INFODIR=${!outputInfo}/share/info $cmakeFlags"
|
|
|
|
|
cmakeFlags="-DCMAKE_INSTALL_DOCDIR=${!outputDoc}/share/doc/${shareDocName} $cmakeFlags"
|
2016-04-20 03:36:03 +02:00
|
|
|
|
cmakeFlags="-DCMAKE_INSTALL_LIBDIR=${!outputLib}/lib $cmakeFlags"
|
2018-12-25 20:35:43 +01:00
|
|
|
|
cmakeFlags="-DCMAKE_INSTALL_LIBEXECDIR=${!outputLib}/libexec $cmakeFlags"
|
|
|
|
|
cmakeFlags="-DCMAKE_INSTALL_LOCALEDIR=${!outputLib}/share/locale $cmakeFlags"
|
2015-03-23 13:54:39 +01:00
|
|
|
|
|
2019-02-22 02:21:31 +01:00
|
|
|
|
# Don’t build tests when doCheck = false
|
2019-10-30 16:16:20 +01:00
|
|
|
|
if [ -z "${doCheck-}" ]; then
|
2019-02-22 02:21:31 +01:00
|
|
|
|
cmakeFlags="-DBUILD_TESTING=OFF $cmakeFlags"
|
|
|
|
|
fi
|
|
|
|
|
|
2009-12-10 23:19:52 +01:00
|
|
|
|
# Avoid cmake resetting the rpath of binaries, on make install
|
2012-02-26 12:27:45 +01:00
|
|
|
|
# And build always Release, to ensure optimisation flags
|
2017-05-10 15:31:54 +02:00
|
|
|
|
cmakeFlags="-DCMAKE_BUILD_TYPE=${cmakeBuildType:-Release} -DCMAKE_SKIP_BUILD_RPATH=ON $cmakeFlags"
|
2009-12-10 23:19:52 +01:00
|
|
|
|
|
2019-01-31 10:17:55 +01:00
|
|
|
|
# Disable user package registry to avoid potential side effects
|
|
|
|
|
# and unecessary attempts to access non-existent home folder
|
|
|
|
|
# https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html#disabling-the-package-registry
|
|
|
|
|
cmakeFlags="-DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON $cmakeFlags"
|
2019-11-26 21:45:58 +01:00
|
|
|
|
cmakeFlags="-DCMAKE_FIND_USE_PACKAGE_REGISTRY=OFF $cmakeFlags"
|
|
|
|
|
cmakeFlags="-DCMAKE_FIND_USE_SYSTEM_PACKAGE_REGISTRY=OFF $cmakeFlags"
|
2019-01-31 10:17:55 +01:00
|
|
|
|
|
2019-10-31 18:59:18 +01:00
|
|
|
|
if [ "${buildPhase-}" = ninjaBuildPhase ]; then
|
2017-12-03 08:49:00 +01:00
|
|
|
|
cmakeFlags="-GNinja $cmakeFlags"
|
|
|
|
|
fi
|
|
|
|
|
|
2009-02-13 15:43:01 +01:00
|
|
|
|
echo "cmake flags: $cmakeFlags ${cmakeFlagsArray[@]}"
|
2009-04-17 15:48:11 +02:00
|
|
|
|
|
2013-03-12 11:31:58 +01:00
|
|
|
|
cmake ${cmakeDir:-.} $cmakeFlags "${cmakeFlagsArray[@]}"
|
2009-04-17 15:48:11 +02:00
|
|
|
|
|
2017-12-02 07:20:07 +01:00
|
|
|
|
if ! [[ -v enableParallelBuilding ]]; then
|
|
|
|
|
enableParallelBuilding=1
|
|
|
|
|
echo "cmake: enabled parallel building"
|
|
|
|
|
fi
|
|
|
|
|
|
2016-01-24 19:18:56 +01:00
|
|
|
|
runHook postConfigure
|
2009-02-13 15:43:01 +01:00
|
|
|
|
}
|
2007-09-20 21:27:55 +02:00
|
|
|
|
|
2019-10-31 18:59:18 +01:00
|
|
|
|
if [ -z "${dontUseCmakeConfigure-}" -a -z "${configurePhase-}" ]; then
|
2016-01-24 19:20:39 +01:00
|
|
|
|
setOutputFlags=
|
2009-02-13 15:43:01 +01:00
|
|
|
|
configurePhase=cmakeConfigurePhase
|
|
|
|
|
fi
|
2007-08-05 15:54:42 +02:00
|
|
|
|
|
2017-08-11 00:22:07 +02:00
|
|
|
|
addEnvHooks "$targetOffset" addCMakeParams
|
2013-06-22 13:58:30 +02:00
|
|
|
|
|
2013-06-27 16:33:24 +02:00
|
|
|
|
makeCmakeFindLibs(){
|
2016-09-08 09:10:00 +02:00
|
|
|
|
isystem_seen=
|
2019-10-11 23:24:33 +02:00
|
|
|
|
iframework_seen=
|
2019-11-06 01:16:36 +01:00
|
|
|
|
for flag in ${NIX_CFLAGS_COMPILE-} ${NIX_LDFLAGS-}; do
|
2016-09-08 09:10:00 +02:00
|
|
|
|
if test -n "$isystem_seen" && test -d "$flag"; then
|
|
|
|
|
isystem_seen=
|
2019-11-05 15:55:39 +01:00
|
|
|
|
export CMAKE_INCLUDE_PATH="${CMAKE_INCLUDE_PATH-}${CMAKE_INCLUDE_PATH:+:}${flag}"
|
2019-10-11 23:24:33 +02:00
|
|
|
|
elif test -n "$iframework_seen" && test -d "$flag"; then
|
|
|
|
|
iframework_seen=
|
2019-11-05 15:55:39 +01:00
|
|
|
|
export CMAKE_FRAMEWORK_PATH="${CMAKE_FRAMEWORK_PATH-}${CMAKE_FRAMEWORK_PATH:+:}${flag}"
|
2016-09-08 09:10:00 +02:00
|
|
|
|
else
|
|
|
|
|
isystem_seen=
|
2019-10-11 23:24:33 +02:00
|
|
|
|
iframework_seen=
|
2016-09-08 09:10:00 +02:00
|
|
|
|
case $flag in
|
|
|
|
|
-I*)
|
2019-11-05 15:55:39 +01:00
|
|
|
|
export CMAKE_INCLUDE_PATH="${CMAKE_INCLUDE_PATH-}${CMAKE_INCLUDE_PATH:+:}${flag:2}"
|
2016-09-08 09:10:00 +02:00
|
|
|
|
;;
|
|
|
|
|
-L*)
|
2019-11-05 15:55:39 +01:00
|
|
|
|
export CMAKE_LIBRARY_PATH="${CMAKE_LIBRARY_PATH-}${CMAKE_LIBRARY_PATH:+:}${flag:2}"
|
2016-09-08 09:10:00 +02:00
|
|
|
|
;;
|
2017-10-21 09:27:09 +02:00
|
|
|
|
-F*)
|
2019-11-05 15:55:39 +01:00
|
|
|
|
export CMAKE_FRAMEWORK_PATH="${CMAKE_FRAMEWORK_PATH-}${CMAKE_FRAMEWORK_PATH:+:}${flag:2}"
|
2017-10-21 09:27:09 +02:00
|
|
|
|
;;
|
2016-09-08 09:10:00 +02:00
|
|
|
|
-isystem)
|
|
|
|
|
isystem_seen=1
|
|
|
|
|
;;
|
2019-10-11 23:24:33 +02:00
|
|
|
|
-iframework)
|
|
|
|
|
iframework_seen=1
|
|
|
|
|
;;
|
2016-09-08 09:10:00 +02:00
|
|
|
|
esac
|
|
|
|
|
fi
|
2013-06-22 13:58:30 +02:00
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# not using setupHook, because it could be a setupHook adding additional
|
|
|
|
|
# include flags to NIX_CFLAGS_COMPILE
|
2013-06-27 16:33:24 +02:00
|
|
|
|
postHooks+=(makeCmakeFindLibs)
|