diff --git a/CMakeLists.txt b/CMakeLists.txt index 23f243ed4e..aff75155c3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -603,27 +603,23 @@ endif() include(cmake/OpenCVDetectVTK.cmake) # -- Custom HAL replacement -- +# 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) set(_includes "") -# assuming OPENCV_HAL_HEADERS and OPENCV_HAL_LIBS are lists of files: -# option example: -DOPENCV_HAL_HEADERS="/header1.h;/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}) +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) + # 2. headers + foreach (h ${OpenCV_HAL_HEADERS}) + set(_includes "${_includes}\n#include \"${h}\"") + endforeach() + # 3. include paths + ocv_include_directories(${OpenCV_HAL_INCLUDE_DIRS}) 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) @@ -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("") diff --git a/samples/hal/README.md b/samples/hal/README.md index c48eda40ba..8e0528331d 100644 --- a/samples/hal/README.md +++ b/samples/hal/README.md @@ -23,8 +23,7 @@ Build OpenCV with HAL replacement 2. Go to the created folder and run cmake: ``` cmake \ - -DOPENCV_HAL_HEADERS="/samples/hal/slow_hal/impl.hpp" \ - -DOPENCV_HAL_LIBS="/my-hal-build/libslow_hal.a" \ + -DOpenCV_HAL_DIR="/my-hal-build/" \ ``` 3. Run make (or `make opencv_perf_core` to build the demonstration test executable only) diff --git a/samples/hal/c_hal/CMakeLists.txt b/samples/hal/c_hal/CMakeLists.txt index 51ebcee267..b8996bb933 100644 --- a/samples/hal/c_hal/CMakeLists.txt +++ b/samples/hal/c_hal/CMakeLists.txt @@ -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) diff --git a/samples/hal/c_hal/config.cmake b/samples/hal/c_hal/config.cmake new file mode 100644 index 0000000000..11fe9f26c2 --- /dev/null +++ b/samples/hal/c_hal/config.cmake @@ -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}") diff --git a/samples/hal/slow_hal/CMakeLists.txt b/samples/hal/slow_hal/CMakeLists.txt index d001c42478..51aa70e361 100644 --- a/samples/hal/slow_hal/CMakeLists.txt +++ b/samples/hal/slow_hal/CMakeLists.txt @@ -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) diff --git a/samples/hal/slow_hal/config.cmake b/samples/hal/slow_hal/config.cmake new file mode 100644 index 0000000000..e901a7dc88 --- /dev/null +++ b/samples/hal/slow_hal/config.cmake @@ -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}")