Skip to content

Commit

Permalink
opencv3/opencv4: reduce path copy-paste in configure arguments; simpl…
Browse files Browse the repository at this point in the history
…ify via cmake portgroup when possible

See: https://trac.macports.org/ticket/62011
  • Loading branch information
mascguy committed Jan 27, 2021
1 parent 4abf2a5 commit 5f1d975
Show file tree
Hide file tree
Showing 2 changed files with 158 additions and 106 deletions.
114 changes: 69 additions & 45 deletions graphics/opencv3/Portfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,14 @@ platform macosx {
#
# This is needed to support Python subports, whose names have no relation to
# the actual physical file layout.
#
# NOTE: Presently, 'parent_subport_name' matches 'name'. HOWEVER, this will
# change once the various OpenCV-related ports are merged.
#------------------------------------------------------------------------------
set physical_subport_name \
set parent_subport_name \
${name}

worksrcdir ${physical_subport_name}-${version}
worksrcdir ${parent_subport_name}-${version}

compiler.cxx_standard \
2011
Expand Down Expand Up @@ -115,40 +118,61 @@ post-patch {
# -DWITH_NVCUVID=OFF
# -DCMAKE_VERBOSE=ON

#------------------------------------------------------------------------------
# CMake Variables
#
# When/if the CMake portgroup is extended to support more of these options,
# they can be replaced with those equivalents. For now, define them ahead of
# time, for later re-use.
#------------------------------------------------------------------------------

# Define all of our base paths up-front
set opencv_install_prefix \
${prefix}/libexec/${parent_subport_name}
set opencv_install_cmake \
${opencv_install_prefix}/cmake
set opencv_install_include \
${prefix}/include/${parent_subport_name}
set opencv_install_lib \
${prefix}/lib/${parent_subport_name}

# Populate the few CMake options currently available
# TODO: Extend CMake portgroup to support more paths
cmake.install_prefix \
${opencv_install_prefix}
cmake_share_module_dir \
${opencv_install_cmake}
cmake.install_rpath \
${opencv_install_lib}

configure.args-append \
-DCMAKE_RULE_MESSAGES=OFF \
-DCMAKE_VERBOSE_MAKEFILE=ON \
\
-DENABLE_CONFIG_VERIFICATION=OFF \
\
-DCMAKE_INSTALL_PREFIX=${prefix}/libexec/${physical_subport_name} \
-DOPENCV_CONFIG_INSTALL_PATH=${prefix}/libexec/${physical_subport_name}/cmake \
-DOPENCV_BIN_INSTALL_PATH=${prefix}/libexec/${physical_subport_name}/bin \
-DOPENCV_SETUPVARS_INSTALL_PATH=${prefix}/libexec/${physical_subport_name}/scripts \
-DOPENCV_SBIN_INSTALL_PATH=${prefix}/libexec/${physical_subport_name}/sbin \
-DOPENCV_JAR_INSTALL_PATH=${prefix}/libexec/${physical_subport_name}/java/jar \
-DOPENCV_JNI_INSTALL_PATH=${prefix}/libexec/${physical_subport_name}/java/jni \
-DOPENCV_JNI_BIN_INSTALL_PATH=${prefix}/libexec/${physical_subport_name}/java/jni \
-DOPENCV_TEST_INSTALL_PATH=${prefix}/libexec/${physical_subport_name}/test/bin \
-DOPENCV_TEST_DATA_PATH=${prefix}/libexec/${physical_subport_name}/test/data \
-DOPENCV_SAMPLES_BIN_INSTALL_PATH=${prefix}/libexec/${physical_subport_name}/share/samples/bin \
-DOPENCV_SAMPLES_SRC_INSTALL_PATH=${prefix}/libexec/${physical_subport_name}/share/samples/src \
-DOPENCV_OTHER_INSTALL_PATH=${prefix}/libexec/${physical_subport_name}/share/data \
-DOPENCV_DOC_INSTALL_PATH=${prefix}/libexec/${physical_subport_name}/share/doc \
-DOPENCV_LICENSES_INSTALL_PATH=${prefix}/libexec/${physical_subport_name}/share/license \
-DOPENCV_INCLUDE_INSTALL_PATH=${prefix}/include/${physical_subport_name} \
-DOPENCV_LIB_INSTALL_PATH=${prefix}/lib/${physical_subport_name} \
-DOPENCV_3P_LIB_INSTALL_PATH=${prefix}/lib/${physical_subport_name}/3rdparty \
-DOPENCV_LIB_ARCHIVE_INSTALL_PATH=${prefix}/lib/${physical_subport_name}/static \
-DCMAKE_BINARY_DIR=${prefix}/libexec/${physical_subport_name}/bin \
-DCMAKE_INSTALL_LIBEXECDIR=${prefix}/libexec/${physical_subport_name} \
-DCMAKE_INSTALL_BINDIR=${prefix}/libexec/${physical_subport_name}/bin \
-DCMAKE_INSTALL_SBINDIR=${prefix}/libexec/${physical_subport_name}/sbin \
-DCMAKE_INSTALL_SHAREDIR=${prefix}/libexec/${physical_subport_name}/share \
-DCMAKE_INSTALL_INCLUDEDIR=${prefix}/include/${physical_subport_name} \
-DCMAKE_INSTALL_LIBDIR=${prefix}/lib/${physical_subport_name} \
-DCMAKE_INSTALL_NAME_DIR=${prefix}/lib/${physical_subport_name} \
-DCMAKE_INSTALL_RPATH=${prefix}/lib/${physical_subport_name} \
-DOPENCV_CONFIG_INSTALL_PATH=${opencv_install_cmake} \
-DOPENCV_BIN_INSTALL_PATH=${opencv_install_prefix}/bin \
-DOPENCV_SETUPVARS_INSTALL_PATH=${opencv_install_prefix}/scripts \
-DOPENCV_SBIN_INSTALL_PATH=${opencv_install_prefix}/sbin \
-DOPENCV_JAR_INSTALL_PATH=${opencv_install_prefix}/java/jar \
-DOPENCV_JNI_INSTALL_PATH=${opencv_install_prefix}/java/jni \
-DOPENCV_JNI_BIN_INSTALL_PATH=${opencv_install_prefix}/java/jni \
-DOPENCV_TEST_INSTALL_PATH=${opencv_install_prefix}/test/bin \
-DOPENCV_TEST_DATA_PATH=${opencv_install_prefix}/test/data \
-DOPENCV_SAMPLES_BIN_INSTALL_PATH=${opencv_install_prefix}/share/samples/bin \
-DOPENCV_SAMPLES_SRC_INSTALL_PATH=${opencv_install_prefix}/share/samples/src \
-DOPENCV_OTHER_INSTALL_PATH=${opencv_install_prefix}/share/data \
-DOPENCV_DOC_INSTALL_PATH=${opencv_install_prefix}/share/doc \
-DOPENCV_LICENSES_INSTALL_PATH=${opencv_install_prefix}/share/license \
-DOPENCV_INCLUDE_INSTALL_PATH=${opencv_install_include} \
-DOPENCV_LIB_INSTALL_PATH=${opencv_install_lib} \
-DOPENCV_3P_LIB_INSTALL_PATH=${opencv_install_lib}/3rdparty \
-DOPENCV_LIB_ARCHIVE_INSTALL_PATH=${opencv_install_lib}/static \
-DCMAKE_INSTALL_LIBEXECDIR=${opencv_install_prefix} \
-DCMAKE_INSTALL_BINDIR=${opencv_install_prefix}/bin \
-DCMAKE_INSTALL_SBINDIR=${opencv_install_prefix}/sbin \
-DCMAKE_INSTALL_SHAREDIR=${opencv_install_prefix}/share \
-DCMAKE_INSTALL_INCLUDEDIR=${opencv_install_include} \
-DCMAKE_INSTALL_LIBDIR=${opencv_install_lib} \
-DCMAKE_INSTALL_NAME_DIR=${opencv_install_lib} \
\
-DWITH_1394=OFF \
-DWITH_CARBON=OFF \
Expand Down Expand Up @@ -300,9 +324,9 @@ if {[variant_isset universal]} {

foreach python_branch {2.7} {
set python_version [join [lrange [split ${python_branch} .] 0 1] ""]
subport py${python_version}-${physical_subport_name} {
subport py${python_version}-${parent_subport_name} {
depends_lib-append \
port:${physical_subport_name} \
port:${parent_subport_name} \
port:python${python_version} \
port:py${python_version}-numpy
configure.args-replace \
Expand All @@ -324,7 +348,7 @@ foreach python_branch {2.7} {
# Deconflict with parent port contents
post-destroot {
ui_debug "${subport}: python subport: removing files unrelated to Python bindings"
foreach f [exec port contents ${physical_subport_name}] {
foreach f [exec port contents ${parent_subport_name}] {
delete ${destroot}${f}
}
}
Expand All @@ -334,9 +358,9 @@ foreach python_branch {2.7} {
set python_branches {3.5 3.6 3.7 3.8 3.9}
foreach python_branch ${python_branches} {
set python_version [join [lrange [split ${python_branch} .] 0 1] ""]
subport py${python_version}-${physical_subport_name} {
subport py${python_version}-${parent_subport_name} {
depends_lib-append \
port:${physical_subport_name} \
port:${parent_subport_name} \
port:python${python_version} \
port:py${python_version}-numpy
configure.args-replace \
Expand All @@ -354,7 +378,7 @@ foreach python_branch ${python_branches} {
# Deconflict with parent port contents
post-destroot {
ui_debug "${subport}: python subport: removing files unrelated to Python bindings"
foreach f [exec port contents ${physical_subport_name}] {
foreach f [exec port contents ${parent_subport_name}] {
delete ${destroot}${f}
}
}
Expand Down Expand Up @@ -684,34 +708,34 @@ proc opencv_soft_link_binaries {p_bin_main_dir p_bin_port_dir p_destroot p_prefi
proc opencv_post_destroot {} {
global prefix
global destroot
global physical_subport_name
global parent_subport_name

# http://trac.macports.org/ticket/42702
if {[variant_isset qt4] || [variant_isset qt5]} {
reinplace "s|-L//System/Library/Frameworks ||g" \
${destroot}${prefix}/lib/${physical_subport_name}/pkgconfig/opencv.pc
${destroot}${prefix}/lib/${parent_subport_name}/pkgconfig/opencv.pc
reinplace "s|-lOpenGL.framework|-framework OpenGL|g" \
${destroot}${prefix}/lib/${physical_subport_name}/pkgconfig/opencv.pc
${destroot}${prefix}/lib/${parent_subport_name}/pkgconfig/opencv.pc
}

set bin_main_dir \
"${destroot}${prefix}/bin"
set bin_port_dir \
"${destroot}${prefix}/libexec/${physical_subport_name}/bin"
"${destroot}${prefix}/libexec/${parent_subport_name}/bin"

# While the various configure-related options should catch everything, one or more
# files may be missed. If so, ensure they're moved to the subport's bin area.
opencv_move_binaries \
${bin_main_dir} \
${bin_port_dir}

# Create soft links for binaries, each prefixed with '<physical_subport_name>_'.
# Create soft links for binaries, each prefixed with '<parent_subport_name>_'.
opencv_soft_link_binaries \
${bin_main_dir} \
${bin_port_dir} \
${destroot} \
${prefix} \
${physical_subport_name}
${parent_subport_name}
}

post-destroot {
Expand Down
Loading

0 comments on commit 5f1d975

Please sign in to comment.