Refactored OpenCVConfig.cmake generation code.

This commit is contained in:
Andrey Kamaev 2012-02-19 21:30:13 +00:00
parent f83aa74bc4
commit 4f97b20ff6
2 changed files with 65 additions and 66 deletions

View File

@ -6,21 +6,27 @@
# -------------------------------------------------------------------------------------------
if(INSTALL_TO_MANGLED_PATHS)
set(OpenCV_USE_MANGLED_PATHS TRUE)
set(OpenCV_USE_MANGLED_PATHS_CONFIGCMAKE TRUE)
else()
set(OpenCV_USE_MANGLED_PATHS FALSE)
set(OpenCV_USE_MANGLED_PATHS_CONFIGCMAKE FALSE)
endif()
if(NOT OpenCV_CUDA_CC)
set(OpenCV_CUDA_CC_CONFIGMAKE "\"\"")
set(OpenCV_CUDA_CC_CONFIGCMAKE "\"\"")
else()
set(OpenCV_CUDA_CC_CONFIGMAKE "${OpenCV_CUDA_CC}")
set(OpenCV_CUDA_CC_CONFIGCMAKE "${OpenCV_CUDA_CC}")
endif()
if(NOT ANDROID_NATIVE_API_LEVEL)
set(OpenCV_ANDROID_NATIVE_API_LEVEL_CONFIGMAKE 0)
set(OpenCV_ANDROID_NATIVE_API_LEVEL_CONFIGCMAKE 0)
else()
set(OpenCV_ANDROID_NATIVE_API_LEVEL_CONFIGMAKE "${ANDROID_NATIVE_API_LEVEL}")
set(OpenCV_ANDROID_NATIVE_API_LEVEL_CONFIGCMAKE "${ANDROID_NATIVE_API_LEVEL}")
endif()
if(MSVC OR CMAKE_GENERATOR MATCHES Xcode)
set(OpenCV_ADD_DEBUG_RELEASE_CONFIGCMAKE TRUE)
else()
set(OpenCV_ADD_DEBUG_RELEASE_CONFIGCMAKE FALSE)
endif()
@ -30,25 +36,25 @@ foreach(m ${OPENCV_MODULES_PUBLIC})
list(INSERT OpenCV_LIB_COMPONENTS 0 ${${m}_MODULE_DEPS_OPT} ${m})
endforeach()
ocv_list_unique(OpenCV_LIB_COMPONENTS)
set(OPENCV_MODULES_CONFIGMAKE ${OpenCV_LIB_COMPONENTS})
set(OPENCV_MODULES_CONFIGCMAKE ${OpenCV_LIB_COMPONENTS})
ocv_list_filterout(OpenCV_LIB_COMPONENTS "^opencv_")
if(OpenCV_LIB_COMPONENTS)
list(REMOVE_ITEM OPENCV_MODULES_CONFIGMAKE ${OpenCV_LIB_COMPONENTS})
list(REMOVE_ITEM OPENCV_MODULES_CONFIGCMAKE ${OpenCV_LIB_COMPONENTS})
endif()
macro(ocv_generate_dependencies_map_configmake suffix configuration)
macro(ocv_generate_dependencies_map_configcmake suffix configuration)
set(OPENCV_DEPENDENCIES_MAP_${suffix} "")
set(OPENCV_PROCESSED_LIBS "")
set(OPENCV_LIBS_TO_PROCESS ${OPENCV_MODULES_CONFIGMAKE})
set(OPENCV_LIBS_TO_PROCESS ${OPENCV_MODULES_CONFIGCMAKE})
while(OPENCV_LIBS_TO_PROCESS)
list(GET OPENCV_LIBS_TO_PROCESS 0 __ocv_lib)
get_target_property(__libname ${__ocv_lib} LOCATION_${configuration})
get_filename_component(__libname "${__libname}" NAME)
if(WIN32)
string(REGEX REPLACE "${CMAKE_SHARED_LIBRARY_SUFFIX}$" "${CMAKE_LINK_LIBRARY_SUFFIX}" __libname "${__libname}")
endif()
set(OPENCV_DEPENDENCIES_MAP_${suffix} "${OPENCV_DEPENDENCIES_MAP_${suffix}}set(OpenCV_${__ocv_lib}_LIBNAME_${suffix} \"${__libname}\")\n")
set(OPENCV_DEPENDENCIES_MAP_${suffix} "${OPENCV_DEPENDENCIES_MAP_${suffix}}set(OpenCV_${__ocv_lib}_DEPS_${suffix} ${${__ocv_lib}_MODULE_DEPS_${suffix}})\n")
set(OPENCV_DEPENDENCIES_MAP_${suffix} "${OPENCV_DEPENDENCIES_MAP_${suffix}}set(OpenCV_${__ocv_lib}_EXTRA_DEPS_${suffix} ${${__ocv_lib}_EXTRA_DEPS_${suffix}})\n")
@ -63,49 +69,48 @@ macro(ocv_generate_dependencies_map_configmake suffix configuration)
unset(__libname)
endmacro()
ocv_generate_dependencies_map_configmake(OPT Release)
ocv_generate_dependencies_map_configmake(DBG Debug)
ocv_generate_dependencies_map_configcmake(OPT Release)
ocv_generate_dependencies_map_configcmake(DBG Debug)
# -------------------------------------------------------------------------------------------
# Part 1/3: ${BIN_DIR}/OpenCVConfig.cmake -> For use *without* "make install"
# -------------------------------------------------------------------------------------------
set(CMAKE_INCLUDE_DIRS_CONFIGCMAKE "\"${OPENCV_CONFIG_FILE_INCLUDE_DIR}\" \"${OpenCV_SOURCE_DIR}/include\" \"${OpenCV_SOURCE_DIR}/include/opencv\"")
set(CMAKE_LIB_DIRS_CONFIGCMAKE "\"${LIBRARY_OUTPUT_PATH}\"")
set(CMAKE_3RDPARTY_LIB_DIRS_CONFIGCMAKE "\"${CMAKE_BINARY_DIR}/3rdparty/${OPENCV_LIB_INSTALL_PATH}\"")
set(OpenCV_INCLUDE_DIRS_CONFIGCMAKE "\"${OPENCV_CONFIG_FILE_INCLUDE_DIR}\" \"${OpenCV_SOURCE_DIR}/include\" \"${OpenCV_SOURCE_DIR}/include/opencv\"")
set(OpenCV_LIB_DIRS_CONFIGCMAKE "\"${LIBRARY_OUTPUT_PATH}\"")
set(OpenCV_3RDPARTY_LIB_DIRS_CONFIGCMAKE "\"${CMAKE_BINARY_DIR}/3rdparty/${OPENCV_LIB_INSTALL_PATH}\"")
#set(CMAKE_OPENCV2_INCLUDE_DIRS_CONFIGCMAKE "${OpenCV_SOURCE_DIR}")
set(CMAKE_OPENCV2_INCLUDE_DIRS_CONFIGCMAKE "")
set(OpenCV2_INCLUDE_DIRS_CONFIGCMAKE "")
foreach(m ${OPENCV_MODULES_BUILD})
if(EXISTS "${OPENCV_MODULE_${m}_LOCATION}/include")
list(APPEND CMAKE_OPENCV2_INCLUDE_DIRS_CONFIGCMAKE "${OPENCV_MODULE_${m}_LOCATION}/include")
list(APPEND OpenCV2_INCLUDE_DIRS_CONFIGCMAKE "${OPENCV_MODULE_${m}_LOCATION}/include")
endif()
endforeach()
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/OpenCVConfig.cmake.in" "${CMAKE_BINARY_DIR}/OpenCVConfig.cmake" IMMEDIATE @ONLY)
configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig.cmake.in" "${CMAKE_BINARY_DIR}/OpenCVConfig.cmake" IMMEDIATE @ONLY)
#support for version checking when finding opencv. find_package(OpenCV 2.3.1 EXACT) should now work.
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/OpenCVConfig-version.cmake.in" "${CMAKE_BINARY_DIR}/OpenCVConfig-version.cmake" IMMEDIATE @ONLY)
configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig-version.cmake.in" "${CMAKE_BINARY_DIR}/OpenCVConfig-version.cmake" IMMEDIATE @ONLY)
# --------------------------------------------------------------------------------------------
# Part 2/3: ${BIN_DIR}/unix-install/OpenCVConfig.cmake -> For use *with* "make install"
# -------------------------------------------------------------------------------------------
set(CMAKE_INCLUDE_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/${OPENCV_INCLUDE_PREFIX}/opencv" "\${OpenCV_INSTALL_PATH}/${OPENCV_INCLUDE_PREFIX}\"")
set(OpenCV_INCLUDE_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/${OPENCV_INCLUDE_PREFIX}/opencv" "\${OpenCV_INSTALL_PATH}/${OPENCV_INCLUDE_PREFIX}\"")
set(CMAKE_OPENCV2_INCLUDE_DIRS_CONFIGCMAKE "\"\"")
set(OpenCV2_INCLUDE_DIRS_CONFIGCMAKE "\"\"")
if(ANDROID)
set(CMAKE_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/libs/\${ANDROID_NDK_ABI_NAME}\"")
set(CMAKE_3RDPARTY_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/share/OpenCV/3rdparty/libs/\${ANDROID_NDK_ABI_NAME}\"")
set(OpenCV_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/libs/\${ANDROID_NDK_ABI_NAME}\"")
set(OpenCV_3RDPARTY_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/share/OpenCV/3rdparty/libs/\${ANDROID_NDK_ABI_NAME}\"")
else()
set(CMAKE_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/${OPENCV_LIB_INSTALL_PATH}\"")
set(CMAKE_3RDPARTY_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/share/OpenCV/3rdparty/${OPENCV_LIB_INSTALL_PATH}\"")
if(INSTALL_TO_MANGLED_PATHS)
set(CMAKE_3RDPARTY_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/share/OpenCV-${OPENCV_VERSION}/3rdparty/${OPENCV_LIB_INSTALL_PATH}\"")
endif()
set(OpenCV_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/${OPENCV_LIB_INSTALL_PATH}\"")
set(OpenCV_3RDPARTY_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/share/OpenCV/3rdparty/${OPENCV_LIB_INSTALL_PATH}\"")
if(INSTALL_TO_MANGLED_PATHS)
set(OpenCV_3RDPARTY_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/share/OpenCV-${OPENCV_VERSION}/3rdparty/${OPENCV_LIB_INSTALL_PATH}\"")
endif()
endif()
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/OpenCVConfig.cmake.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig.cmake" IMMEDIATE @ONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/OpenCVConfig-version.cmake.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig-version.cmake" IMMEDIATE @ONLY)
configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig.cmake.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig.cmake" IMMEDIATE @ONLY)
configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig-version.cmake.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig-version.cmake" IMMEDIATE @ONLY)
if(UNIX)
#http://www.vtk.org/Wiki/CMake/Tutorials/Packaging reference
@ -124,22 +129,21 @@ if(UNIX)
endif()
if(ANDROID)
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/android/android.toolchain.cmake" DESTINATION share/OpenCV)
install(FILES "${OpenCV_SOURCE_DIR}/android/android.toolchain.cmake" DESTINATION share/OpenCV)
endif()
# --------------------------------------------------------------------------------------------
# Part 3/3: ${BIN_DIR}/win-install/OpenCVConfig.cmake -> For use within binary installers/packages
# -------------------------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------
if(WIN32)
set(CMAKE_INCLUDE_DIRS_CONFIGCMAKE "\"\${OpenCV_CONFIG_PATH}/include\" \"\${OpenCV_CONFIG_PATH}/include/opencv\"")
set(CMAKE_OPENCV2_INCLUDE_DIRS_CONFIGCMAKE "\"\"")
set(CMAKE_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_CONFIG_PATH}/${OPENCV_LIB_INSTALL_PATH}\"")
set(CMAKE_3RDPARTY_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_CONFIG_PATH}/share/OpenCV/3rdparty/${OPENCV_LIB_INSTALL_PATH}\"")
set(OpenCV_INCLUDE_DIRS_CONFIGCMAKE "\"\${OpenCV_CONFIG_PATH}/include\" \"\${OpenCV_CONFIG_PATH}/include/opencv\"")
set(OpenCV2_INCLUDE_DIRS_CONFIGCMAKE "\"\"")
set(OpenCV_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_CONFIG_PATH}/${OPENCV_LIB_INSTALL_PATH}\"")
set(OpenCV_3RDPARTY_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_CONFIG_PATH}/share/OpenCV/3rdparty/${OPENCV_LIB_INSTALL_PATH}\"")
exec_program(mkdir ARGS "-p \"${CMAKE_BINARY_DIR}/win-install/\"" OUTPUT_VARIABLE RET_VAL)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/OpenCVConfig.cmake.in" "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig.cmake" IMMEDIATE @ONLY)
# Install the OpenCVConfig.cmake file which has the right paths pointing to the install directory
install(FILES "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig.cmake" DESTINATION "${CMAKE_INSTALL_PREFIX}/")
exec_program(mkdir ARGS "-p \"${CMAKE_BINARY_DIR}/win-install/\"" OUTPUT_VARIABLE RET_VAL)
configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig.cmake.in" "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig.cmake" IMMEDIATE @ONLY)
configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig-version.cmake.in" "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig-version.cmake" IMMEDIATE @ONLY)
install(FILES "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig.cmake" DESTINATION "${CMAKE_INSTALL_PREFIX}/")
install(FILES "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig-version.cmake" DESTINATION "${CMAKE_INSTALL_PREFIX}/")
endif()

View File

@ -13,10 +13,9 @@
#
# FIND_PACKAGE(OpenCV REQUIRED core highgui)
#
# If the module found then OPENCV_<MODULE>_FOUND is set.
# If the module is found then OPENCV_<MODULE>_FOUND is set to TRUE.
#
# This file will define the following variables:
# -
# - OpenCV_LIBS : The list of libraries to links against.
# - OpenCV_LIB_DIR : The directory(es) where lib files are. Calling LINK_DIRECTORIES
# with this path is NOT needed.
@ -36,19 +35,19 @@
# - OpenCV_USE_MANGLED_PATHS
# - OpenCV_HAVE_ANDROID_CAMERA
#
# =================================================================================================
# ===================================================================================
# Version Compute Capability from which OpenCV has been compiled is remembered
set(OpenCV_COMPUTE_CAPABILITIES @OpenCV_CUDA_CC_CONFIGMAKE@)
set(OpenCV_COMPUTE_CAPABILITIES @OpenCV_CUDA_CC_CONFIGCMAKE@)
# Android API level from which OpenCV has been compiled is remembered
set(OpenCV_ANDROID_NATIVE_API_LEVEL @OpenCV_ANDROID_NATIVE_API_LEVEL_CONFIGMAKE@)
set(OpenCV_ANDROID_NATIVE_API_LEVEL @OpenCV_ANDROID_NATIVE_API_LEVEL_CONFIGCMAKE@)
# Some additional settings are required if OpenCV is built as static libs
set(OpenCV_SHARED @BUILD_SHARED_LIBS@)
# Enables mangled install paths, that help with side by side installs
set(OpenCV_USE_MANGLED_PATHS @OpenCV_USE_MANGLED_PATHS@)
set(OpenCV_USE_MANGLED_PATHS @OpenCV_USE_MANGLED_PATHS_CONFIGCMAKE@)
# Extract the directory where *this* file has been installed (determined at cmake run-time)
get_filename_component(OpenCV_CONFIG_PATH "${CMAKE_CURRENT_LIST_FILE}" PATH)
@ -64,7 +63,7 @@ set(OpenCV_HAVE_ANDROID_CAMERA @HAVE_opencv_androidcamera@)
# ======================================================
# Provide the include directories to the caller
set(OpenCV_INCLUDE_DIRS @CMAKE_INCLUDE_DIRS_CONFIGCMAKE@)
set(OpenCV_INCLUDE_DIRS @OpenCV_INCLUDE_DIRS_CONFIGCMAKE@)
include_directories(${OpenCV_INCLUDE_DIRS})
# ======================================================
@ -72,10 +71,10 @@ include_directories(${OpenCV_INCLUDE_DIRS})
# ======================================================
# Provide the libs directories to the caller
set(OpenCV_LIB_DIR_OPT @CMAKE_LIB_DIRS_CONFIGCMAKE@)
set(OpenCV_LIB_DIR_DBG @CMAKE_LIB_DIRS_CONFIGCMAKE@)
set(OpenCV_3RDPARTY_LIB_DIR_OPT @CMAKE_3RDPARTY_LIB_DIRS_CONFIGCMAKE@)
set(OpenCV_3RDPARTY_LIB_DIR_DBG @CMAKE_3RDPARTY_LIB_DIRS_CONFIGCMAKE@)
set(OpenCV_LIB_DIR_OPT @OpenCV_LIB_DIRS_CONFIGCMAKE@)
set(OpenCV_LIB_DIR_DBG @OpenCV_LIB_DIRS_CONFIGCMAKE@)
set(OpenCV_3RDPARTY_LIB_DIR_OPT @OpenCV_3RDPARTY_LIB_DIRS_CONFIGCMAKE@)
set(OpenCV_3RDPARTY_LIB_DIR_DBG @OpenCV_3RDPARTY_LIB_DIRS_CONFIGCMAKE@)
# ======================================================
# Version variables:
@ -89,7 +88,7 @@ SET(OpenCV_VERSION_PATCH @OPENCV_VERSION_PATCH@)
# Link libraries: e.g. libopencv_core.so, opencv_imgproc220d.lib, etc...
# ====================================================================
SET(OpenCV_LIB_COMPONENTS @OPENCV_MODULES_CONFIGMAKE@)
SET(OpenCV_LIB_COMPONENTS @OPENCV_MODULES_CONFIGCMAKE@)
@OPENCV_DEPENDENCIES_MAP_OPT@
@ -98,17 +97,13 @@ SET(OpenCV_LIB_COMPONENTS @OPENCV_MODULES_CONFIGMAKE@)
# ==============================================================
# Extra include directories, needed by OpenCV 2 new structure
# ==============================================================
SET(OpenCV2_INCLUDE_DIRS @CMAKE_OPENCV2_INCLUDE_DIRS_CONFIGCMAKE@)
SET(OpenCV2_INCLUDE_DIRS @OpenCV2_INCLUDE_DIRS_CONFIGCMAKE@)
if(OpenCV2_INCLUDE_DIRS)
include_directories(${OpenCV2_INCLUDE_DIRS})
list(APPEND OpenCV_INCLUDE_DIRS ${OpenCV2_INCLUDE_DIRS})
set(OpenCV_AddDebugRelease FALSE)
if(MSVC OR CMAKE_GENERATOR MATCHES Xcode)
set(OpenCV_AddDebugRelease TRUE)
endif()
if(OpenCV_AddDebugRelease)
set(OpenCV_ADD_DEBUG_RELEASE @OpenCV_ADD_DEBUG_RELEASE_CONFIGCMAKE@)
if(OpenCV_ADD_DEBUG_RELEASE)
set(OpenCV_LIB_DIR_OPT "${OpenCV_LIB_DIR_OPT}/Release")
set(OpenCV_LIB_DIR_DBG "${OpenCV_LIB_DIR_DBG}/Debug")
set(OpenCV_3RDPARTY_LIB_DIR_OPT "${OpenCV_3RDPARTY_LIB_DIR_OPT}/Release")