Skip to content

Commit 16368a2

Browse files
dkurtvpisarev
authored andcommitted
cmake: add Halide support (opencv#8794)
1 parent 5f20e80 commit 16368a2

File tree

5 files changed

+72
-3
lines changed

5 files changed

+72
-3
lines changed

CMakeLists.txt

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ endif()
112112

113113
include(cmake/OpenCVUtils.cmake)
114114

115+
if(OPENCV_CXX11)
116+
#cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
117+
set(CMAKE_CXX_STANDARD 11)
118+
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
119+
endif()
120+
115121
# must go before the project command
116122
ocv_update(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "Configs" FORCE)
117123
if(DEFINED CMAKE_BUILD_TYPE)
@@ -212,6 +218,7 @@ OCV_OPTION(WITH_GSTREAMER_0_10 "Enable Gstreamer 0.10 support (instead of 1.x)"
212218
OCV_OPTION(WITH_GTK "Include GTK support" ON IF (UNIX AND NOT APPLE AND NOT ANDROID) )
213219
OCV_OPTION(WITH_GTK_2_X "Use GTK version 2" OFF IF (UNIX AND NOT APPLE AND NOT ANDROID) )
214220
OCV_OPTION(WITH_IPP "Include Intel IPP support" NOT MINGW IF (X86_64 OR X86) AND NOT WINRT )
221+
OCV_OPTION(WITH_HALIDE "Include Halide support" OFF)
215222
OCV_OPTION(WITH_JASPER "Include JPEG2K support" ON IF (NOT IOS) )
216223
OCV_OPTION(WITH_JPEG "Include JPEG support" ON)
217224
OCV_OPTION(WITH_WEBP "Include WebP support" ON IF (NOT WINRT) )
@@ -295,6 +302,7 @@ OCV_OPTION(INSTALL_TESTS "Install accuracy and performance test binar
295302

296303
# OpenCV build options
297304
# ===================================================
305+
OCV_OPTION(OPENCV_CXX11 "Enable C++11 compilation mode" OFF )
298306
OCV_OPTION(ENABLE_CCACHE "Use ccache" (UNIX AND NOT IOS AND (CMAKE_GENERATOR MATCHES "Makefile" OR CMAKE_GENERATOR MATCHES "Ninja")) )
299307
OCV_OPTION(ENABLE_PRECOMPILED_HEADERS "Use precompiled headers" ON IF (NOT IOS AND NOT CMAKE_CROSSCOMPILING) )
300308
OCV_OPTION(ENABLE_SOLUTION_FOLDERS "Solution folder in Visual Studio or in other IDEs" (MSVC_IDE OR CMAKE_GENERATOR MATCHES Xcode) )
@@ -623,6 +631,11 @@ if(WITH_OPENCL)
623631
include(cmake/OpenCVDetectOpenCL.cmake)
624632
endif()
625633

634+
# --- Halide ---
635+
if(WITH_HALIDE)
636+
include(cmake/OpenCVDetectHalide.cmake)
637+
endif()
638+
626639
# --- DirectX ---
627640
if(WITH_DIRECTX)
628641
include(cmake/OpenCVDetectDirectX.cmake)
@@ -768,7 +781,9 @@ endif()
768781
include(cmake/OpenCVGenHeaders.cmake)
769782

770783
# Generate opencv.pc for pkg-config command
771-
include(cmake/OpenCVGenPkgconfig.cmake)
784+
if(NOT OPENCV_SKIP_PKGCONFIG_GENERATION)
785+
include(cmake/OpenCVGenPkgconfig.cmake)
786+
endif()
772787

773788
# Generate OpenCV.mk for ndk-build (Android build tool)
774789
include(cmake/OpenCVGenAndroidMK.cmake)
@@ -934,6 +949,9 @@ string(STRIP "${OPENCV_COMPILER_STR}" OPENCV_COMPILER_STR)
934949
status("")
935950
status(" C/C++:")
936951
status(" Built as dynamic libs?:" BUILD_SHARED_LIBS THEN YES ELSE NO)
952+
if(OPENCV_CXX11)
953+
status(" C++11:" "YES")
954+
endif()
937955
status(" C++ Compiler:" ${OPENCV_COMPILER_STR})
938956
status(" C++ flags (Release):" ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE})
939957
status(" C++ flags (Debug):" ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG})
@@ -1302,6 +1320,9 @@ endif(DEFINED WITH_LAPACK)
13021320
status(" Use Eigen:" HAVE_EIGEN THEN "YES (ver ${EIGEN_WORLD_VERSION}.${EIGEN_MAJOR_VERSION}.${EIGEN_MINOR_VERSION})" ELSE NO)
13031321
status(" Use Cuda:" HAVE_CUDA THEN "YES (ver ${CUDA_VERSION_STRING})" ELSE NO)
13041322
status(" Use OpenCL:" HAVE_OPENCL THEN YES ELSE NO)
1323+
if(WITH_HALIDE OR HAVE_HALIDE)
1324+
status(" Use Halide:" HAVE_HALIDE THEN "YES (${HALIDE_LIBRARIES} ${HALIDE_INCLUDE_DIRS})" ELSE NO)
1325+
endif()
13051326
status(" Use OpenVX:" HAVE_OPENVX THEN "YES (${OPENVX_LIBRARIES})" ELSE "NO")
13061327
status(" Use custom HAL:" OpenCV_USED_HAL THEN "YES (${OpenCV_USED_HAL})" ELSE "NO")
13071328

cmake/OpenCVDetectHalide.cmake

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
cmake_minimum_required(VERSION 3.1)
2+
3+
if(" ${HALIDE_ROOT_DIR}" STREQUAL " ")
4+
unset(HALIDE_ROOT_DIR CACHE)
5+
endif()
6+
ocv_check_environment_variables(HALIDE_ROOT_DIR)
7+
set(HALIDE_ROOT_DIR "${HALIDE_ROOT_DIR}" CACHE PATH "Halide root directory")
8+
9+
if(NOT HAVE_HALIDE)
10+
find_package(Halide QUIET) # Try CMake-based config files
11+
if(Halide_FOUND)
12+
set(HALIDE_INCLUDE_DIRS "${Halide_INCLUDE_DIRS}" CACHE PATH "Halide include directories" FORCE)
13+
set(HALIDE_LIBRARIES "${Halide_LIBRARIES}" CACHE PATH "Halide libraries" FORCE)
14+
set(HAVE_HALIDE TRUE)
15+
endif()
16+
endif()
17+
18+
if(NOT HAVE_HALIDE AND HALIDE_ROOT_DIR)
19+
# Try manual search
20+
find_library(HALIDE_LIBRARY
21+
NAMES Halide
22+
HINTS ${HALIDE_ROOT_DIR}/lib # Unix
23+
HINTS ${HALIDE_ROOT_DIR}/lib/Release # Win32
24+
)
25+
find_path(HALIDE_INCLUDE_DIR
26+
NAMES Halide.h HalideRuntime.h
27+
HINTS ${HALIDE_ROOT_DIR}/include
28+
)
29+
if(HALIDE_LIBRARY AND HALIDE_INCLUDE_DIR)
30+
# TODO try_compile
31+
set(HALIDE_INCLUDE_DIRS "${HALIDE_INCLUDE_DIR}" CACHE PATH "Halide include directories" FORCE)
32+
set(HALIDE_LIBRARIES "${HALIDE_LIBRARY}" CACHE PATH "Halide libraries" FORCE)
33+
set(HAVE_HALIDE TRUE)
34+
endif()
35+
if(NOT HAVE_HALIDE)
36+
ocv_clear_vars(HALIDE_LIBRARIES HALIDE_INCLUDE_DIRS CACHE)
37+
endif()
38+
endif()
39+
40+
if(HAVE_HALIDE)
41+
include_directories(${HALIDE_INCLUDE_DIRS})
42+
list(APPEND OPENCV_LINKER_LIBS ${HALIDE_LIBRARIES})
43+
else()
44+
ocv_clear_vars(HALIDE_INCLUDE_DIRS HALIDE_LIBRARIES)
45+
endif()

cmake/OpenCVUtils.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ endmacro()
7979

8080
macro(ocv_check_environment_variables)
8181
foreach(_var ${ARGN})
82-
if(NOT DEFINED ${_var} AND DEFINED ENV{${_var}})
82+
if(" ${${_var}}" STREQUAL " " AND DEFINED ENV{${_var}})
8383
set(__value "$ENV{${_var}}")
8484
file(TO_CMAKE_PATH "${__value}" __value) # Assume that we receive paths
8585
set(${_var} "${__value}")

cmake/templates/cvconfig.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@
9292
/* GTK+ 2.x toolkit */
9393
#cmakedefine HAVE_GTK
9494

95+
/* Halide support */
96+
#cmakedefine HAVE_HALIDE
97+
9598
/* Define to 1 if you have the <inttypes.h> header file. */
9699
#cmakedefine HAVE_INTTYPES_H 1
97100

modules/core/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ ocv_glob_module_sources(SOURCES "${OPENCV_MODULE_opencv_core_BINARY_DIR}/version
3535
ocv_module_include_directories(${the_module} ${ZLIB_INCLUDE_DIRS} ${OPENCL_INCLUDE_DIRS} ${CPUFEATURES_INCLUDE_DIRS})
3636
ocv_create_module(${extra_libs})
3737

38-
ocv_target_link_libraries(${the_module} ${ZLIB_LIBRARIES} "${OPENCL_LIBRARIES}" "${VA_LIBRARIES}" "${LAPACK_LIBRARIES}" "${CPUFEATURES_LIBRARIES}")
38+
ocv_target_link_libraries(${the_module} ${ZLIB_LIBRARIES} "${OPENCL_LIBRARIES}" "${VA_LIBRARIES}" "${LAPACK_LIBRARIES}" "${CPUFEATURES_LIBRARIES}" "${HALIDE_LIBRARIES}")
3939

4040
ocv_add_accuracy_tests()
4141
ocv_add_perf_tests()

0 commit comments

Comments
 (0)