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
8if(INSTALL_TO_MANGLED_PATHS)
9  set(OpenCV_USE_MANGLED_PATHS_CONFIGCMAKE TRUE)
10else()
11  set(OpenCV_USE_MANGLED_PATHS_CONFIGCMAKE FALSE)
12endif()
13
14if(NOT OpenCV_CUDA_CC)
15  set(OpenCV_CUDA_CC_CONFIGCMAKE "\"\"")
16  set(OpenCV_CUDA_VERSION "")
17else()
18  set(OpenCV_CUDA_CC_CONFIGCMAKE "${OpenCV_CUDA_CC}")
19  set(OpenCV_CUDA_VERSION ${CUDA_VERSION_STRING})
20endif()
21
22if(NOT ANDROID_NATIVE_API_LEVEL)
23  set(OpenCV_ANDROID_NATIVE_API_LEVEL_CONFIGCMAKE 0)
24else()
25  set(OpenCV_ANDROID_NATIVE_API_LEVEL_CONFIGCMAKE "${ANDROID_NATIVE_API_LEVEL}")
26endif()
27
28if(CMAKE_GENERATOR MATCHES "Visual" OR CMAKE_GENERATOR MATCHES "Xcode")
29  set(OpenCV_ADD_DEBUG_RELEASE_CONFIGCMAKE TRUE)
30else()
31  set(OpenCV_ADD_DEBUG_RELEASE_CONFIGCMAKE FALSE)
32endif()
33
34
35
36if(WIN32)
37  if(MINGW)
38    set(OPENCV_LINK_LIBRARY_SUFFIX ".dll.a")
39  else()
40    set(OPENCV_LINK_LIBRARY_SUFFIX ".lib")
41  endif()
42endif()
43
44#build list of modules available for the OpenCV user
45set(OpenCV_LIB_COMPONENTS "")
46foreach(m ${OPENCV_MODULES_PUBLIC})
47  list(INSERT OpenCV_LIB_COMPONENTS 0 ${${m}_MODULE_DEPS_OPT} ${m})
48endforeach()
49ocv_list_unique(OpenCV_LIB_COMPONENTS)
50set(OPENCV_MODULES_CONFIGCMAKE ${OpenCV_LIB_COMPONENTS})
51ocv_list_filterout(OpenCV_LIB_COMPONENTS "^opencv_")
52if(OpenCV_LIB_COMPONENTS)
53  list(REMOVE_ITEM OPENCV_MODULES_CONFIGCMAKE ${OpenCV_LIB_COMPONENTS})
54endif()
55
56if(BUILD_FAT_JAVA_LIB AND HAVE_opencv_java)
57  list(APPEND OPENCV_MODULES_CONFIGCMAKE opencv_java)
58endif()
59
60# -------------------------------------------------------------------------------------------
61#  Part 1/3: ${BIN_DIR}/OpenCVConfig.cmake              -> For use *without* "make install"
62# -------------------------------------------------------------------------------------------
63set(OpenCV_INCLUDE_DIRS_CONFIGCMAKE "\"${OPENCV_CONFIG_FILE_INCLUDE_DIR}\" \"${OpenCV_SOURCE_DIR}/include\" \"${OpenCV_SOURCE_DIR}/include/opencv\"")
64
65set(OpenCV2_INCLUDE_DIRS_CONFIGCMAKE "")
66foreach(m ${OPENCV_MODULES_BUILD})
67  if(EXISTS "${OPENCV_MODULE_${m}_LOCATION}/include")
68    list(APPEND OpenCV2_INCLUDE_DIRS_CONFIGCMAKE "${OPENCV_MODULE_${m}_LOCATION}/include")
69  endif()
70endforeach()
71
72if(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})
75endif()
76
77set(modules_file_suffix "")
78if(ANDROID)
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}")
82endif()
83
84export(TARGETS ${OpenCVModules_TARGETS} FILE "${CMAKE_BINARY_DIR}/OpenCVModules${modules_file_suffix}.cmake")
85
86if(TARGET ippicv)
87  set(USE_IPPICV TRUE)
88  file(RELATIVE_PATH INSTALL_PATH_RELATIVE_IPPICV ${CMAKE_BINARY_DIR} ${IPPICV_LOCATION_PATH})
89else()
90  set(USE_IPPICV FALSE)
91  set(INSTALL_PATH_RELATIVE_IPPICV "non-existed-path")
92endif()
93
94configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig.cmake.in" "${CMAKE_BINARY_DIR}/OpenCVConfig.cmake" @ONLY)
95#support for version checking when finding opencv. find_package(OpenCV 2.3.1 EXACT) should now work.
96configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig-version.cmake.in" "${CMAKE_BINARY_DIR}/OpenCVConfig-version.cmake" @ONLY)
97
98# --------------------------------------------------------------------------------------------
99#  Part 2/3: ${BIN_DIR}/unix-install/OpenCVConfig.cmake -> For use *with* "make install"
100# -------------------------------------------------------------------------------------------
101set(OpenCV_INCLUDE_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/${OPENCV_INCLUDE_INSTALL_PATH}/opencv" "\${OpenCV_INSTALL_PATH}/${OPENCV_INCLUDE_INSTALL_PATH}\"")
102
103set(OpenCV2_INCLUDE_DIRS_CONFIGCMAKE "\"\"")
104set(OpenCV_3RDPARTY_LIB_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/${OPENCV_3P_LIB_INSTALL_PATH}\"")
105
106if(UNIX) # ANDROID configuration is created here also
107  #http://www.vtk.org/Wiki/CMake/Tutorials/Packaging reference
108  # For a command "find_package(<name> [major[.minor]] [EXACT] [REQUIRED|QUIET])"
109  # cmake will look in the following dir on unix:
110  #                <prefix>/(share|lib)/cmake/<name>*/                     (U)
111  #                <prefix>/(share|lib)/<name>*/                           (U)
112  #                <prefix>/(share|lib)/<name>*/(cmake|CMake)/             (U)
113  if(USE_IPPICV)
114    file(RELATIVE_PATH INSTALL_PATH_RELATIVE_IPPICV "${CMAKE_INSTALL_PREFIX}/${OPENCV_CONFIG_INSTALL_PATH}/" ${IPPICV_INSTALL_PATH})
115  endif()
116  configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig.cmake.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig.cmake" @ONLY)
117  configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig-version.cmake.in" "${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig-version.cmake" @ONLY)
118  install(FILES "${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig.cmake" DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}/ COMPONENT dev)
119  install(FILES ${CMAKE_BINARY_DIR}/unix-install/OpenCVConfig-version.cmake DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}/ COMPONENT dev)
120  install(EXPORT OpenCVModules DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}/ FILE OpenCVModules${modules_file_suffix}.cmake COMPONENT dev)
121endif()
122
123if(ANDROID)
124  install(FILES "${OpenCV_SOURCE_DIR}/platforms/android/android.toolchain.cmake" DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}/ COMPONENT dev)
125endif()
126
127# --------------------------------------------------------------------------------------------
128#  Part 3/3: ${BIN_DIR}/win-install/OpenCVConfig.cmake  -> For use within binary installers/packages
129# --------------------------------------------------------------------------------------------
130if(WIN32)
131  set(OpenCV_INCLUDE_DIRS_CONFIGCMAKE "\"\${OpenCV_CONFIG_PATH}/include\" \"\${OpenCV_CONFIG_PATH}/include/opencv\"")
132  set(OpenCV2_INCLUDE_DIRS_CONFIGCMAKE "\"\"")
133
134  exec_program(mkdir ARGS "-p \"${CMAKE_BINARY_DIR}/win-install/\"" OUTPUT_VARIABLE RET_VAL)
135  if(USE_IPPICV)
136    if(BUILD_SHARED_LIBS)
137      file(RELATIVE_PATH INSTALL_PATH_RELATIVE_IPPICV "${CMAKE_INSTALL_PREFIX}/${OpenCV_INSTALL_BINARIES_PREFIX}lib" ${IPPICV_INSTALL_PATH})
138    else()
139      file(RELATIVE_PATH INSTALL_PATH_RELATIVE_IPPICV "${CMAKE_INSTALL_PREFIX}/${OpenCV_INSTALL_BINARIES_PREFIX}staticlib" ${IPPICV_INSTALL_PATH})
140    endif()
141  endif()
142  configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig.cmake.in" "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig.cmake" @ONLY)
143  configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig-version.cmake.in" "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig-version.cmake" @ONLY)
144  if (CMAKE_HOST_SYSTEM_NAME MATCHES Windows)
145    if(BUILD_SHARED_LIBS)
146      install(FILES "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig.cmake" DESTINATION "${OpenCV_INSTALL_BINARIES_PREFIX}lib" COMPONENT dev)
147      install(EXPORT OpenCVModules DESTINATION "${OpenCV_INSTALL_BINARIES_PREFIX}lib" FILE OpenCVModules${modules_file_suffix}.cmake COMPONENT dev)
148    else()
149      install(FILES "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig.cmake" DESTINATION "${OpenCV_INSTALL_BINARIES_PREFIX}staticlib" COMPONENT dev)
150      install(EXPORT OpenCVModules DESTINATION "${OpenCV_INSTALL_BINARIES_PREFIX}staticlib" FILE OpenCVModules${modules_file_suffix}.cmake COMPONENT dev)
151    endif()
152    install(FILES "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig-version.cmake" DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT dev)
153    install(FILES "${OpenCV_SOURCE_DIR}/cmake/OpenCVConfig.cmake" DESTINATION "${CMAKE_INSTALL_PREFIX}/" COMPONENT dev)
154  else ()
155    install(FILES "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig.cmake" DESTINATION "${OpenCV_INSTALL_BINARIES_PREFIX}lib/cmake/opencv-${OPENCV_VERSION}" COMPONENT dev)
156    install(EXPORT OpenCVModules DESTINATION "${OpenCV_INSTALL_BINARIES_PREFIX}lib/cmake/opencv-${OPENCV_VERSION}" FILE OpenCVModules${modules_file_suffix}.cmake COMPONENT dev)
157    install(FILES "${CMAKE_BINARY_DIR}/win-install/OpenCVConfig-version.cmake" DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/cmake/opencv-${OPENCV_VERSION}" COMPONENT dev)
158  endif ()
159endif()
160