| 76 | # Prepare the out-of-source cmake build for shared and static versions |
| 77 | set sharedsrcpath "${worksrcpath}/build-shared" |
| 78 | set staticsrcpath "${worksrcpath}/build-static" |
| 79 | set destrootstatic "${destroot}-static" |
| 80 | |
| 81 | # In out-of-source builds, the cmake toplevel is one directory above |
| 82 | configure.pre_args .. "${configure.pre_args}" |
| 83 | |
| 84 | # Utility routines to switch between different build types |
| 85 | set build_state_last_opts "" |
| 86 | |
| 87 | proc adjust_build_vars {new_opts new_path} { |
| 88 | global build_state_last_opts |
| 89 | |
| 90 | configure.dir "${new_path}" |
| 91 | build.dir "${new_path}" |
| 92 | destroot.dir "${new_path}" |
| 93 | |
| 94 | configure.args-delete "${build_state_last_opts}" |
| 95 | configure.args-append "${new_opts}" |
| 96 | |
| 97 | set build_state_last_opts "${new_opts}" |
| 98 | } |
| 99 | |
| 100 | proc get_python_version {} { |
| 101 | if {[variant_isset python26]} {return "2.6"} |
| 102 | if {[variant_isset python27]} {return "2.7"} |
| 103 | return "" |
| 104 | } |
| 105 | |
| 106 | proc python_variant_set {} { |
| 107 | return [expr {[get_python_version] != {}}] |
| 108 | } |
| 109 | |
| 110 | proc build_state {state} { |
| 111 | global UI_PREFIX name sharedsrcpath staticsrcpath destroot destrootstatic |
| 112 | |
| 113 | ui_msg "$UI_PREFIX Setting the build state for ${name} to ${state}" |
| 114 | |
| 115 | set shared_opts [ list \ |
| 116 | -DINSTALL_C_EXAMPLES=ON \ |
| 117 | -DBUILD_SHARED_LIBS=ON \ |
| 118 | -DWITH_JASPER=ON ] |
| 119 | |
| 120 | # Add python support to the shared version if a python variant was specified |
| 121 | if {[python_variant_set]} { |
| 122 | global frameworks_dir prefix |
| 123 | |
| 124 | set py_version [get_python_version] |
| 125 | set python_framework ${frameworks_dir}/Python.framework/Versions/${py_version} |
| 126 | |
| 127 | lappend shared_opts \ |
| 128 | -DINSTALL_PYTHON_EXAMPLES=ON \ |
| 129 | -DBUILD_NEW_PYTHON_SUPPORT=ON \ |
| 130 | -DPYTHON_EXECUTABLE=${prefix}/bin/python${py_version} \ |
| 131 | -DPYTHON_LIBRARY=${prefix}/lib/libpython${py_version}.dylib \ |
| 132 | -DPYTHON_INCLUDE_DIR=${python_framework}/Headers \ |
| 133 | -DPYTHON_PACKAGES_PATH=${python_framework}/lib/python${py_version}/site-packages |
| 134 | } else { |
| 135 | lappend shared_opts \ |
| 136 | -DINSTALL_PYTHON_EXAMPLES=OFF \ |
| 137 | -DBUILD_NEW_PYTHON_SUPPORT=OFF |
| 138 | } |
| 139 | |
| 140 | if {[variant_isset tbb]} { |
| 141 | lappend shared_opts -DWITH_TBB=ON |
| 142 | } else { |
| 143 | lappend shared_opts -DWITH_TBB=OFF |
| 144 | } |
| 145 | |
| 146 | if {[variant_isset qt4]} { |
| 147 | lappend shared_opts \ |
| 148 | -DWITH_QT=ON \ |
| 149 | -DWITH_QT_OPENGL=ON |
| 150 | } else { |
| 151 | lappend shared_opts -DWITH_QT=OFF |
| 152 | } |
| 153 | |
| 154 | if {[variant_isset full_docs]} { |
| 155 | lappend shared_opts -DBUILD_DOCS=ON |
| 156 | } else { |
| 157 | lappend shared_opts -DBUILD_DOCS=OFF |
| 158 | } |
| 159 | |
| 160 | # Python support can be turned off while building static libraries |
| 161 | # since the shared library bindings will be used anyway |
| 162 | # Same goes for the documentation |
| 163 | set static_opts [ list \ |
| 164 | -DINSTALL_C_EXAMPLES=OFF \ |
| 165 | -DBUILD_SHARED_LIBS=OFF \ |
| 166 | -DWITH_JASPER=OFF \ |
| 167 | -DBUILD_DOCS=OFF \ |
| 168 | -DBUILD_NEW_PYTHON_SUPPORT=OFF \ |
| 169 | -DINSTALL_PYTHON_EXAMPLES=OFF ] |
| 170 | |
| 171 | # Unless explicitly asked, we will omit Intel TBB from the static |
| 172 | # build, because it introduces a dynamic library dependency |
| 173 | if {[variant_isset tbb_in_static]} { |
| 174 | lappend static_opts -DWITH_TBB=ON |
| 175 | } else { |
| 176 | lappend static_opts -DWITH_TBB=OFF |
| 177 | } |
| 178 | |
| 179 | if {[variant_isset qt4_in_static]} { |
| 180 | lappend static_opts \ |
| 181 | -DWITH_QT=ON \ |
| 182 | -DWITH_QT_OPENGL=ON |
| 183 | } else { |
| 184 | lappend static_opts -DWITH_QT=OFF |
| 185 | } |
| 186 | |
| 187 | switch "${state}" { |
| 188 | shared { |
| 189 | adjust_build_vars "${shared_opts}" "${sharedsrcpath}" |
| 190 | destroot.destdir "DESTDIR=${destroot}" |
| 191 | } |
| 192 | static { |
| 193 | adjust_build_vars "${static_opts}" "${staticsrcpath}" |
| 194 | destroot.destdir "DESTDIR=${destrootstatic}" |
| 195 | } |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | # Make sure to create out-of-source build directories |
| 200 | post-extract { |
| 201 | global sharedsrcpath staticsrcpath |
| 202 | |
| 203 | # Prepare the out-of-source build directories for |
| 204 | # both the shared and static libaries |
| 205 | system "mkdir ${sharedsrcpath} && mkdir ${staticsrcpath}" |
| 206 | |
| 207 | # Start with the shared library setup |
| 208 | # This step should be done on pre-configure, but cmake portgroup |
| 209 | # already implements pre-configure |
| 210 | build_state shared |
| 211 | } |
| 212 | |
| 213 | post-patch { |
| 214 | reinplace "s|/usr/local|${prefix}|g" ${worksrcpath}/CMakeLists.txt |
| 215 | } |
| 216 | |
| 238 | |
| 239 | # Start with the shared libary setup |
| 240 | build_state shared |
| 241 | } |
| 242 | |
| 243 | post-build { |
| 244 | global UI_PREFIX name sharedsrcpath staticsrcpath |
| 245 | |
| 246 | if {[variant_isset also_static]} { |
| 247 | # Continue with the static library build |
| 248 | build_state static |
| 249 | |
| 250 | ui_msg "$UI_PREFIX Configuring ${name} again for static libraries" |
| 251 | command_exec configure |
| 252 | ui_msg "$UI_PREFIX Building ${name} static libraries" |
| 253 | portbuild::build_main |
| 254 | } |
| 255 | |
| 256 | if {[variant_isset full_docs]} { |
| 257 | # Continue building the documentation in the shared library build |
| 258 | build_state shared |
| 259 | |
| 260 | ui_msg "$UI_PREFIX Building LaTeX documentation" |
| 261 | system "cd ${sharedsrcpath} && make docs" |
| 262 | |
| 263 | ui_msg "$UI_PREFIX Building HTML documentation" |
| 264 | system "cd ${sharedsrcpath} && make html_docs" |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | pre-destroot { |
| 269 | # Continue to the shared library installation |
| 270 | build_state shared |
| 271 | } |
| 272 | |
| 273 | post-destroot { |
| 274 | global UI_PREFIX name sharedsrcpath destroot destrootstatic |
| 275 | |
| 276 | if {[variant_isset also_static]} { |
| 277 | # Continue with the static library installation |
| 278 | build_state static |
| 279 | |
| 280 | ui_msg "$UI_PREFIX Staging ${name} again for static libraries" |
| 281 | command_exec destroot |
| 282 | |
| 283 | # Copy over the static libraries |
| 284 | set static_libs [glob ${destrootstatic}${prefix}/lib/*.a] |
| 285 | foreach static_lib ${static_libs} { |
| 286 | file rename ${static_lib} ${destroot}${prefix}/lib |
| 287 | } |
| 288 | |
| 289 | # The static library config works for both static and shared OpenCV |
| 290 | set config_path ${prefix}/share/OpenCV/OpenCVConfig.cmake |
| 291 | file copy -force ${destrootstatic}${config_path} ${destroot}${config_path} |
| 292 | |
| 293 | # Continue with the shared library for install |
| 294 | build_state shared |
| 295 | } |
| 296 | |
| 297 | if {[variant_isset full_docs]} { |
| 298 | ui_msg "$UI_PREFIX Staging ${name} full documentation" |
| 299 | set doc_output_path ${destroot}${prefix}/share/OpenCV/doc |
| 300 | |
| 301 | file mkdir ${doc_output_path} |
| 302 | set pdf_files [glob ${sharedsrcpath}/doc/*.pdf] |
| 303 | foreach pdf_file ${pdf_files} { |
| 304 | file copy -force ${pdf_file} ${doc_output_path} |
| 305 | } |
| 306 | |
| 307 | file copy ${sharedsrcpath}/doc/_html ${doc_output_path}/html |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | variant also_static description {Also produce static versions of the OpenCV library} { |
| 312 | configure.args-delete -DOPENCV_BUILT_SHARED_AND_STATIC=OFF |
| 313 | configure.args-append -DOPENCV_BUILT_SHARED_AND_STATIC=ON |
141 | | configure.args-append -DWITH_TBB=ON \ |
142 | | -DHAVE_TBB=ON \ |
143 | | -DTBB_INCLUDE_DIRS=${prefix}/include \ |
144 | | -DTBB_LIBRARY_DIRS=${prefix}/lib \ |
145 | | -DOPENCV_LINKER_LIBS="-ltbb -ltbbmalloc" |
| 343 | } |
| 344 | |
| 345 | variant tbb_in_static description {Use Intel Thread Building Block in the static build (a dynamic lib dependency)} { |
| 346 | depends_lib-append port:tbb |
| 347 | } |
| 348 | |
| 349 | variant full_docs description {Build full OpenCV documentation} { |
| 350 | depends_lib-append port:texlive-basic \ |
| 351 | port:texlive-generic-recommended \ |
| 352 | port:texlive-generic-extra \ |
| 353 | port:texlive-latex-recommended \ |
| 354 | port:texlive-latex-extra \ |
| 355 | port:texlive-fonts-recommended \ |
| 356 | port:texlive-fonts-extra |
| 357 | |
| 358 | if {[variant_isset python26]} { |
| 359 | depends_lib-append port:py26-sphinx |
| 360 | } elseif {[variant_isset python27]} { |
| 361 | depends_lib-append port:py27-sphinx |
| 362 | } else { |
| 363 | depends_lib-append port:py-sphinx |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | variant eigen description {Include the Eigen2/3 C++ linear algebra library support} { |
| 368 | depends_lib-append port:eigen port:eigen3 |
| 369 | configure.args-delete -DWITH_EIGEN=OFF |
| 370 | configure.args-append -DWITH_EIGEN=ON |
| 371 | } |
| 372 | |
| 373 | variant ffmpeg description {Include video support through the FFmpeg library} { |
| 374 | depends_lib-append port:ffmpeg \ |
| 375 | port:orc |
| 376 | configure.args-delete -DWITH_FFMPEG=OFF |
| 377 | configure.args-append -DWITH_FFMPEG=ON |