1 | # -*- coding: utf-8; mode: tcl; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4; truncate-lines: t -*- vim:fenc=utf-8:et:sw=4:ts=4:sts=4 |
---|
2 | # $Id: cmake-1.0.tcl 143801 2015-12-22 01:37:59Z ryandesign@macports.org $ |
---|
3 | # $Id: cmake-1.1.tcl 143801 2016-09-11 16:28:00Z gmail.com:rjvbertin $ |
---|
4 | # |
---|
5 | # Copyright (c) 2009 Orville Bennett <illogical1 at gmail.com> |
---|
6 | # Copyright (c) 2010-2015 The MacPorts Project |
---|
7 | # Copyright (c) 2015, 2016 R.J.V. Bertin |
---|
8 | # All rights reserved. |
---|
9 | # |
---|
10 | # Redistribution and use in source and binary forms, with or without |
---|
11 | # modification, are permitted provided that the following conditions are |
---|
12 | # met: |
---|
13 | # |
---|
14 | # 1. Redistributions of source code must retain the above copyright |
---|
15 | # notice, this list of conditions and the following disclaimer. |
---|
16 | # 2. Redistributions in binary form must reproduce the above copyright |
---|
17 | # notice, this list of conditions and the following disclaimer in the |
---|
18 | # documentation and/or other materials provided with the distribution. |
---|
19 | # 3. Neither the name of Apple Computer, Inc. nor the names of its |
---|
20 | # contributors may be used to endorse or promote products derived from |
---|
21 | # this software without specific prior written permission. |
---|
22 | # |
---|
23 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
24 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
25 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
---|
26 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
---|
27 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
---|
28 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
---|
29 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
---|
30 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
---|
31 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
---|
32 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
---|
33 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
34 | # |
---|
35 | # |
---|
36 | # Usage: |
---|
37 | # PortGroup cmake 1.1 |
---|
38 | |
---|
39 | namespace eval cmake { |
---|
40 | # our directory: |
---|
41 | variable currentportgroupdir [file dirname [dict get [info frame 0] file]] |
---|
42 | } |
---|
43 | |
---|
44 | options cmake.out_of_source cmake.build_dir |
---|
45 | |
---|
46 | default cmake.out_of_source no |
---|
47 | default cmake.build_dir {${workpath}/build} |
---|
48 | |
---|
49 | # standard place to install extra CMake modules |
---|
50 | set cmake_share_module_dir ${prefix}/share/cmake/Modules |
---|
51 | |
---|
52 | # can use cmake or cmake-devel; default to cmake if not installed |
---|
53 | depends_build-append path:bin/cmake:cmake |
---|
54 | |
---|
55 | proc _cmake_get_build_dir {} { |
---|
56 | if {[option cmake.out_of_source]} { |
---|
57 | return [option cmake.build_dir] |
---|
58 | } |
---|
59 | return [option worksrcpath] |
---|
60 | } |
---|
61 | |
---|
62 | default configure.dir {[_cmake_get_build_dir]} |
---|
63 | |
---|
64 | pre-configure { |
---|
65 | file mkdir ${configure.dir} |
---|
66 | } |
---|
67 | |
---|
68 | #FIXME: ccache works with cmake on linux |
---|
69 | configure.ccache no |
---|
70 | |
---|
71 | configure.cmd ${prefix}/bin/cmake |
---|
72 | |
---|
73 | configure.pre_args -DCMAKE_INSTALL_PREFIX=${prefix} |
---|
74 | |
---|
75 | set cmake_install_rpath ${prefix}/lib |
---|
76 | |
---|
77 | configure.args -DCMAKE_VERBOSE_MAKEFILE=ON \ |
---|
78 | -DCMAKE_COLOR_MAKEFILE=ON \ |
---|
79 | -DCMAKE_BUILD_TYPE=MacPorts \ |
---|
80 | -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \ |
---|
81 | -DCMAKE_INSTALL_RPATH="${cmake_install_rpath}" \ |
---|
82 | -DCMAKE_INSTALL_NAME_DIR=${prefix}/lib \ |
---|
83 | -DCMAKE_SYSTEM_PREFIX_PATH="${prefix}\;/usr" \ |
---|
84 | -DCMAKE_MODULE_PATH=${cmake_share_module_dir} \ |
---|
85 | -DCMAKE_FIND_FRAMEWORK=LAST \ |
---|
86 | -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ |
---|
87 | -Wno-dev |
---|
88 | |
---|
89 | proc cmake.install_rpath {mode path} { |
---|
90 | upvar #0 cmake_install_rpath rpath |
---|
91 | if {${path} ne ""} { |
---|
92 | switch -nocase ${mode} { |
---|
93 | append {set newpath "${rpath}\;${path}"} |
---|
94 | prepend {set newpath "${path}\;${rpath}"} |
---|
95 | reset {set newpath "${path}"} |
---|
96 | default { |
---|
97 | ui_error "Usage: cmake.install_rpath <append|prepend|reset> <path>" |
---|
98 | return -code error "Invalid invocation of cmake.install_rpath" |
---|
99 | } |
---|
100 | } |
---|
101 | configure.args-replace \ |
---|
102 | -DCMAKE_INSTALL_RPATH="${rpath}" \ |
---|
103 | -DCMAKE_INSTALL_RPATH="${newpath}" |
---|
104 | set rpath ${newpath} |
---|
105 | } |
---|
106 | } |
---|
107 | |
---|
108 | default configure.post_args {${worksrcpath}} |
---|
109 | |
---|
110 | # CMake honors set environment variables CFLAGS, CXXFLAGS, and LDFLAGS when it |
---|
111 | # is first run in a build directory to initialize CMAKE_C_FLAGS, |
---|
112 | # CMAKE_CXX_FLAGS, CMAKE_[EXE|SHARED|MODULE]_LINKER_FLAGS. However, be aware |
---|
113 | # that a CMake script can always override these flags when it runs, as they |
---|
114 | # are frequently set internally in functions of other CMake build variables! |
---|
115 | # |
---|
116 | # Attention: If you want to be sure that no compiler flags are passed via |
---|
117 | # configure.args, you have to manually clear configure.optflags, as it is set |
---|
118 | # to "-Os" by default and added to all language-specific flags. If you want to |
---|
119 | # turn off optimization, explicitly set configure.optflags to "-O0". |
---|
120 | |
---|
121 | # TODO: Handle configure.objcflags (cf. to CMake upstream ticket #4756 |
---|
122 | # "CMake needs an Objective-C equivalent of CMAKE_CXX_FLAGS" |
---|
123 | # <http://public.kitware.com/Bug/view.php?id=4756>) |
---|
124 | |
---|
125 | # TODO: Handle the Fortran-specific configure.* variables: |
---|
126 | # configure.fflags, configure.fcflags, configure.f90flags |
---|
127 | |
---|
128 | # TODO: Handle the Java-specific configure.classpath variable. |
---|
129 | |
---|
130 | pre-configure { |
---|
131 | # The environment variable CPPFLAGS is not considered by CMake. |
---|
132 | # (CMake upstream ticket #12928 "CMake silently ignores CPPFLAGS" |
---|
133 | # <http://www.cmake.org/Bug/view.php?id=12928>). |
---|
134 | # |
---|
135 | # But adding -I${prefix}/include to CFLAGS/CXXFLAGS is a bad idea. |
---|
136 | # If any other flags are needed, we need to add them. |
---|
137 | |
---|
138 | # In addition, CMake provides build-type-specific flags for |
---|
139 | # Release (-O3 -DNDEBUG), Debug (-g), MinSizeRel (-Os -DNDEBUG), and |
---|
140 | # RelWithDebInfo (-O2 -g -DNDEBUG). If the configure.optflags have been |
---|
141 | # set (-Os by default), we have to remove the optimization flags from the |
---|
142 | # from the concerned Release build type so that configure.optflags |
---|
143 | # gets honored (Debug used by the +debug variant does not set |
---|
144 | # optimization flags by default). |
---|
145 | # NB: more recent CMake versions (>=3?) no longer take the env. variables into |
---|
146 | # account, and thus require explicit use of ${configure.c*flags} below: |
---|
147 | # if {${configure.optflags} ne ""} { |
---|
148 | # configure.args-append -DCMAKE_C_FLAGS="-DNDEBUG ${configure.cflags}" \ |
---|
149 | # -DCMAKE_CXX_FLAGS="-DNDEBUG ${configure.cxxflags}" |
---|
150 | # } |
---|
151 | # Using a custom BUILD_TYPE we can simply append to the env. variables, |
---|
152 | # but why do we set -DNDEBUG? |
---|
153 | configure.cflags-append -DNDEBUG |
---|
154 | configure.cxxflags-append -DNDEBUG |
---|
155 | # force newer CMake versions to take a change in compiler choice into account |
---|
156 | # even if it is invoked in a build.dir that was configured before. |
---|
157 | if {${configure.cc} ne ""} { |
---|
158 | configure.args-append \ |
---|
159 | -DCMAKE_C_COMPILER=${configure.cc} |
---|
160 | } |
---|
161 | if {${configure.cxx} ne ""} { |
---|
162 | configure.args-append \ |
---|
163 | -DCMAKE_CXX_COMPILER=${configure.cxx} |
---|
164 | } |
---|
165 | |
---|
166 | |
---|
167 | # process ${configure.cppflags} to extract include directives and other options |
---|
168 | if {${configure.cppflags} ne ""} { |
---|
169 | set cppflags [split ${configure.cppflags}] |
---|
170 | # reset configure.cppflags; we don't want options in double in CPPFLAGS and CFLAGS/CXXFLAGS |
---|
171 | set configure.cppflags "" |
---|
172 | set next_is_path 0 |
---|
173 | foreach flag ${cppflags} { |
---|
174 | if {${next_is_path}} { |
---|
175 | # previous option was a lone -I |
---|
176 | configure.cppflags-append -I${flag} |
---|
177 | set next_is_path 0 |
---|
178 | } else { |
---|
179 | if {[string match "-I" ${flag}]} { |
---|
180 | # lone -I, store the next argument as a path |
---|
181 | # (or ignore if this is the last argument) |
---|
182 | set next_is_path 1 |
---|
183 | } elseif {[string match "-I*" ${flag}]} { |
---|
184 | # a -Ipath option |
---|
185 | configure.cppflags-append ${flag} |
---|
186 | } else { |
---|
187 | # everything else must go into CFLAGS and CXXFLAGS |
---|
188 | configure.cflags-append ${flag} |
---|
189 | configure.cxxflags-append ${flag} |
---|
190 | # append to the ObjC flags too, even if CMake ignores them: |
---|
191 | configure.objcflags-append ${flag} |
---|
192 | configure.objcxxflags-append ${flag} |
---|
193 | } |
---|
194 | } |
---|
195 | } |
---|
196 | if {${configure.cppflags} ne ""} { |
---|
197 | ui_debug "-DINCLUDE_DIRECTORIES=${configure.cppflags}" |
---|
198 | configure.args-append -DINCLUDE_DIRECTORIES:PATH="${configure.cppflags}" |
---|
199 | } |
---|
200 | ui_debug "CFLAGS=\"${configure.cflags}\" CXXFLAGS=\"${configure.cxxflags}\"" |
---|
201 | } |
---|
202 | } |
---|
203 | |
---|
204 | post-configure { |
---|
205 | # either compile_commands.json was created because of -DCMAKE_EXPORT_COMPILE_COMMANDS=ON |
---|
206 | # in which case touch'ing it won't change anything. Or else it wasn't created, in which case |
---|
207 | # we'll create a file that corresponds, i.e. containing an empty json array. |
---|
208 | if {![file exists ${build.dir}/compile_commands.json]} { |
---|
209 | if {![catch {set fd [open "${build.dir}/compile_commands.json" "w"]} err]} { |
---|
210 | puts ${fd} "\[\n\]" |
---|
211 | close ${fd} |
---|
212 | } |
---|
213 | } |
---|
214 | if {![catch {set fd [open "${workpath}/.macports.${subport}.configure.cmd" "w"]} err]} { |
---|
215 | foreach var [array names ::env] { |
---|
216 | puts ${fd} "${var}=$::env(${var})" |
---|
217 | } |
---|
218 | puts ${fd} "[join [lrange [split ${configure.env} " "] 0 end] "\n"]" |
---|
219 | # the following variables are no longer set in the environment at this point: |
---|
220 | puts ${fd} "CPP=\"${configure.cpp}\"" |
---|
221 | puts ${fd} "CC=\"${configure.cc}\"" |
---|
222 | puts ${fd} "CXX=\"${configure.cxx}\"" |
---|
223 | if {${configure.objcxx} ne ${configure.cxx}} { |
---|
224 | puts ${fd} "OBJCXX=\"${configure.objcxx}\"" |
---|
225 | } |
---|
226 | puts ${fd} "CFLAGS=\"${configure.cflags}\"" |
---|
227 | puts ${fd} "CXXFLAGS=\"${configure.cxxflags}\"" |
---|
228 | if {${configure.objcflags} ne ${configure.cflags}} { |
---|
229 | puts ${fd} "OBJCFLAGS=\"${configure.objcflags}\"" |
---|
230 | } |
---|
231 | if {${configure.objcxxflags} ne ${configure.cxxflags}} { |
---|
232 | puts ${fd} "OBJCXXFLAGS=\"${configure.objcxxflags}\"" |
---|
233 | } |
---|
234 | puts ${fd} "LDFLAGS=\"${configure.ldflags}\"" |
---|
235 | if {${configure.optflags} ne ""} { |
---|
236 | puts ${fd} "configure.optflags=\"${configure.optflags}\"" |
---|
237 | } |
---|
238 | puts ${fd} "\ncd ${worksrcpath}" |
---|
239 | puts ${fd} "${configure.cmd} ${configure.pre_args} ${configure.args} ${configure.post_args}" |
---|
240 | close ${fd} |
---|
241 | unset fd |
---|
242 | } |
---|
243 | } |
---|
244 | |
---|
245 | platform darwin { |
---|
246 | set cmake._archflag_vars {cc_archflags cxx_archflags ld_archflags objc_archflags objcxx_archflags \ |
---|
247 | universal_cflags universal_cxxflags universal_ldflags universal_objcflags universal_objcxxflags} |
---|
248 | pre-configure { |
---|
249 | # cmake will add the correct -arch flag(s) based on the value of CMAKE_OSX_ARCHITECTURES. |
---|
250 | if {[variant_exists universal] && [variant_isset universal]} { |
---|
251 | if {[info exists universal_archs_supported]} { |
---|
252 | merger_arch_compiler no |
---|
253 | merger_arch_flag no |
---|
254 | global merger_configure_args |
---|
255 | foreach arch ${universal_archs_to_use} { |
---|
256 | lappend merger_configure_args(${arch}) -DCMAKE_OSX_ARCHITECTURES=${arch} |
---|
257 | } |
---|
258 | } else { |
---|
259 | configure.universal_args-append \ |
---|
260 | -DCMAKE_OSX_ARCHITECTURES="[join ${configure.universal_archs} \;]" |
---|
261 | } |
---|
262 | } else { |
---|
263 | configure.args-append \ |
---|
264 | -DCMAKE_OSX_ARCHITECTURES="${configure.build_arch}" |
---|
265 | } |
---|
266 | |
---|
267 | # Setting our own -arch flags is unnecessary (in the case of a non-universal build) or even |
---|
268 | # harmful (in the case of a universal build, because it causes the compiler identification to |
---|
269 | # fail; see http://public.kitware.com/pipermail/cmake-developers/2015-September/026586.html). |
---|
270 | # Save all archflag-containing variables before changing any of them, because some of them |
---|
271 | # declare their default value based on the value of another. |
---|
272 | foreach archflag_var ${cmake._archflag_vars} { |
---|
273 | global cmake._saved_${archflag_var} |
---|
274 | set cmake._saved_${archflag_var} [option configure.${archflag_var}] |
---|
275 | } |
---|
276 | foreach archflag_var ${cmake._archflag_vars} { |
---|
277 | configure.${archflag_var} |
---|
278 | } |
---|
279 | |
---|
280 | configure.args-append -DCMAKE_OSX_DEPLOYMENT_TARGET="${macosx_deployment_target}" |
---|
281 | |
---|
282 | if {${configure.sdkroot} != ""} { |
---|
283 | configure.args-append -DCMAKE_OSX_SYSROOT="${configure.sdkroot}" |
---|
284 | } else { |
---|
285 | configure.args-append -DCMAKE_OSX_SYSROOT="/" |
---|
286 | } |
---|
287 | } |
---|
288 | post-configure { |
---|
289 | # Although cmake wants us not to set -arch flags ourselves when we run cmake, |
---|
290 | # ports might have need to access these variables at other times. |
---|
291 | foreach archflag_var ${cmake._archflag_vars} { |
---|
292 | global cmake._saved_${archflag_var} |
---|
293 | configure.${archflag_var} [set cmake._saved_${archflag_var}] |
---|
294 | } |
---|
295 | } |
---|
296 | } |
---|
297 | |
---|
298 | configure.universal_args-delete --disable-dependency-tracking |
---|
299 | |
---|
300 | variant debug description "Enable debug binaries" { |
---|
301 | configure.args-replace -DCMAKE_BUILD_TYPE=Release -DCMAKE_BUILD_TYPE=Debug |
---|
302 | } |
---|
303 | |
---|
304 | # cmake doesn't like --enable-debug, so in case a portfile sets |
---|
305 | # --enable-debug (regardless of variant) we remove it |
---|
306 | if {[string first "--enable-debug" ${configure.args}] > -1} { |
---|
307 | configure.args-delete --enable-debug |
---|
308 | } |
---|
309 | |
---|
310 | default build.dir {${configure.dir}} |
---|
311 | |
---|
312 | default build.post_args {VERBOSE=ON} |
---|