OpenCVGenConfig.cmake 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. # --------------------------------------------------------------------------------------------
  2. # Installation for CMake Module: OpenCVConfig.cmake
  3. # Part 1/3: ${BIN_DIR}/OpenCVConfig.cmake -> For use *without* "make install"
  4. # Part 2/3: ${BIN_DIR}/unix-install/OpenCVConfig.cmake -> For use with "make install"
  5. # Part 3/3: ${BIN_DIR}/win-install/OpenCVConfig.cmake -> For use within binary installers/packages
  6. # -------------------------------------------------------------------------------------------
  7. if(INSTALL_TO_MANGLED_PATHS)
  8. set(OpenCV_USE_MANGLED_PATHS_CONFIGCMAKE TRUE)
  9. else()
  10. set(OpenCV_USE_MANGLED_PATHS_CONFIGCMAKE FALSE)
  11. endif()
  12. if(HAVE_CUDA)
  13. ocv_cmake_configure("${CMAKE_CURRENT_LIST_DIR}/templates/OpenCVConfig-CUDA.cmake.in" CUDA_CONFIGCMAKE @ONLY)
  14. endif()
  15. if(ANDROID)
  16. if(NOT ANDROID_NATIVE_API_LEVEL)
  17. set(OpenCV_ANDROID_NATIVE_API_LEVEL_CONFIGCMAKE 0)
  18. else()
  19. set(OpenCV_ANDROID_NATIVE_API_LEVEL_CONFIGCMAKE "${ANDROID_NATIVE_API_LEVEL}")
  20. endif()
  21. ocv_cmake_configure("${CMAKE_CURRENT_LIST_DIR}/templates/OpenCVConfig-ANDROID.cmake.in" ANDROID_CONFIGCMAKE @ONLY)
  22. endif()
  23. set(OPENCV_MODULES_CONFIGCMAKE ${OPENCV_MODULES_PUBLIC})
  24. if(BUILD_FAT_JAVA_LIB AND HAVE_opencv_java)
  25. list(APPEND OPENCV_MODULES_CONFIGCMAKE opencv_java)
  26. endif()
  27. if(BUILD_OBJC AND HAVE_opencv_objc)
  28. list(APPEND OPENCV_MODULES_CONFIGCMAKE opencv_objc)
  29. endif()
  30. # -------------------------------------------------------------------------------------------
  31. # Part 1/3: ${BIN_DIR}/OpenCVConfig.cmake -> For use *without* "make install"
  32. # -------------------------------------------------------------------------------------------
  33. set(OpenCV_INCLUDE_DIRS_CONFIGCMAKE "\"${OPENCV_CONFIG_FILE_INCLUDE_DIR}\" \"${OpenCV_SOURCE_DIR}/include\"")
  34. foreach(m ${OPENCV_MODULES_BUILD})
  35. if(EXISTS "${OPENCV_MODULE_${m}_LOCATION}/include")
  36. set(OpenCV_INCLUDE_DIRS_CONFIGCMAKE "${OpenCV_INCLUDE_DIRS_CONFIGCMAKE} \"${OPENCV_MODULE_${m}_LOCATION}/include\"")
  37. endif()
  38. endforeach()
  39. export(EXPORT OpenCVModules FILE "${CMAKE_BINARY_DIR}/OpenCVModules.cmake")
  40. if(TARGET ippicv AND NOT BUILD_SHARED_LIBS)
  41. set(USE_IPPICV TRUE)
  42. file(RELATIVE_PATH IPPICV_INSTALL_PATH_RELATIVE_CONFIGCMAKE "${CMAKE_BINARY_DIR}" "${IPPICV_LOCATION_PATH}")
  43. ocv_cmake_configure("${CMAKE_CURRENT_LIST_DIR}/templates/OpenCVConfig-IPPICV.cmake.in" IPPICV_CONFIGCMAKE @ONLY)
  44. else()
  45. set(USE_IPPICV FALSE)
  46. endif()
  47. if(TARGET ippiw AND NOT BUILD_SHARED_LIBS AND IPPIW_INSTALL_PATH)
  48. set(USE_IPPIW TRUE)
  49. file(RELATIVE_PATH IPPIW_INSTALL_PATH_RELATIVE_CONFIGCMAKE "${CMAKE_BINARY_DIR}" "${IPPIW_LOCATION_PATH}")
  50. ocv_cmake_configure("${CMAKE_CURRENT_LIST_DIR}/templates/OpenCVConfig-IPPIW.cmake.in" IPPIW_CONFIGCMAKE @ONLY)
  51. else()
  52. set(USE_IPPIW FALSE)
  53. endif()
  54. ocv_cmake_hook(PRE_CMAKE_CONFIG_BUILD)
  55. configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig.cmake.in" "${CMAKE_BINARY_DIR}/OpenCVConfig.cmake" @ONLY)
  56. #support for version checking when finding opencv. find_package(OpenCV 2.3.1 EXACT) should now work.
  57. configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig-version.cmake.in" "${CMAKE_BINARY_DIR}/OpenCVConfig-version.cmake" @ONLY)
  58. # --------------------------------------------------------------------------------------------
  59. # Part 2/3: ${BIN_DIR}/unix-install/OpenCVConfig.cmake -> For use *with* "make install"
  60. # -------------------------------------------------------------------------------------------
  61. file(RELATIVE_PATH OpenCV_INSTALL_PATH_RELATIVE_CONFIGCMAKE "${CMAKE_INSTALL_PREFIX}/${OPENCV_CONFIG_INSTALL_PATH}/" ${CMAKE_INSTALL_PREFIX})
  62. if (IS_ABSOLUTE ${OPENCV_INCLUDE_INSTALL_PATH})
  63. set(OpenCV_INCLUDE_DIRS_CONFIGCMAKE "\"${OPENCV_INCLUDE_INSTALL_PATH}\"")
  64. else()
  65. set(OpenCV_INCLUDE_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/${OPENCV_INCLUDE_INSTALL_PATH}\"")
  66. endif()
  67. if(USE_IPPICV)
  68. file(RELATIVE_PATH IPPICV_INSTALL_PATH_RELATIVE_CONFIGCMAKE "${CMAKE_INSTALL_PREFIX}" "${IPPICV_INSTALL_PATH}")
  69. ocv_cmake_configure("${CMAKE_CURRENT_LIST_DIR}/templates/OpenCVConfig-IPPICV.cmake.in" IPPICV_CONFIGCMAKE @ONLY)
  70. endif()
  71. if(USE_IPPIW)
  72. file(RELATIVE_PATH IPPIW_INSTALL_PATH_RELATIVE_CONFIGCMAKE "${CMAKE_INSTALL_PREFIX}" "${IPPIW_INSTALL_PATH}")
  73. ocv_cmake_configure("${CMAKE_CURRENT_LIST_DIR}/templates/OpenCVConfig-IPPIW.cmake.in" IPPIW_CONFIGCMAKE @ONLY)
  74. endif()
  75. function(ocv_gen_config TMP_DIR NESTED_PATH ROOT_NAME)
  76. ocv_path_join(__install_nested "${OPENCV_CONFIG_INSTALL_PATH}" "${NESTED_PATH}")
  77. ocv_path_join(__tmp_nested "${TMP_DIR}" "${NESTED_PATH}")
  78. file(RELATIVE_PATH OpenCV_INSTALL_PATH_RELATIVE_CONFIGCMAKE "${CMAKE_INSTALL_PREFIX}/${__install_nested}" "${CMAKE_INSTALL_PREFIX}/")
  79. ocv_cmake_hook(PRE_CMAKE_CONFIG_INSTALL)
  80. configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig-version.cmake.in" "${TMP_DIR}/OpenCVConfig-version.cmake" @ONLY)
  81. configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig.cmake.in" "${__tmp_nested}/OpenCVConfig.cmake" @ONLY)
  82. install(EXPORT OpenCVModules DESTINATION "${__install_nested}" FILE OpenCVModules.cmake COMPONENT dev)
  83. install(FILES
  84. "${TMP_DIR}/OpenCVConfig-version.cmake"
  85. "${__tmp_nested}/OpenCVConfig.cmake"
  86. DESTINATION "${__install_nested}" COMPONENT dev)
  87. if(ROOT_NAME)
  88. # Root config file
  89. configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/${ROOT_NAME}" "${TMP_DIR}/OpenCVConfig.cmake" @ONLY)
  90. install(FILES
  91. "${TMP_DIR}/OpenCVConfig-version.cmake"
  92. "${TMP_DIR}/OpenCVConfig.cmake"
  93. DESTINATION "${OPENCV_CONFIG_INSTALL_PATH}" COMPONENT dev)
  94. endif()
  95. endfunction()
  96. if((CMAKE_HOST_SYSTEM_NAME MATCHES "Linux" OR UNIX) AND NOT ANDROID)
  97. ocv_gen_config("${CMAKE_BINARY_DIR}/unix-install" "" "")
  98. endif()
  99. if(ANDROID)
  100. ocv_gen_config("${CMAKE_BINARY_DIR}/unix-install" "abi-${ANDROID_NDK_ABI_NAME}" "OpenCVConfig.root-ANDROID.cmake.in")
  101. install(FILES "${OpenCV_SOURCE_DIR}/platforms/android/android.toolchain.cmake" DESTINATION "${OPENCV_CONFIG_INSTALL_PATH}" COMPONENT dev)
  102. endif()
  103. # --------------------------------------------------------------------------------------------
  104. # Part 3/3: ${BIN_DIR}/win-install/OpenCVConfig.cmake -> For use within binary installers/packages
  105. # --------------------------------------------------------------------------------------------
  106. if(WIN32)
  107. if(CMAKE_HOST_SYSTEM_NAME MATCHES Windows AND NOT OPENCV_SKIP_CMAKE_ROOT_CONFIG)
  108. ocv_gen_config("${CMAKE_BINARY_DIR}/win-install"
  109. "${OPENCV_INSTALL_BINARIES_PREFIX}${OPENCV_INSTALL_BINARIES_SUFFIX}"
  110. "OpenCVConfig.root-WIN32.cmake.in")
  111. else()
  112. ocv_gen_config("${CMAKE_BINARY_DIR}/win-install" "" "")
  113. endif()
  114. endif()