xz: update to 5.6.2.
[void-pkg.git] / common / build-style / cmake.sh
blob124ed354eff6748482548a475a16f50f87d53f5e
2 # This helper is for templates using cmake.
4 do_configure() {
5 local cmake_args=
6 [ ! -d ${cmake_builddir:=build} ] && mkdir -p ${cmake_builddir}
7 cd ${cmake_builddir}
9 if [ -z "$CHROOT_READY" ]; then
10 cat >bootstrap.cmake <<_EOF
11 SET(CMAKE_SYSTEM_NAME Linux)
12 SET(CMAKE_SYSTEM_VERSION 1)
14 SET(CMAKE_C_COMPILER ${CC})
15 SET(CMAKE_CXX_COMPILER ${CXX})
17 SET(CMAKE_FIND_ROOT_PATH "${XBPS_MASTERDIR}/usr;${XBPS_MASTERDIR}")
19 SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
20 SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
21 _EOF
22 configure_args+=" -DCMAKE_TOOLCHAIN_FILE=bootstrap.cmake"
23 elif [ "$CROSS_BUILD" ]; then
24 case "$XBPS_TARGET_MACHINE" in
25 x86_64*) _CMAKE_SYSTEM_PROCESSOR=x86_64 ;;
26 i686*) _CMAKE_SYSTEM_PROCESSOR=x86 ;;
27 aarch64*) _CMAKE_SYSTEM_PROCESSOR=aarch64 ;;
28 arm*) _CMAKE_SYSTEM_PROCESSOR=arm ;;
29 mips*) _CMAKE_SYSTEM_PROCESSOR=mips ;;
30 ppc64le*) _CMAKE_SYSTEM_PROCESSOR=ppc64le ;;
31 ppc64*) _CMAKE_SYSTEM_PROCESSOR=ppc64 ;;
32 ppcle*) _CMAKE_SYSTEM_PROCESSOR=ppcle ;;
33 ppc*) _CMAKE_SYSTEM_PROCESSOR=ppc ;;
34 riscv64*) _CMAKE_SYSTEM_PROCESSOR=riscv64 ;;
35 *) _CMAKE_SYSTEM_PROCESSOR=generic ;;
36 esac
37 cat > cross_${XBPS_CROSS_TRIPLET}.cmake <<_EOF
38 SET(CMAKE_SYSTEM_NAME Linux)
39 SET(CMAKE_SYSTEM_VERSION 1)
41 SET(CMAKE_C_COMPILER ${CC})
42 SET(CMAKE_CXX_COMPILER ${CXX})
43 SET(Rust_CARGO_TARGET ${XBPS_CROSS_RUST_TARGET})
44 SET(CMAKE_CROSSCOMPILING TRUE)
46 SET(CMAKE_SYSTEM_PROCESSOR ${_CMAKE_SYSTEM_PROCESSOR})
48 SET(CMAKE_FIND_ROOT_PATH "${XBPS_CROSS_BASE}/usr;${XBPS_CROSS_BASE}")
50 SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
51 SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
52 SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
53 _EOF
54 cmake_args+=" -DCMAKE_TOOLCHAIN_FILE=${wrksrc}/${build_wrksrc}/${cmake_builddir}/cross_${XBPS_CROSS_TRIPLET}.cmake"
56 cmake_args+=" -DCMAKE_INSTALL_PREFIX:PATH=/usr"
57 cmake_args+=" -DCMAKE_BUILD_TYPE=None"
58 cmake_args+=" -DCMAKE_INSTALL_LIBDIR:PATH=lib${XBPS_TARGET_WORDSIZE}"
59 cmake_args+=" -DCMAKE_INSTALL_SYSCONFDIR:PATH=/etc"
61 if [ "$CROSS_BUILD" ]; then
62 cmake_args+=" -DQT_HOST_PATH=/usr"
63 # QT_HOST_PATH isn't enough in my system,
64 # which have binfmts support on and off
65 cmake_args+=" -DQT_HOST_PATH_CMAKE_DIR=/usr/lib/cmake"
68 if [[ $build_helper = *"qemu"* ]]; then
69 echo "SET(CMAKE_CROSSCOMPILING_EMULATOR /usr/bin/qemu-${XBPS_TARGET_QEMU_MACHINE}-static)" \
70 >> cross_${XBPS_CROSS_TRIPLET}.cmake
73 cmake_args+=" -DCMAKE_INSTALL_SBINDIR:PATH=bin"
75 export CMAKE_GENERATOR="${CMAKE_GENERATOR:-Ninja}"
76 # Remove -pipe: https://gitlab.kitware.com/cmake/cmake/issues/19590
77 CFLAGS="-DNDEBUG ${CFLAGS/ -pipe / }" CXXFLAGS="-DNDEBUG ${CXXFLAGS/ -pipe / }" \
78 cmake ${cmake_args} ${configure_args} \
79 ${LIBS:+-DCMAKE_C_STANDARD_LIBRARIES="$LIBS"} \
80 ${LIBS:+-DCMAKE_CXX_STANDARD_LIBRARIES="$LIBS"} \
81 ${wrksrc}/${build_wrksrc}
83 # Replace -isystem with -I
84 if [ "$CMAKE_GENERATOR" = "Unix Makefiles" ]; then
85 find . -name flags.make -exec sed -i -e 's/-isystem/-I/g' "{}" +
86 elif [ "$CMAKE_GENERATOR" = Ninja ]; then
87 sed -i -e 's/-isystem/-I/g' build.ninja
91 do_build() {
92 : ${make_cmd:=ninja}
94 cd ${cmake_builddir:=build}
95 ${make_cmd} ${makejobs} ${make_build_args} ${make_build_target}
98 do_check() {
99 : ${make_cmd:=ninja}
101 cd ${cmake_builddir:=build}
103 if [ -z "$make_check_target" ]; then
104 case $make_cmd in
105 make)
106 if make -q test 2>/dev/null; then
108 else
109 if [ $? -eq 2 ]; then
110 msg_warn 'No target to "make test".\n'
111 return 0
115 ninja)
116 if ! ninja -t query test >/dev/null 2>&1; then
117 msg_warn 'No target to "ninja test".\n'
118 return 0
122 msg_warn "Can't run tests with '$make_cmd', define do_check.\n"
124 esac
127 : ${make_check_target:=test}
129 ${make_check_pre} ${make_cmd} ${makejobs} ${make_check_args} ${make_check_target}
132 do_install() {
133 : ${make_cmd:=ninja}
134 : ${make_install_target:=install}
136 cd ${cmake_builddir:=build}
137 DESTDIR=${DESTDIR} ${make_cmd} ${make_install_args} ${make_install_target}