Using find_package to import custom HAL library
This commit is contained in:
parent
e792ee89de
commit
727743809e
@ -603,29 +603,25 @@ endif()
|
|||||||
include(cmake/OpenCVDetectVTK.cmake)
|
include(cmake/OpenCVDetectVTK.cmake)
|
||||||
|
|
||||||
# -- Custom HAL replacement --
|
# -- Custom HAL replacement --
|
||||||
set(_includes "")
|
# Package config in: OpenCV_HALConfig.cmake or opencv_hal-config.cmake
|
||||||
# assuming OPENCV_HAL_HEADERS and OPENCV_HAL_LIBS are lists of files:
|
# Use variables: OpenCV_HAL_LIBRARIES, OpenCV_HAL_HEADERS and OpenCV_HAL_INCLUDE_DIRS variables
|
||||||
# option example: -DOPENCV_HAL_HEADERS="<some-path>/header1.h;<some-path>/header2.h"
|
find_package(OpenCV_HAL CONFIG QUIET)
|
||||||
if (OPENCV_HAL_HEADERS AND OPENCV_HAL_LIBS)
|
if (OpenCV_HAL_FOUND)
|
||||||
foreach (h ${OPENCV_HAL_HEADERS})
|
# 1. libraries
|
||||||
get_filename_component(h "${h}" ABSOLUTE)
|
foreach (l ${OpenCV_HAL_LIBRARIES})
|
||||||
set(_includes "${_includes}\n#include \"${h}\"")
|
|
||||||
endforeach()
|
|
||||||
foreach (l ${OPENCV_HAL_LIBS})
|
|
||||||
get_filename_component(l "${l}" ABSOLUTE)
|
get_filename_component(l "${l}" ABSOLUTE)
|
||||||
set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${l})
|
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()
|
endforeach()
|
||||||
else()
|
# 2. headers
|
||||||
set(_includes "// using default HAL")
|
set(_includes "")
|
||||||
unset(OPENCV_HAL_HEADERS CACHE)
|
foreach (h ${OpenCV_HAL_HEADERS})
|
||||||
unset(OPENCV_HAL_LIBS CACHE)
|
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()
|
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")
|
|
||||||
configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/custom_hal.hpp.in" "${CMAKE_BINARY_DIR}/custom_hal.hpp" @ONLY)
|
|
||||||
unset(_includes)
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
# Add CUDA libraries (needed for apps/tools, samples)
|
# 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 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 Cuda:" HAVE_CUDA THEN "YES (ver ${CUDA_VERSION_STRING})" ELSE NO)
|
||||||
status(" Use OpenCL:" HAVE_OPENCL THEN YES 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)
|
if(HAVE_CUDA)
|
||||||
status("")
|
status("")
|
||||||
|
@ -23,8 +23,7 @@ Build OpenCV with HAL replacement
|
|||||||
2. Go to the created folder and run cmake:
|
2. Go to the created folder and run cmake:
|
||||||
```
|
```
|
||||||
cmake \
|
cmake \
|
||||||
-DOPENCV_HAL_HEADERS="<opencv-src>/samples/hal/slow_hal/impl.hpp" \
|
-DOpenCV_HAL_DIR="<home-dir>/my-hal-build/" \
|
||||||
-DOPENCV_HAL_LIBS="<home-dir>/my-hal-build/libslow_hal.a" \
|
|
||||||
<opencv-src>
|
<opencv-src>
|
||||||
```
|
```
|
||||||
3. Run make (or `make opencv_perf_core` to build the demonstration test executable only)
|
3. Run make (or `make opencv_perf_core` to build the demonstration test executable only)
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
cmake_minimum_required(VERSION 2.8.8 FATAL_ERROR)
|
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)
|
add_library(c_hal impl.c)
|
||||||
|
set_target_properties(c_hal PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
|
||||||
set(OPENCV_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../..")
|
set(OPENCV_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../..")
|
||||||
target_include_directories(c_hal PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${OPENCV_SRC_DIR}/modules/core/include)
|
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)
|
||||||
|
5
samples/hal/c_hal/config.cmake
Normal file
5
samples/hal/c_hal/config.cmake
Normal 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}")
|
@ -1,11 +1,9 @@
|
|||||||
cmake_minimum_required(VERSION 2.8.8 FATAL_ERROR)
|
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)
|
add_library(slow_hal impl.cpp)
|
||||||
|
set_target_properties(slow_hal PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
|
||||||
set(OPENCV_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../..")
|
set(OPENCV_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../..")
|
||||||
target_include_directories(slow_hal PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${OPENCV_SRC_DIR}/modules/core/include)
|
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)
|
||||||
|
5
samples/hal/slow_hal/config.cmake
Normal file
5
samples/hal/slow_hal/config.cmake
Normal 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}")
|
Loading…
Reference in New Issue
Block a user