1 # -------------------------------------------------------------------------------------------- 2 # according to man pkg-config 3 # The package name specified on the pkg-config command line is defined to 4 # be the name of the metadata file, minus the .pc extension. If a library 5 # can install multiple versions simultaneously, it must give each version 6 # its own name (for example, GTK 1.2 might have the package name "gtk+" 7 # while GTK 2.0 has "gtk+-2.0"). 8 # 9 # ${BIN_DIR}/unix-install/opencv.pc -> For use *with* "make install" 10 # ------------------------------------------------------------------------------------------- 11 12 macro(fix_prefix lst isown) 13 set(_lst) 14 foreach(item ${${lst}}) 15 if(TARGET ${item}) 16 get_target_property(item "${item}" LOCATION_${CMAKE_BUILD_TYPE}) 17 if("${isown}") 18 get_filename_component(item "${item}" NAME_WE) 19 string(REGEX REPLACE "^lib(.*)" "\\1" item "${item}") 20 endif() 21 endif() 22 if(item MATCHES "^-l") 23 list(APPEND _lst "${item}") 24 elseif(item MATCHES "[\\/]") 25 get_filename_component(libdir "${item}" PATH) 26 get_filename_component(libname "${item}" NAME_WE) 27 string(REGEX REPLACE "^lib(.*)" "\\1" libname "${libname}") 28 list(APPEND _lst "-L${libdir}" "-l${libname}") 29 else() 30 list(APPEND _lst "-l${item}") 31 endif() 32 endforeach() 33 set(${lst} ${_lst}) 34 unset(_lst) 35 endmacro() 36 37 # build the list of opencv libs and dependencies for all modules 38 ocv_get_all_libs(_modules _extra _3rdparty) 39 40 #build the list of components 41 42 # Note: 43 # when linking against static libraries, if libfoo depends on libbar, then 44 # libfoo must come first in the linker flags. 45 46 # world and contrib_world are special targets whose library should come first, 47 # especially for static link. 48 if(_modules MATCHES "opencv_world") 49 set(_modules "opencv_world") 50 endif() 51 52 if(_modules MATCHES "opencv_contrib_world") 53 list(REMOVE_ITEM _modules "opencv_contrib_world") 54 list(INSERT _modules 0 "opencv_contrib_world") 55 endif() 56 57 fix_prefix(_modules TRUE) 58 fix_prefix(_extra FALSE) 59 fix_prefix(_3rdparty TRUE) 60 61 ocv_list_unique(_modules) 62 ocv_list_unique(_extra) 63 ocv_list_unique(_3rdparty) 64 65 set(OPENCV_PC_LIBS 66 "-L\${exec_prefix}/${OPENCV_LIB_INSTALL_PATH}" 67 "${_modules}" 68 ) 69 if (BUILD_SHARED_LIBS) 70 set(OPENCV_PC_LIBS_PRIVATE "${_extra}") 71 else() 72 set(OPENCV_PC_LIBS_PRIVATE 73 "-L\${exec_prefix}/${OPENCV_3P_LIB_INSTALL_PATH}" 74 "${_3rdparty}" 75 "${_extra}" 76 ) 77 endif() 78 string(REPLACE ";" " " OPENCV_PC_LIBS "${OPENCV_PC_LIBS}") 79 string(REPLACE ";" " " OPENCV_PC_LIBS_PRIVATE "${OPENCV_PC_LIBS_PRIVATE}") 80 81 #generate the .pc file 82 set(prefix "${CMAKE_INSTALL_PREFIX}") 83 set(exec_prefix "\${prefix}") 84 set(libdir "\${exec_prefix}/${OPENCV_LIB_INSTALL_PATH}") 85 set(includedir "\${prefix}/${OPENCV_INCLUDE_INSTALL_PATH}") 86 87 if(INSTALL_TO_MANGLED_PATHS) 88 set(OPENCV_PC_FILE_NAME "opencv-${OPENCV_VERSION}.pc") 89 else() 90 set(OPENCV_PC_FILE_NAME opencv.pc) 91 endif() 92 configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/opencv-XXX.pc.in" 93 "${CMAKE_BINARY_DIR}/unix-install/${OPENCV_PC_FILE_NAME}" 94 @ONLY) 95 96 if(UNIX AND NOT ANDROID) 97 install(FILES ${CMAKE_BINARY_DIR}/unix-install/${OPENCV_PC_FILE_NAME} DESTINATION ${OPENCV_LIB_INSTALL_PATH}/pkgconfig COMPONENT dev) 98 endif() 99