37 | | options cmake.out_of_source cmake.build_dir |
| 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 cmake.set_osx_architectures |
| 45 | options cmake.install_rpath |
| 46 | |
| 47 | # make out-of-source builds the default (finally) |
| 48 | default cmake.out_of_source yes |
| 49 | |
| 50 | # set CMAKE_OSX_ARCHITECTURES when necessary. |
| 51 | # This can be deactivated when (non-Apple) compilers are used |
| 52 | # that don't support the corresponding -arch options. |
| 53 | default cmake.set_osx_architectures yes |
116 | | if {${configure.optflags} ne ""} { |
117 | | configure.args-append -DCMAKE_C_FLAGS_RELEASE="-DNDEBUG" \ |
118 | | -DCMAKE_CXX_FLAGS_RELEASE="-DNDEBUG" |
| 135 | # NB: more recent CMake versions (>=3?) no longer take the env. variables into |
| 136 | # account, and thus require explicit use of ${configure.c*flags} below: |
| 137 | # if {${configure.optflags} ne ""} { |
| 138 | # configure.args-append -DCMAKE_C_FLAGS="-DNDEBUG ${configure.cflags}" \ |
| 139 | # -DCMAKE_CXX_FLAGS="-DNDEBUG ${configure.cxxflags}" |
| 140 | # } |
| 141 | # Using a custom BUILD_TYPE we can simply append to the env. variables, |
| 142 | # but why do we set -DNDEBUG? |
| 143 | configure.cflags-append -DNDEBUG |
| 144 | configure.cxxflags-append -DNDEBUG |
| 145 | # force newer CMake versions to take a change in compiler choice into account |
| 146 | # even if it is invoked in a build.dir that was configured before. |
| 147 | if {${configure.cc} ne ""} { |
| 148 | configure.args-append \ |
| 149 | -DCMAKE_C_COMPILER=${configure.cc} |
| 150 | } |
| 151 | if {${configure.cxx} ne ""} { |
| 152 | configure.args-append \ |
| 153 | -DCMAKE_CXX_COMPILER=${configure.cxx} |
| 154 | } |
| 155 | |
| 156 | |
| 157 | # process ${configure.cppflags} to extract include directives and other options |
| 158 | if {${configure.cppflags} ne ""} { |
| 159 | set cppflags [split ${configure.cppflags}] |
| 160 | # reset configure.cppflags; we don't want options in double in CPPFLAGS and CFLAGS/CXXFLAGS |
| 161 | set configure.cppflags "" |
| 162 | set next_is_path 0 |
| 163 | foreach flag ${cppflags} { |
| 164 | if {${next_is_path}} { |
| 165 | # previous option was a lone -I |
| 166 | configure.cppflags-append -I${flag} |
| 167 | set next_is_path 0 |
| 168 | } else { |
| 169 | if {[string match "-I" ${flag}]} { |
| 170 | # lone -I, store the next argument as a path |
| 171 | # (or ignore if this is the last argument) |
| 172 | set next_is_path 1 |
| 173 | } elseif {[string match "-I*" ${flag}]} { |
| 174 | # a -Ipath option |
| 175 | configure.cppflags-append ${flag} |
| 176 | } else { |
| 177 | # everything else must go into CFLAGS and CXXFLAGS |
| 178 | configure.cflags-append ${flag} |
| 179 | configure.cxxflags-append ${flag} |
| 180 | # append to the ObjC flags too, even if CMake ignores them: |
| 181 | configure.objcflags-append ${flag} |
| 182 | configure.objcxxflags-append ${flag} |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | if {${configure.cppflags} ne ""} { |
| 187 | ui_debug "-DINCLUDE_DIRECTORIES=${configure.cppflags}" |
| 188 | configure.args-append -DINCLUDE_DIRECTORIES:PATH="${configure.cppflags}" |
| 189 | } |
| 190 | ui_debug "CFLAGS=\"${configure.cflags}\" CXXFLAGS=\"${configure.cxxflags}\"" |
| 191 | } |
| 192 | |
| 193 | if {${cmake.install_rpath} ne ""} { |
| 194 | ui_debug "Adding -DCMAKE_INSTALL_RPATH=[join ${cmake.install_rpath} \;] to configure.args" |
| 195 | configure.args-append -DCMAKE_INSTALL_RPATH="[join ${cmake.install_rpath} \;]" |
122 | | platform darwin { |
123 | | set cmake._archflag_vars {cc_archflags cxx_archflags ld_archflags objc_archflags objcxx_archflags universal_cflags universal_cxxflags universal_ldflags universal_objcflags universal_objcxxflags} |
| 199 | post-configure { |
| 200 | # either compile_commands.json was created because of -DCMAKE_EXPORT_COMPILE_COMMANDS=ON |
| 201 | # in which case touch'ing it won't change anything. Or else it wasn't created, in which case |
| 202 | # we'll create a file that corresponds, i.e. containing an empty json array. |
| 203 | if {![file exists ${build.dir}/compile_commands.json]} { |
| 204 | if {![catch {set fd [open "${build.dir}/compile_commands.json" "w"]} err]} { |
| 205 | puts ${fd} "\[\n\]" |
| 206 | close ${fd} |
| 207 | } |
| 208 | } |
| 209 | if {![catch {set fd [open "${workpath}/.macports.${subport}.configure.cmd" "w"]} err]} { |
| 210 | foreach var [array names ::env] { |
| 211 | puts ${fd} "${var}=$::env(${var})" |
| 212 | } |
| 213 | puts ${fd} "[join [lrange [split ${configure.env} " "] 0 end] "\n"]" |
| 214 | # the following variables are no longer set in the environment at this point: |
| 215 | puts ${fd} "CPP=\"${configure.cpp}\"" |
| 216 | puts ${fd} "CC=\"${configure.cc}\"" |
| 217 | puts ${fd} "CXX=\"${configure.cxx}\"" |
| 218 | if {${configure.objcxx} ne ${configure.cxx}} { |
| 219 | puts ${fd} "OBJCXX=\"${configure.objcxx}\"" |
| 220 | } |
| 221 | puts ${fd} "CFLAGS=\"${configure.cflags}\"" |
| 222 | puts ${fd} "CXXFLAGS=\"${configure.cxxflags}\"" |
| 223 | if {${configure.objcflags} ne ${configure.cflags}} { |
| 224 | puts ${fd} "OBJCFLAGS=\"${configure.objcflags}\"" |
| 225 | } |
| 226 | if {${configure.objcxxflags} ne ${configure.cxxflags}} { |
| 227 | puts ${fd} "OBJCXXFLAGS=\"${configure.objcxxflags}\"" |
| 228 | } |
| 229 | puts ${fd} "LDFLAGS=\"${configure.ldflags}\"" |
| 230 | if {${configure.optflags} ne ""} { |
| 231 | puts ${fd} "configure.optflags=\"${configure.optflags}\"" |
| 232 | } |
| 233 | puts ${fd} "\ncd ${worksrcpath}" |
| 234 | puts ${fd} "${configure.cmd} ${configure.pre_args} ${configure.args} ${configure.post_args}" |
| 235 | close ${fd} |
| 236 | unset fd |
| 237 | } |
| 238 | } |