From f4ebc504d1c31e5b3da77df5128c5b3bdd25ab06 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Wed, 15 Jun 2016 15:51:19 +0300 Subject: [PATCH] cmake: refactor HAL attaching process --- CMakeLists.txt | 44 +++++++++++++++++++++---------- cmake/OpenCVUtils.cmake | 1 + cmake/templates/custom_hal.hpp.in | 2 +- modules/core/CMakeLists.txt | 2 +- 4 files changed, 33 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f0085b6c8..04ace8fdc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -602,26 +602,42 @@ 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 NO_MODULE QUIET) -set(_includes "") -if (OpenCV_HAL_FOUND) + +# ---------------------------------------------------------------------------- +# OpenCV HAL +# ---------------------------------------------------------------------------- +set(_hal_includes "") +macro(ocv_hal_register HAL_LIBRARIES_VAR HAL_HEADERS_VAR HAL_INCLUDE_DIRS_VAR) # 1. libraries - foreach (l ${OpenCV_HAL_LIBRARIES}) - get_filename_component(l "${l}" ABSOLUTE) - set(OPENCV_LINKER_LIBS ${OPENCV_LINKER_LIBS} ${l}) + foreach (l ${${HAL_LIBRARIES_VAR}}) + if(NOT TARGET ${l}) + get_filename_component(l "${l}" ABSOLUTE) + endif() + list(APPEND OPENCV_HAL_LINKER_LIBS ${l}) endforeach() # 2. headers - foreach (h ${OpenCV_HAL_HEADERS}) - set(_includes "${_includes}\n#include \"${h}\"") + foreach (h ${${HAL_HEADERS_VAR}}) + set(_hal_includes "${_hal_includes}\n#include \"${h}\"") endforeach() # 3. include paths - ocv_include_directories(${OpenCV_HAL_INCLUDE_DIRS}) + ocv_include_directories(${${HAL_INCLUDE_DIRS_VAR}}) +endmacro() + +if(NOT DEFINED OpenCV_HAL) + set(OpenCV_HAL "OpenCV_HAL") endif() +foreach(hal ${OpenCV_HAL}) + ocv_debug_message(STATUS "OpenCV HAL: ${hal} ...") + ocv_clear_vars(OpenCV_HAL_LIBRARIES OpenCV_HAL_HEADERS OpenCV_HAL_INCLUDE_DIRS) + find_package(${hal} NO_MODULE QUIET) + if(${hal}_FOUND) + ocv_hal_register(OpenCV_HAL_LIBRARIES OpenCV_HAL_HEADERS OpenCV_HAL_INCLUDE_DIRS) + list(APPEND OpenCV_USED_HAL "${hal} (ver ${${hal}_VERSION})") + endif() +endforeach() configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/custom_hal.hpp.in" "${CMAKE_BINARY_DIR}/custom_hal.hpp" @ONLY) -unset(_includes) +unset(_hal_includes) + # ---------------------------------------------------------------------------- # Add CUDA libraries (needed for apps/tools, samples) @@ -1160,7 +1176,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_FOUND THEN "YES (ver ${OpenCV_HAL_VERSION}, ${OpenCV_HAL_CONFIG})" ELSE "NO") +status(" Use custom HAL:" OpenCV_USED_HAL THEN "YES (${OpenCV_USED_HAL})" ELSE "NO") if(HAVE_CUDA) status("") diff --git a/cmake/OpenCVUtils.cmake b/cmake/OpenCVUtils.cmake index 735b94f52..a17e25548 100644 --- a/cmake/OpenCVUtils.cmake +++ b/cmake/OpenCVUtils.cmake @@ -126,6 +126,7 @@ endfunction() # clears all passed variables macro(ocv_clear_vars) foreach(_var ${ARGN}) + unset(${_var}) unset(${_var} CACHE) endforeach() endmacro() diff --git a/cmake/templates/custom_hal.hpp.in b/cmake/templates/custom_hal.hpp.in index f1c651595..c62f17dac 100644 --- a/cmake/templates/custom_hal.hpp.in +++ b/cmake/templates/custom_hal.hpp.in @@ -1,6 +1,6 @@ #ifndef _CUSTOM_HAL_INCLUDED_ #define _CUSTOM_HAL_INCLUDED_ -@_includes@ +@_hal_includes@ #endif diff --git a/modules/core/CMakeLists.txt b/modules/core/CMakeLists.txt index 8a68c9028..171fa9b08 100644 --- a/modules/core/CMakeLists.txt +++ b/modules/core/CMakeLists.txt @@ -1,6 +1,6 @@ set(the_description "The Core Functionality") ocv_add_module(core - PRIVATE_REQUIRED ${ZLIB_LIBRARIES} "${OPENCL_LIBRARIES}" "${VA_LIBRARIES}" + PRIVATE_REQUIRED ${ZLIB_LIBRARIES} "${OPENCL_LIBRARIES}" "${VA_LIBRARIES}" "${OPENCV_HAL_LINKER_LIBS}" OPTIONAL opencv_cudev WRAP java python)