Merge pull request #1704 from SpecLad:merge-2.4
[profile/ivi/opencv.git] / cmake / OpenCVGenConfig.cmake
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
8 if(INSTALL_TO_MANGLED_PATHS)
9   set(OpenCV_USE_MANGLED_PATHS_CONFIGCMAKE TRUE)
10 else()
11   set(OpenCV_USE_MANGLED_PATHS_CONFIGCMAKE FALSE)
12 endif()
13
14 if(NOT OpenCV_CUDA_CC)
15   set(OpenCV_CUDA_CC_CONFIGCMAKE "\"\"")
16   set(OpenCV_CUDA_VERSION "")
17 else()
18   set(OpenCV_CUDA_CC_CONFIGCMAKE "${OpenCV_CUDA_CC}")
19   set(OpenCV_CUDA_VERSION ${CUDA_VERSION_STRING})
20 endif()
21
22 if(NOT ANDROID_NATIVE_API_LEVEL)
23   set(OpenCV_ANDROID_NATIVE_API_LEVEL_CONFIGCMAKE 0)
24 else()
25   set(OpenCV_ANDROID_NATIVE_API_LEVEL_CONFIGCMAKE "${ANDROID_NATIVE_API_LEVEL}")
26 endif()
27
28 if(CMAKE_GENERATOR MATCHES "Visual" OR CMAKE_GENERATOR MATCHES "Xcode")
29   set(OpenCV_ADD_DEBUG_RELEASE_CONFIGCMAKE TRUE)
30 else()
31   set(OpenCV_ADD_DEBUG_RELEASE_CONFIGCMAKE FALSE)
32 endif()
33
34
35
36 if(WIN32)
37   if(MINGW)
38     set(OPENCV_LINK_LIBRARY_SUFFIX ".dll.a")
39   else()
40     set(OPENCV_LINK_LIBRARY_SUFFIX ".lib")
41   endif()
42 endif()
43
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})
48 endforeach()
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})
54 endif()
55
56 if(BUILD_FAT_JAVA_LIB AND HAVE_opencv_java)
57   list(APPEND OPENCV_MODULES_CONFIGCMAKE opencv_java)
58 endif()
59
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\"")
64
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")
69   endif()
70 endforeach()
71
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})
75 endif()
76
77 set(modules_file_suffix "")
78 if(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}")
82 endif()
83
84 export(TARGETS ${OpenCVModules_TARGETS} FILE "${CMAKE_BINARY_DIR}/OpenCVModules${modules_file_suffix}.cmake")
85
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)
89
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}\"")
94
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}\"")
99 endif()
100
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)
103
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)
115   else()
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)
119   endif()
120 endif()
121
122 if(ANDROID)
123   install(FILES "${OpenCV_SOURCE_DIR}/platforms/android/android.toolchain.cmake" DESTINATION ${OPENCV_CONFIG_INSTALL_PATH}/)
124 endif()
125
126 # --------------------------------------------------------------------------------------------
127 #  Part 3/3: ${BIN_DIR}/win-install/OpenCVConfig.cmake  -> For use within binary installers/packages
128 # --------------------------------------------------------------------------------------------
129 if(WIN32)
130   set(OpenCV_INCLUDE_DIRS_CONFIGCMAKE "\"\${OpenCV_CONFIG_PATH}/include\" \"\${OpenCV_CONFIG_PATH}/include/opencv\"")
131   set(OpenCV2_INCLUDE_DIRS_CONFIGCMAKE "\"\"")
132
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)
139   else()
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)
142   endif()
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}/")
145 endif()