Skip to content

Instantly share code, notes, and snippets.

@AhiyaHiya
Created June 23, 2019 18:57
Show Gist options
  • Save AhiyaHiya/f950dfae0e8b2ce642fa4538e37fe773 to your computer and use it in GitHub Desktop.
Save AhiyaHiya/f950dfae0e8b2ce642fa4538e37fe773 to your computer and use it in GitHub Desktop.
Creates makefile for OpenCV, macOS, using CMake at the command line. Also builds project using make with j option.
#!/usr/bin/env bash
# 2019-06-23
# Jaime O. Rios
# Script modeled after Homebrew Formula for OpenCV
# https://github.com/Homebrew/homebrew-core/blob/master/Formula/opencv.rb
set -o errexit
set -o nounset
set -o pipefail
#set -o xtrace
py2_prefix=$(python2-config --prefix)
py2_lib="${py2_prefix}/lib"
py3_config=$(python3-config --configdir)
py3_include=$(python3 -c "import distutils.sysconfig as s; print(s.get_python_inc())")
py3_version="3.7.3"
buildpath=$PWD/build
cmake $HOME/Development/GitHub/OpenCV \
-DCMAKE_OSX_DEPLOYMENT_TARGET= \
-DCMAKE_INSTALL_PREFIX:PATH=${buildpath}/install \
-DBUILD_JASPER=OFF \
-DBUILD_JPEG=ON \
-DBUILD_OPENEXR=OFF \
-DBUILD_PERF_TESTS=OFF \
-DBUILD_PNG=OFF \
-DBUILD_TESTS=ON \
-DBUILD_TIFF=OFF \
-DBUILD_ZLIB=OFF \
-DBUILD_opencv_hdf=OFF \
-DBUILD_opencv_java=OFF \
-DBUILD_opencv_text=ON \
-DOPENCV_ENABLE_NONFREE=ON \
-DOPENCV_GENERATE_PKGCONFIG=ON \
-DWITH_1394=OFF \
-DWITH_CUDA=OFF \
-DWITH_EIGEN=ON \
-DWITH_FFMPEG=ON \
-DWITH_GPHOTO2=OFF \
-DWITH_GSTREAMER=OFF \
-DWITH_JASPER=OFF \
-DWITH_OPENEXR=ON \
-DWITH_OPENGL=OFF \
-DWITH_QT=OFF \
-DWITH_TBB=ON \
-DWITH_VTK=OFF \
-DBUILD_opencv_python2=ON \
-DBUILD_opencv_python3=ON \
-DPYTHON2_EXECUTABLE=$(which "python") \
-DPYTHON2_LIBRARY=$py2_lib/libpython2.7.dylib \
-DPYTHON2_INCLUDE_DIR=$py2_prefix/include/python2.7 \
-DPYTHON3_EXECUTABLE=$(which "python3") \
-DPYTHON3_LIBRARY=$py3_config/libpython${py3_version}.dylib \
-DPYTHON3_INCLUDE_DIR=$py3_include \
-DCPU_DISPATCH=SSE4_1,SSE4_2,AVX
# -DBUILD_TESTS=OFF \
make -j$(getconf _NPROCESSORS_ONLN)
@jps05
Copy link

jps05 commented Oct 11, 2021

How do you use this script in combination with your setup_opencv_macos.sh?
I have probably the same issue as compiling openCV fails by using your setup_opencv_macos.sh.

@AhiyaHiya
Copy link
Author

This script effectively replaces that older shell script. What issues are you getting when you build OpenCV in your environment @jps05 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment