1 ################################################################################
3 # cmake.cygclass - functions for building CMake-based packages
5 # Part of cygport - Cygwin packaging application
6 # Copyright (C) 2006-2020 Cygport authors
7 # Provided by the Cygwin project <https://cygwin.com/>
9 # cygport is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
14 # cygport is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with cygport. If not, see <https://www.gnu.org/licenses/>.
22 ################################################################################
24 #****h* Cygclasses/cmake.cygclass
28 # CMake is a build system which can be used instead of autoconf and automake.
29 # The build configuration and commands are written as CMakeLists.txt files
30 # in each directory, which cmake uses to run configuration tests and create
31 # Makefiles, config headers, and other files.
33 # CMake can be used for a wide variety of software, but is most commonly
34 # used in KDE and some Qt-based packages.
38 # kde4.cygclass, kf5-cygclass, qt4-cmake.cygclass
46 # FIXME: do binutils/gcc really support all these?
48 *-ibm-aix*) cmsys="AIX" ;;
49 *-*-beos*) cmsys="BeOS" ;;
50 *-*-bsdi*) cmsys="BSDOS" ;;
51 *-ibm-cnk*) cmsys="BlueGeneL" ;;
52 *-cray-unicos*) cmsys="Catamount" ;;
53 *-*-cygwin*) cmsys="CYGWIN" ;;
54 *-*-darwin*) cmsys="Darwin" ;;
55 *-*-dragonfly*) cmsys="DragonFly" ;;
56 *-*-freebsd*) cmsys="FreeBSD" ;;
57 *-*-haiku*) cmsys="Haiku" ;;
58 *-*-hpux*) cmsys="HP-UX" ;;
59 *-*-irix6*) cmsys="IRIX64" ;;
60 *-*-irix*) cmsys="IRIX" ;;
61 *-*-kfreebsd*) cmsys="kFreeBSD" ;;
62 *-*-linux*) cmsys="Linux" ;;
63 *-ncr-sysv*) cmsys="MP-RAS" ;;
64 *-*-netbsd*) cmsys="NetBSD" ;;
65 *-*-openbsd*) cmsys="OpenBSD" ;;
66 *-dec-vms*) cmsys="OpenVMS" ;;
67 *-*-osf*) cmsys="OSF1" ;;
68 *-*-nto-qnx*) cmsys="QNX" ;;
69 *-*-riscos*) cmsys="RISCos" ;;
70 *-*-sco*) cmsys="SCO_SV" ;;
71 *-sni-sysv*) cmsys="SINIX" ;;
72 *-*-solaris*) cmsys="SunOS" ;;
73 *-*-ultrix*) cmsys="ULTRIX" ;;
74 *-*-sysv4.2uw*) cmsys="UnixWare" ;;
75 *-*-mingw*) cmsys="Windows" ;;
76 *-*-xenix*) cmsys="Xenix" ;;
77 # must be last to avoid false positives from *-*-KERNEL-gnu
78 *-*-gnu*) cmsys="GNU" ;;
79 *) error "Host ${CHOST} is not supported by CMake" ;;
85 #****C* cmake.cygclass/cygcmake
89 # Runs cmake to configure the package. cygcmake passes cmake the flags
90 # necessary to install the package into the standard prefix and according to the
91 # |html <a href="https://www.pathname.com/fhs/">Filesystem Hierarchy Standard</a> and the
92 # |html <a href="https://cygwin.com/packaging-package-files.html#package_contents">Cygwin package guidelines</a>.
93 # In addition, all arguments to cygcmake are passed to cmake, followed by
94 # CYGCMAKE_ARGS, if set.
96 # * cygcmake should be run in or under $B, as it defines the build directory of
97 # the package and creates numerous files.
98 # * If the top-level CMakeLists.txt is not in $S, see CYGCMAKE_SOURCE.
99 # * Packages configured with cygcmake use either cygmake or cygninja to
100 # compile, depending on the value of CYGCMAKE_GENERATOR.
105 local buildtype cmdir crossargs exeext;
107 check_prog_req cmake;
110 *-cygwin*|*-mingw*|*-msys*) exeext=".exe" ;;
113 #****v* cygcmake/CYGCMAKE_SOURCE
115 # Set this variable to the directory containing the top-level CMakeLists.txt.
116 # This is only necessary when the top-level CMakeLists.txt is not in $S and
117 # cygcmake is not being run in the same subdirectory of $B which under $S
118 # contains the top-level CMakeLists.txt. (IOW if the top-level CMakeLists.txt
119 # is in $S/unix and cygcmake is run from $B/unix, setting CYGCMAKE_SOURCE
120 # would not be necessary.)
122 if defined CYGCMAKE_SOURCE && [ -e ${CYGCMAKE_SOURCE}/CMakeLists.txt ]
124 cmdir=${CYGCMAKE_SOURCE};
125 elif [ -e ${PWD/${B}/${S}}/CMakeLists.txt ]
127 cmdir=${PWD/${B}/${S}};
128 elif [ -e ${S}/CMakeLists.txt ]
132 error "cygcmake: cmake directory not found";
135 if defined _CYGPORT_RESTRICT_debuginfo_
139 buildtype=RelWithDebInfo
144 crossargs="-DCMAKE_SYSTEM_NAME=$(__cmake_system)
145 -D_CMAKE_TOOLCHAIN_PREFIX=${CHOST}-
146 -DCMAKE_FIND_ROOT_PATH=$(${CC} -print-sysroot)
147 -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY
148 -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY"
149 case ${CHOST} in *-cygwin*|*-mingw*)
150 crossargs+=" -DCMAKE_RC_COMPILER=$(which ${CHOST}-windres${exeext})"
153 if check_prog ${CHOST}-pkg-config
155 crossargs+=" -DPKG_CONFIG_EXECUTABLE=$(which ${CHOST}-pkg-config)"
161 #****v* cygcmake/CYGCMAKE_ARGS
163 # Additional flags to pass to cmake during cygcmake.
165 # Flags in CYGCMAKE_ARGS follow, and therefore override, flags passed by
166 # default and as arguments to cygcmake.
168 #****v* cygcmake/CYGCMAKE_GENERATOR
170 # The CMake Generator to be used in this build, either "Ninja" or "Unix Makefiles".
172 # If cygcmake is called explicitly, the default is "Unix Makefiles" for
173 # backwards compatibility. If the default src_compile is used, then "Ninja"
174 # will be the default; note that in this case, if the default src_install is
175 # not used, then it will fail until either CYGCMAKE_GENERATOR is set to
176 # "Unix Makefiles", or cyginstall replaced by ninja_install.
180 -G "${CYGCMAKE_GENERATOR:-Unix Makefiles}" \
182 -DCMAKE_BINARY_DIR=. \
183 -DCMAKE_BUILD_TYPE=${buildtype} \
184 -DCMAKE_C_COMPILER=$(which ${CC}${exeext}) \
185 -DCMAKE_C_FLAGS="${CFLAGS} ${CPPFLAGS}" \
186 -DCMAKE_CXX_COMPILER=$(which ${CXX}${exeext}) \
187 -DCMAKE_CXX_FLAGS="${CXXFLAGS} ${CPPFLAGS}" \
188 -DCMAKE_Fortran_COMPILER=$(which ${FC}${exeext}) \
189 -DCMAKE_Fortran_FLAGS="${FCFLAGS} ${CPPFLAGS}" \
190 -DCMAKE_AR=$(which ${AR}${exeext}) \
191 -DCMAKE_RANLIB=$(which ${RANLIB}${exeext}) \
192 -DCMAKE_EXE_LINKER_FLAGS="${LDFLAGS}" \
193 -DCMAKE_MODULE_LINKER_FLAGS="${LDFLAGS}" \
194 -DCMAKE_SHARED_LINKER_FLAGS="${LDFLAGS}" \
195 -DCMAKE_INSTALL_PREFIX=$(__host_prefix) \
196 -DCMAKE_LEGACY_CYGWIN_WIN32=0 \
200 || error "cmake failed"
203 #****o* cmake.cygclass/src_compile (cmake)
207 : ${CYGCMAKE_GENERATOR=Ninja}
209 if [ -f build.ninja ]
218 #****o* cmake.cygclass/src_test (cmake)
226 #****o* cmake.cygclass/src_install (cmake)
230 if [ -f build.ninja ]
239 readonly -f __cmake_system cygcmake