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 12macro(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) 35endmacro() 36 37# build the list of opencv libs and dependencies for all modules 38ocv_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. 48if(_modules MATCHES "opencv_world") 49 set(_modules "opencv_world") 50endif() 51 52if(_modules MATCHES "opencv_contrib_world") 53 list(REMOVE_ITEM _modules "opencv_contrib_world") 54 list(INSERT _modules 0 "opencv_contrib_world") 55endif() 56 57fix_prefix(_modules TRUE) 58fix_prefix(_extra FALSE) 59fix_prefix(_3rdparty TRUE) 60 61ocv_list_unique(_modules) 62ocv_list_unique(_extra) 63ocv_list_unique(_3rdparty) 64 65set(OPENCV_PC_LIBS 66 "-L\${exec_prefix}/${OPENCV_LIB_INSTALL_PATH}" 67 "${_modules}" 68) 69if (BUILD_SHARED_LIBS) 70 set(OPENCV_PC_LIBS_PRIVATE "${_extra}") 71else() 72 set(OPENCV_PC_LIBS_PRIVATE 73 "-L\${exec_prefix}/${OPENCV_3P_LIB_INSTALL_PATH}" 74 "${_3rdparty}" 75 "${_extra}" 76 ) 77endif() 78string(REPLACE ";" " " OPENCV_PC_LIBS "${OPENCV_PC_LIBS}") 79string(REPLACE ";" " " OPENCV_PC_LIBS_PRIVATE "${OPENCV_PC_LIBS_PRIVATE}") 80 81#generate the .pc file 82set(prefix "${CMAKE_INSTALL_PREFIX}") 83set(exec_prefix "\${prefix}") 84set(libdir "\${exec_prefix}/${OPENCV_LIB_INSTALL_PATH}") 85set(includedir "\${prefix}/${OPENCV_INCLUDE_INSTALL_PATH}") 86 87if(INSTALL_TO_MANGLED_PATHS) 88 set(OPENCV_PC_FILE_NAME "opencv-${OPENCV_VERSION}.pc") 89else() 90 set(OPENCV_PC_FILE_NAME opencv.pc) 91endif() 92configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/opencv-XXX.pc.in" 93 "${CMAKE_BINARY_DIR}/unix-install/${OPENCV_PC_FILE_NAME}" 94 @ONLY) 95 96if(UNIX AND NOT ANDROID) 97 install(FILES ${CMAKE_BINARY_DIR}/unix-install/${OPENCV_PC_FILE_NAME} DESTINATION ${OPENCV_LIB_INSTALL_PATH}/pkgconfig COMPONENT dev) 98endif() 99