Bump version to 0.36.9
[cygport.git] / cygclass / cmake.cygclass
blobd2a7ef093314595205575553f45214790d04a794
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
25 #  SYNOPSIS
26 #  inherit cmake
27 #  DESCRIPTION
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.
35 #  INHERITS
36 #  ninja.cygclass
37 #  INHERITED BY
38 #  kde4.cygclass, kf5-cygclass, qt4-cmake.cygclass
39 #****
41 inherit ninja
43 __cmake_system() {
44         local cmsys
46         # FIXME: do binutils/gcc really support all these?
47         case ${CHOST} in
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" ;;
80         esac
82         echo -n ${cmsys}
85 #****C* cmake.cygclass/cygcmake
86 #  SYNOPSIS
87 #  cygcmake [OPTIONS]
88 #  DESCRIPTION
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.
95 #  NOTES
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.
101 #  REQUIRES
102 #  cmake
103 #****
104 cygcmake() {
105         local buildtype cmdir crossargs exeext;
107         check_prog_req cmake;
109         case ${CBUILD} in
110                 *-cygwin*|*-mingw*|*-msys*)  exeext=".exe" ;;
111         esac
113 #****v* cygcmake/CYGCMAKE_SOURCE
114 #  DESCRIPTION
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.)
121 #****
122         if defined CYGCMAKE_SOURCE && [ -e ${CYGCMAKE_SOURCE}/CMakeLists.txt ]
123         then
124                 cmdir=${CYGCMAKE_SOURCE};
125         elif [ -e ${PWD/${B}/${S}}/CMakeLists.txt ]
126         then
127                 cmdir=${PWD/${B}/${S}};
128         elif [ -e ${S}/CMakeLists.txt ]
129         then
130                 cmdir=${S};
131         else
132                 error "cygcmake: cmake directory not found";
133         fi
135         if defined _CYGPORT_RESTRICT_debuginfo_
136         then
137                 buildtype=Release
138         else
139                 buildtype=RelWithDebInfo
140         fi
142         if cross_compiling
143         then
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})"
151                         ;;
152                 esac
153                 if check_prog ${CHOST}-pkg-config
154                 then
155                         crossargs+=" -DPKG_CONFIG_EXECUTABLE=$(which ${CHOST}-pkg-config)"
156                 fi
157         else
158                 crossargs=
159         fi
161 #****v* cygcmake/CYGCMAKE_ARGS
162 #  DESCRIPTION
163 #  Additional flags to pass to cmake during cygcmake.
164 #  NOTES
165 #  Flags in CYGCMAKE_ARGS follow, and therefore override, flags passed by
166 #  default and as arguments to cygcmake.
167 #****
168 #****v* cygcmake/CYGCMAKE_GENERATOR
169 #  DESCRIPTION
170 #  The CMake Generator to be used in this build, either "Ninja" or "Unix Makefiles".
171 #  NOTES
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.
177 #****
179         cmake -Wno-dev \
180                 -G "${CYGCMAKE_GENERATOR:-Unix Makefiles}" \
181                 ${cmdir} \
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 \
197                 ${crossargs} \
198                 "${@}" \
199                 ${CYGCMAKE_ARGS} \
200                 || error "cmake failed"
203 #****o* cmake.cygclass/src_compile (cmake)
204 #  DEFINITION
205 src_compile() {
206         cd ${B}
207         : ${CYGCMAKE_GENERATOR=Ninja}
208         cygcmake
209         if [ -f build.ninja ]
210         then
211                 cygninja
212         else
213                 cygmake
214         fi
216 #****
218 #****o* cmake.cygclass/src_test (cmake)
219 #  DEFINITION
220 src_test() {
221         cd ${B}
222         ctest
224 #****
226 #****o* cmake.cygclass/src_install (cmake)
227 #  DEFINITION
228 src_install() {
229         cd ${B}
230         if [ -f build.ninja ]
231         then
232                 ninja_install
233         else
234                 cyginstall
235         fi
237 #****
239 readonly -f __cmake_system cygcmake