Ticket #32528: Portfile-opencv.diff

File Portfile-opencv.diff, 14.7 KB (added by marin.saric@…, 12 years ago)

OpenCV 2.3.1a fixed Portfile

  • Portfile

    old new  
    66
    77name                            opencv
    88version                         2.3.1a
    9 revision                        1
     9revision                        2
    1010set short_version               [strsed ${version} {g/[^0-9.].*$//}]
    1111categories                      graphics science
    1212license                         BSD
    1313platforms                       darwin
    14 maintainers                     nomaintainer
     14maintainers                     gmail:marin.saric openmaintainer
    1515
    1616description                     Intel(R) Open Source Computer Vision Library
    1717
     
    3535depends_build-append            port:pkgconfig
    3636
    3737depends_lib-append              port:zlib \
    38                                 path:lib/libavcodec.dylib:ffmpeg \
    3938                                port:libpng \
    4039                                port:tiff \
    4140                                port:jasper \
    4241                                port:jpeg \
    43                                 port:bzip2 \
    44                                 port:dirac \
    45                                 port:faac \
    46                                 port:faad2 \
    47                                 port:lame \
    48                                 port:schroedinger \
    49                                 port:liboil \
    50                                 port:libtheora \
    51                                 port:libvorbis \
    52                                 port:libogg \
    53                                 port:x264 \
    54                                 port:orc
     42                                port:bzip2
    5543
    5644# liboil is not universal
    5745universal_variant               no
    5846
     47default_variants                +eigen +ffmpeg +python27 +tbb +also_static
     48
    5949patchfiles                      patch-CMakeLists.txt.diff \
    60                                 patch-install_name.diff
     50                                patch-install_name.diff \
     51                                patch-OpenCVConfig.cmake.in.diff \
     52                                patch-modules_highgui_CMakeLists.txt.diff \
     53                                patch-samples_CMakeLists.txt.diff \
     54                                patch-samples_c_build_all.sh.diff \
     55                                patch-samples_c_CMakeLists.txt.diff \
     56                                patch-samples_cpp_CMakeLists.txt.diff
    6157
    6258if {[variant_isset universal] && [variant_exists universal]} {
    63     patchfiles-append           patch-pch-CMakeLists.txt.diff
     59    configure.args-append       -DUSE_PRECOMPILED_HEADERS=OFF
    6460}
    6561
    66 configure.args-append           -DBUILD_NEW_PYTHON_SUPPORT=OFF \
    67                                 -DBUILD_EXAMPLES=ON \
    68                                 -DINSTALL_C_EXAMPLES=ON \
    69                                 -DBZIP2_LIBRARIES=${prefix}/lib/libbz2.dylib \
    70                                 -DZLIB_LIBRARY=${prefix}/lib/libz.dylib \
     62# Common options
     63configure.args-append           -DCMAKE_PREFIX_PATH=\"${prefix}\;/usr\" \
     64                                -DOPENCV_BUILT_SHARED_AND_STATIC=OFF \
     65                                -DBUILD_EXAMPLES=OFF \
     66                                -DBUILD_TESTS=OFF \
     67                                -DWITH_EIGEN=OFF \
     68                                -DWITH_FFMPEG=OFF \
    7169                                -DWITH_OPENEXR=OFF \
    7270                                -DWITH_1394=OFF
    7371
     
    7573    configure.compiler llvm-gcc-4.2
    7674}
    7775
     76# Prepare the out-of-source cmake build for shared and static versions
     77set sharedsrcpath "${worksrcpath}/build-shared"
     78set staticsrcpath "${worksrcpath}/build-static"
     79set destrootstatic "${destroot}-static"
     80
     81# In out-of-source builds, the cmake toplevel is one directory above
     82configure.pre_args .. "${configure.pre_args}"
     83
     84# Utility routines to switch between different build types
     85set build_state_last_opts ""
     86
     87proc 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
     100proc get_python_version {} {
     101    if {[variant_isset python26]} {return "2.6"}
     102    if {[variant_isset python27]} {return "2.7"}
     103    return ""
     104}
     105
     106proc python_variant_set {} {
     107    return [expr {[get_python_version] != {}}]
     108}
     109
     110proc 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
     200post-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
     213post-patch {
     214    reinplace "s|/usr/local|${prefix}|g" ${worksrcpath}/CMakeLists.txt
     215}
     216
    78217platform darwin {
    79218    # Use macros in /usr/include/stdint.h with C++ compiler
    80219    # http://roundup.libav.org/issue2093
     
    96235            return -code error "incompatible ${name} version active"
    97236        }
    98237    }
     238
     239    # Start with the shared libary setup
     240    build_state shared
     241}
     242
     243post-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
     268pre-destroot {
     269    # Continue to the shared library installation
     270    build_state shared
     271}
     272
     273post-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
     311variant 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
    99314}
    100315
    101316variant dc1394 description {Use libdc1394 for FireWire camera. Breaks compatibility with Apple iSight FireWire camera.} {
     
    107322
    108323variant qt4 description {Use experimental qt4 backend for graphical interface.} {
    109324    depends_lib-append          port:qt4-mac
    110     configure.args-append       -DWITH_QT=ON
     325}
     326
     327variant qt4_in_static description {Use the qt4 backend in the static build. Introduces an implicit dependency on QT4 dynamic libaries} {
     328    depends_lib-append          port:qt4-mac
    111329}
    112330
    113331variant python26 conflicts python27 description {Add Python 2.6 bindings} {
    114     depends_lib-append          port:python26
    115     configure.args-delete       -DBUILD_NEW_PYTHON_SUPPORT=OFF
    116     configure.args-append       -DINSTALL_PYTHON_EXAMPLES=ON \
    117                                 -DBUILD_NEW_PYTHON_SUPPORT=ON \
    118                                 -DPYTHON_EXECUTABLE=${prefix}/bin/python2.6 \
    119                                 -DPYTHON_LIBRARY=${prefix}/lib/libpython2.6.dylib \
    120                                 -DPYTHON_INCLUDE_DIR=${frameworks_dir}/Python.framework/Versions/2.6/Headers
    121     post-patch {
    122         reinplace "s|@@PYTHON_PKGD@@|${frameworks_dir}/Python.framework/Versions/2.6/lib/python2.6/site-packages|g" ${worksrcpath}/CMakeLists.txt
    123     }
     332    depends_lib-append          port:python26 port:py26-numpy
     333    configure.env-append        PYTHON=${prefix}/bin/python2.6
    124334}
    125335
    126336variant python27 conflicts python26 description {Add Python 2.7 bindings} {
    127     depends_lib-append          port:python27
    128     configure.args-delete       -DBUILD_NEW_PYTHON_SUPPORT=OFF
    129     configure.args-append       -DINSTALL_PYTHON_EXAMPLES=ON \
    130                                 -DBUILD_NEW_PYTHON_SUPPORT=ON \
    131                                 -DPYTHON_EXECUTABLE=${prefix}/bin/python2.7 \
    132                                 -DPYTHON_LIBRARY=${prefix}/lib/libpython2.7.dylib \
    133                                 -DPYTHON_INCLUDE_DIR=${frameworks_dir}/Python.framework/Versions/2.7/Headers
    134     post-patch {
    135         reinplace "s|@@PYTHON_PKGD@@|${frameworks_dir}/Python.framework/Versions/2.7/lib/python2.7/site-packages|g" ${worksrcpath}/CMakeLists.txt
    136     }
     337    depends_lib-append          port:python27 port:py27-numpy
     338    configure.env-append        PYTHON=${prefix}/bin/python2.7
    137339}
    138340
    139 variant tbb description {Use Intel TBB} {
     341variant tbb description {Use Intel Thread Building Blocks} {
    140342    depends_lib-append          port:tbb
    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
     345variant 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
     349variant 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
     367variant 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
     373variant 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
    146378}
    147379
    148380livecheck.type                  sourceforge