Using find_package to import custom HAL library

This commit is contained in:
Maksim Shabunin 2016-03-24 17:05:54 +03:00
parent e792ee89de
commit 727743809e
6 changed files with 35 additions and 34 deletions

View File

@ -603,29 +603,25 @@ endif()
include(cmake/OpenCVDetectVTK.cmake)
# -- Custom HAL replacement --
set(_includes "")
# assuming OPENCV_HAL_HEADERS and OPENCV_HAL_LIBS are lists of files:
# option example: -DOPENCV_HAL_HEADERS="<some-path>/header1.h;<some-path>/header2.h"
if (OPENCV_HAL_HEADERS AND OPENCV_HAL_LIBS)
foreach (h ${OPENCV_HAL_HEADERS})
get_filename_component(h "${h}" ABSOLUTE)
set(_includes "${_includes}\n#include \"${h}\"")
endforeach()
foreach (l ${OPENCV_HAL_LIBS})
# Package config in: OpenCV_HALConfig.cmake or opencv_hal-config.cmake
# Use variables: OpenCV_HAL_LIBRARIES, OpenCV_HAL_HEADERS and OpenCV_HAL_INCLUDE_DIRS variables
find_package(OpenCV_HAL CONFIG QUIET)
if (OpenCV_HAL_FOUND)
# 1. libraries
foreach (l ${OpenCV_HAL_LIBRARIES})
get_filename_component(l "${l}" ABSOLUTE)
set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${l})
# TODO: install?
# ocv_install_target(${l} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev)
endforeach()
else()
set(_includes "// using default HAL")
unset(OPENCV_HAL_HEADERS CACHE)
unset(OPENCV_HAL_LIBS CACHE)
endif()
set(OPENCV_HAL_HEADERS "${OPENCV_HAL_HEADERS}" CACHE STRING "Headers with custom HAL implementation")
set(OPENCV_HAL_LIBS "${OPENCV_HAL_LIBS}" CACHE STRING "Libraries with custom HAL implementation")
# 2. headers
set(_includes "")
foreach (h ${OpenCV_HAL_HEADERS})
set(_includes "${_includes}\n#include \"${h}\"")
endforeach()
configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/custom_hal.hpp.in" "${CMAKE_BINARY_DIR}/custom_hal.hpp" @ONLY)
unset(_includes)
# 3. include paths
ocv_include_directories(${OpenCV_HAL_INCLUDE_DIRS})
endif()
# ----------------------------------------------------------------------------
# Add CUDA libraries (needed for apps/tools, samples)
@ -1164,7 +1160,7 @@ endif(DEFINED WITH_VA_INTEL)
status(" Use Eigen:" HAVE_EIGEN THEN "YES (ver ${EIGEN_WORLD_VERSION}.${EIGEN_MAJOR_VERSION}.${EIGEN_MINOR_VERSION})" ELSE NO)
status(" Use Cuda:" HAVE_CUDA THEN "YES (ver ${CUDA_VERSION_STRING})" ELSE NO)
status(" Use OpenCL:" HAVE_OPENCL THEN YES ELSE NO)
status(" Use custom HAL:" OPENCV_HAL_HEADERS AND OPENCV_HAL_LIBS THEN "YES (${OPENCV_HAL_HEADERS}; ${OPENCV_HAL_LIBS})" ELSE "NO")
status(" Use custom HAL:" OpenCV_HAL_FOUND THEN "YES (ver ${OpenCV_HAL_VERSION}, ${OpenCV_HAL_CONFIG})" ELSE "NO")
if(HAVE_CUDA)
status("")

View File

@ -23,8 +23,7 @@ Build OpenCV with HAL replacement
2. Go to the created folder and run cmake:
```
cmake \
-DOPENCV_HAL_HEADERS="<opencv-src>/samples/hal/slow_hal/impl.hpp" \
-DOPENCV_HAL_LIBS="<home-dir>/my-hal-build/libslow_hal.a" \
-DOpenCV_HAL_DIR="<home-dir>/my-hal-build/" \
<opencv-src>
```
3. Run make (or `make opencv_perf_core` to build the demonstration test executable only)

View File

@ -1,11 +1,9 @@
cmake_minimum_required(VERSION 2.8.8 FATAL_ERROR)
if(UNIX)
if(CMAKE_COMPILER_IS_GNUC OR CV_ICC)
set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
endif()
endif()
add_library(c_hal impl.c)
set_target_properties(c_hal PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
set(OPENCV_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../..")
target_include_directories(c_hal PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${OPENCV_SRC_DIR}/modules/core/include)
configure_file("impl.h" "${CMAKE_BINARY_DIR}/impl.h" COPYONLY)
configure_file("config.cmake" "${CMAKE_BINARY_DIR}/OpenCV_HALConfig.cmake" COPYONLY)

View File

@ -0,0 +1,5 @@
set(OpenCV_HAL_FOUND TRUE)
set(OpenCV_HAL_VERSION "0.0.1")
set(OpenCV_HAL_LIBRARIES "${CMAKE_CURRENT_LIST_DIR}/libc_hal.a")
set(OpenCV_HAL_HEADERS "impl.h")
set(OpenCV_HAL_INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}")

View File

@ -1,11 +1,9 @@
cmake_minimum_required(VERSION 2.8.8 FATAL_ERROR)
if(UNIX)
if(CMAKE_COMPILER_IS_GNUCXX OR CV_ICC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
endif()
endif()
add_library(slow_hal impl.cpp)
set_target_properties(slow_hal PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
set(OPENCV_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../..")
target_include_directories(slow_hal PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${OPENCV_SRC_DIR}/modules/core/include)
configure_file("impl.hpp" "${CMAKE_BINARY_DIR}/impl.hpp" COPYONLY)
configure_file("config.cmake" "${CMAKE_BINARY_DIR}/OpenCV_HALConfig.cmake" COPYONLY)

View File

@ -0,0 +1,5 @@
set(OpenCV_HAL_FOUND TRUE)
set(OpenCV_HAL_VERSION "0.0.1")
set(OpenCV_HAL_LIBRARIES "${CMAKE_CURRENT_LIST_DIR}/libslow_hal.a")
set(OpenCV_HAL_HEADERS "impl.hpp")
set(OpenCV_HAL_INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}")