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