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 # -------------------------------------------------------------------------------------------
8 if(INSTALL_TO_MANGLED_PATHS)
9 set(OpenCV_USE_MANGLED_PATHS_CONFIGCMAKE TRUE)
11 set(OpenCV_USE_MANGLED_PATHS_CONFIGCMAKE FALSE)
14 if(NOT OpenCV_CUDA_CC)
15 set(OpenCV_CUDA_CC_CONFIGCMAKE "\"\"")
16 set(OpenCV_CUDA_VERSION "")
18 set(OpenCV_CUDA_CC_CONFIGCMAKE "${OpenCV_CUDA_CC}")
19 set(OpenCV_CUDA_VERSION ${CUDA_VERSION_STRING})
22 if(NOT ANDROID_NATIVE_API_LEVEL)
23 set(OpenCV_ANDROID_NATIVE_API_LEVEL_CONFIGCMAKE 0)
25 set(OpenCV_ANDROID_NATIVE_API_LEVEL_CONFIGCMAKE "${ANDROID_NATIVE_API_LEVEL}")
28 if(CMAKE_GENERATOR MATCHES "Visual" OR CMAKE_GENERATOR MATCHES "Xcode")
29 set(OpenCV_ADD_DEBUG_RELEASE_CONFIGCMAKE TRUE)
31 set(OpenCV_ADD_DEBUG_RELEASE_CONFIGCMAKE FALSE)
38 set(OPENCV_LINK_LIBRARY_SUFFIX ".dll.a")
40 set(OPENCV_LINK_LIBRARY_SUFFIX ".lib")
44 #build list of modules available for the OpenCV user
45 set(OpenCV_LIB_COMPONENTS "")
46 foreach(m ${OPENCV_MODULES_PUBLIC})
47 list(INSERT OpenCV_LIB_COMPONENTS 0 ${${m}_MODULE_DEPS_OPT} ${m})
49 ocv_list_unique(OpenCV_LIB_COMPONENTS)
50 set(OPENCV_MODULES_CONFIGCMAKE ${OpenCV_LIB_COMPONENTS})
51 ocv_list_filterout(OpenCV_LIB_COMPONENTS "^opencv_")
52 if(OpenCV_LIB_COMPONENTS)
53 list(REMOVE_ITEM OPENCV_MODULES_CONFIGCMAKE ${OpenCV_LIB_COMPONENTS})
56 if(BUILD_FAT_JAVA_LIB AND HAVE_opencv_java)
57 list(APPEND OPENCV_MODULES_CONFIGCMAKE opencv_java)
60 # -------------------------------------------------------------------------------------------
61 # Part 1/3: ${BIN_DIR}/OpenCVConfig.cmake -> For use *without* "make install"
62 # -------------------------------------------------------------------------------------------
63 set(OpenCV_INCLUDE_DIRS_CONFIGCMAKE "\"${OPENCV_CONFIG_FILE_INCLUDE_DIR}\" \"${OpenCV_SOURCE_DIR}/include\" \"${OpenCV_SOURCE_DIR}/include/opencv\"")
65 set(OpenCV2_INCLUDE_DIRS_CONFIGCMAKE "")
66 foreach(m ${OPENCV_MODULES_BUILD})
67 if(EXISTS "${OPENCV_MODULE_${m}_LOCATION}/include")
68 list(APPEND OpenCV2_INCLUDE_DIRS_CONFIGCMAKE "${OPENCV_MODULE_${m}_LOCATION}/include")
72 if(ANDROID AND NOT BUILD_SHARED_LIBS AND HAVE_TBB)
73 #export TBB headers location because static linkage of TBB might be troublesome if application wants to use TBB itself
74 list(APPEND OpenCV2_INCLUDE_DIRS_CONFIGCMAKE ${TBB_INCLUDE_DIRS})
77 set(modules_file_suffix "")
79 # the REPLACE here is needed, because OpenCVModules_armeabi.cmake includes
80 # OpenCVModules_armeabi-*.cmake, which would match OpenCVModules_armeabi-v7a*.cmake.
81 string(REPLACE - _ modules_file_suffix "_${ANDROID_NDK_ABI_NAME}")
84 export(TARGETS ${OpenCVModules_TARGETS} FILE "${CMAKE_BINARY_DIR}/OpenCVModules${modules_file_suffix}.cmake")
86 configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig.cmake.in" "${CMAKE_BINARY_DIR}/OpenCVConfig.cmake" IMMEDIATE @ONLY)
87 #support for version checking when finding opencv. find_package(OpenCV 2.3.1 EXACT) should now work.
88 configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig-version.cmake.in" "${CMAKE_BINARY_DIR}/OpenCVConfig-version.cmake" IMMEDIATE @ONLY)
90 # --------------------------------------------------------------------------------------------
91 # Part 2/3: ${BIN_DIR}/unix-install/OpenCVConfig.cmake -> For use *with* "make install"
92 # -------------------------------------------------------------------------------------------
93 set(OpenCV_INCLUDE_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/${OPENCV_INCLUDE_INSTALL_PATH}/opencv" "\${OpenCV_INSTALL_PATH}/${OPENCV_INCLUDE_INSTALL_PATH}\"")
95 set(OpenCV2_INCLUDE_DIRS_CONFIGCMAKE "\"\"")
96 if(INSTALL_TO_MANGLED_PATHS)
97 string(REPLACE "OpenCV" "OpenCV-${OPENCV_VERSION}" OpenCV_3RDPARTY_LIB_DIRS_CONFIGCMAKE "${OPENCV_3P_LIB_INSTALL_PATH}")
98 set(OpenCV_3RDPARTY_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/${OpenCV_3RDPARTY_LIB_DIRS_CONFIGCMAKE}\"")
101 configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig.cmake.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig.cmake" IMMEDIATE @ONLY)
102 configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig-version.cmake.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig-version.cmake" IMMEDIATE @ONLY)
104 if(UNIX) # ANDROID configuration is created here also
105 #http://www.vtk.org/Wiki/CMake/Tutorials/Packaging reference
106 # For a command "find_package(<name> [major[.minor]] [EXACT] [REQUIRED|QUIET])"
107 # cmake will look in the following dir on unix:
108 # <prefix>/(share|lib)/cmake/<name>*/ (U)
109 # <prefix>/(share|lib)/<name>*/ (U)
110 # <prefix>/(share|lib)/<name>*/(cmake|CMake)/ (U)
111 if(INSTALL_TO_MANGLED_PATHS)
112 install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig.cmake DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}-${OPENCV_VERSION}/)
113 install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig-version.cmake DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}-${OPENCV_VERSION}/)
114 install(EXPORT OpenCVModules DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}-${OPENCV_VERSION}/ FILE OpenCVModules${modules_file_suffix}.cmake)
116 install(FILES "${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig.cmake" DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}/)
117 install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig-version.cmake DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}/)
118 install(EXPORT OpenCVModules DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}/ FILE OpenCVModules${modules_file_suffix}.cmake)
123 install(FILES "${OpenCV_SOURCE_DIR}/platforms/android/android.toolchain.cmake" DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}/)
126 # --------------------------------------------------------------------------------------------
127 # Part 3/3: ${BIN_DIR}/win-install/OpenCVConfig.cmake -> For use within binary installers/packages
128 # --------------------------------------------------------------------------------------------
130 set(OpenCV_INCLUDE_DIRS_CONFIGCMAKE "\"\${OpenCV_CONFIG_PATH}/include\" \"\${OpenCV_CONFIG_PATH}/include/opencv\"")
131 set(OpenCV2_INCLUDE_DIRS_CONFIGCMAKE "\"\"")
133 exec_program(mkdir ARGS "-p \"${CMAKE_BINARY_DIR}/win-install/\"" OUTPUT_VARIABLE RET_VAL)
134 configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig.cmake.in" "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig.cmake" IMMEDIATE @ONLY)
135 configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig-version.cmake.in" "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig-version.cmake" IMMEDIATE @ONLY)
136 if(BUILD_SHARED_LIBS)
137 install(FILES "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig.cmake" DESTINATION "${OpenCV_INSTALL_BINARIES_PREFIX}/lib")
138 install(EXPORT OpenCVModules DESTINATION "${OpenCV_INSTALL_BINARIES_PREFIX}/lib" FILE OpenCVModules${modules_file_suffix}.cmake)
140 install(FILES "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig.cmake" DESTINATION "${OpenCV_INSTALL_BINARIES_PREFIX}/staticlib")
141 install(EXPORT OpenCVModules DESTINATION "${OpenCV_INSTALL_BINARIES_PREFIX}/staticlib" FILE OpenCVModules${modules_file_suffix}.cmake)
143 install(FILES "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig-version.cmake" DESTINATION "${CMAKE_INSTALL_PREFIX}")
144 install(FILES "${OpenCV_SOURCE_DIR}/cmake/OpenCVConfig.cmake" DESTINATION "${CMAKE_INSTALL_PREFIX}/")