2008-08-19 14:55:46 -04:00
|
|
|
#!/usr/bin/env ruby
|
2008-08-19 11:01:28 -04:00
|
|
|
require "mkmf"
|
|
|
|
|
2012-07-16 05:32:27 -04:00
|
|
|
def cv_version_suffix(incdir)
|
|
|
|
major, minor, subminor = nil, nil, nil
|
|
|
|
open("#{incdir}/opencv2/core/version.hpp", 'r') { |f|
|
|
|
|
f.read.lines.each { |line|
|
2013-03-24 12:43:31 -04:00
|
|
|
major = $1.to_s if line =~ /\A#define\s+(?:CV_VERSION_EPOCH|CV_MAJOR_VERSION)\s+(\d+)\s*\Z/
|
|
|
|
minor = $1.to_s if line =~ /\A#define\s+(?:CV_VERSION_MAJOR|CV_MINOR_VERSION)\s+(\d+)\s*\Z/
|
|
|
|
subminor = $1.to_s if line =~ /\A#define\s+(?:CV_VERSION_MINOR|CV_SUBMINOR_VERSION)\s+(\d+)\s*\Z/
|
2012-07-16 05:32:27 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
major + minor + subminor
|
|
|
|
end
|
|
|
|
|
2013-03-02 15:26:54 -05:00
|
|
|
# Quick fix for 2.0.0
|
|
|
|
# @libdir_basename is set to nil and dir_config() sets invalid libdir '${opencv-dir}/' when --with-opencv-dir option passed.
|
|
|
|
@libdir_basename ||= 'lib'
|
2012-07-16 04:48:19 -04:00
|
|
|
incdir, libdir = dir_config("opencv", "/usr/local/include", "/usr/local/lib")
|
2010-12-29 14:32:34 -05:00
|
|
|
dir_config("libxml2", "/usr/include", "/usr/lib")
|
|
|
|
|
2011-07-10 11:32:39 -04:00
|
|
|
opencv_headers = ["opencv2/core/core_c.h", "opencv2/core/core.hpp", "opencv2/imgproc/imgproc_c.h",
|
|
|
|
"opencv2/imgproc/imgproc.hpp", "opencv2/video/tracking.hpp", "opencv2/features2d/features2d.hpp",
|
|
|
|
"opencv2/flann/flann.hpp", "opencv2/calib3d/calib3d.hpp", "opencv2/objdetect/objdetect.hpp",
|
|
|
|
"opencv2/legacy/compat.hpp", "opencv2/legacy/legacy.hpp", "opencv2/highgui/highgui_c.h",
|
2012-04-22 09:27:58 -04:00
|
|
|
"opencv2/highgui/highgui.hpp", "opencv2/photo/photo.hpp", "opencv2/nonfree/nonfree.hpp"]
|
2010-12-29 14:32:34 -05:00
|
|
|
|
|
|
|
opencv_libraries = ["opencv_calib3d", "opencv_contrib", "opencv_core", "opencv_features2d",
|
|
|
|
"opencv_flann", "opencv_gpu", "opencv_highgui", "opencv_imgproc",
|
2012-04-22 09:27:58 -04:00
|
|
|
"opencv_legacy", "opencv_ml", "opencv_objdetect", "opencv_video",
|
|
|
|
"opencv_photo", "opencv_nonfree"]
|
2008-08-19 11:01:28 -04:00
|
|
|
|
|
|
|
|
2012-02-04 05:51:21 -05:00
|
|
|
puts ">> Check the required libraries..."
|
2008-08-19 11:01:28 -04:00
|
|
|
case CONFIG["arch"]
|
|
|
|
when /mswin32/
|
2012-07-16 05:32:27 -04:00
|
|
|
suffix = cv_version_suffix(incdir)
|
|
|
|
opencv_libraries.map! {|lib| lib + suffix }
|
2011-11-27 18:31:12 -05:00
|
|
|
have_library("msvcrt")
|
2012-02-04 05:51:21 -05:00
|
|
|
opencv_libraries.each {|lib|
|
2011-12-27 09:47:08 -05:00
|
|
|
raise "#{lib}.lib not found." unless have_library(lib)
|
2008-08-19 11:01:28 -04:00
|
|
|
}
|
2011-11-27 18:31:12 -05:00
|
|
|
$CFLAGS << ' /EHsc'
|
2012-02-04 05:51:21 -05:00
|
|
|
when /mingw32/
|
2012-07-16 05:32:27 -04:00
|
|
|
suffix = cv_version_suffix(incdir)
|
|
|
|
opencv_libraries.map! {|lib| lib + suffix }
|
2012-02-04 05:51:21 -05:00
|
|
|
have_library("msvcrt")
|
|
|
|
opencv_libraries.each {|lib|
|
|
|
|
raise "lib#{lib} not found." unless have_library(lib)
|
|
|
|
}
|
2008-08-19 11:01:28 -04:00
|
|
|
else
|
2012-02-04 05:51:21 -05:00
|
|
|
opencv_libraries.each {|lib|
|
2008-08-19 11:01:28 -04:00
|
|
|
raise "lib#{lib} not found." unless have_library(lib)
|
|
|
|
}
|
|
|
|
have_library("stdc++")
|
|
|
|
end
|
|
|
|
|
2012-02-04 05:51:21 -05:00
|
|
|
# Check the required headers
|
|
|
|
puts ">> Check the required headers..."
|
|
|
|
opencv_headers.each {|header|
|
2012-07-16 04:48:19 -04:00
|
|
|
unless have_header(header)
|
|
|
|
if CONFIG["arch"] =~ /mswin32/ and File.exists? "#{incdir}/#{header}"
|
|
|
|
# In mswin32, have_header('opencv2/nonfree/nonfree.hpp') fails because of a syntax problem.
|
|
|
|
warn "warning: #{header} found but `have_header` failed."
|
|
|
|
$defs << "-DHAVE_#{header.tr_cpp}"
|
|
|
|
else
|
|
|
|
raise "#{header} not found."
|
|
|
|
end
|
|
|
|
end
|
2008-08-19 11:01:28 -04:00
|
|
|
}
|
|
|
|
have_header("stdarg.h")
|
|
|
|
|
2013-03-24 13:32:41 -04:00
|
|
|
if $warnflags
|
|
|
|
$warnflags.slice!('-Wdeclaration-after-statement')
|
|
|
|
$warnflags.slice!('-Wimplicit-function-declaration')
|
|
|
|
end
|
2013-03-02 15:40:33 -05:00
|
|
|
|
2011-05-03 12:32:48 -04:00
|
|
|
# Quick fix for 1.8.7
|
2011-05-04 15:24:21 -04:00
|
|
|
$CFLAGS << " -I#{File.dirname(__FILE__)}/ext/opencv"
|
2011-05-03 12:32:48 -04:00
|
|
|
|
2012-02-04 05:51:21 -05:00
|
|
|
# Create Makefile
|
2013-03-02 12:28:21 -05:00
|
|
|
create_makefile('opencv')
|
2011-05-03 12:32:48 -04:00
|
|
|
|