Commit 3863dc5b authored by Maksim Shabunin's avatar Maksim Shabunin

Updated pkg-config generation, added sample makefile

parent 671a630f
...@@ -769,6 +769,11 @@ else() ...@@ -769,6 +769,11 @@ else()
endif() endif()
status(" Precompiled headers:" PCHSupport_FOUND AND ENABLE_PRECOMPILED_HEADERS THEN YES ELSE NO) status(" Precompiled headers:" PCHSupport_FOUND AND ENABLE_PRECOMPILED_HEADERS THEN YES ELSE NO)
# ========================== Dependencies ============================
ocv_get_all_libs(deps_modules deps_extra deps_3rdparty)
status(" Extra dependencies:" ${deps_extra})
status(" 3rdparty dependencies:" ${deps_3rdparty})
# ========================== OpenCV modules ========================== # ========================== OpenCV modules ==========================
status("") status("")
status(" OpenCV modules:") status(" OpenCV modules:")
...@@ -909,7 +914,7 @@ else() ...@@ -909,7 +914,7 @@ else()
endif() endif()
if( WITH_GDAL ) if( WITH_GDAL )
status(" GDAL:" GDAL_FOUND THEN "${GDAL_LIBRARY}") status(" GDAL:" GDAL_FOUND THEN "${GDAL_LIBRARY}" ELSE "NO")
else() else()
status(" GDAL:" "NO") status(" GDAL:" "NO")
endif() endif()
......
...@@ -9,26 +9,33 @@ ...@@ -9,26 +9,33 @@
# ${BIN_DIR}/unix-install/opencv.pc -> For use *with* "make install" # ${BIN_DIR}/unix-install/opencv.pc -> For use *with* "make install"
# ------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------
if(CMAKE_BUILD_TYPE MATCHES "Release") macro(fix_prefix lst isown)
set(ocv_optkind OPT) set(_lst)
else() foreach(item ${${lst}})
set(ocv_optkind DBG) if(TARGET ${item})
endif() get_target_property(item "${item}" LOCATION_${CMAKE_BUILD_TYPE})
if("${isown}")
#build the list of opencv libs and dependencies for all modules get_filename_component(item "${item}" NAME_WE)
set(OpenCV_LIB_COMPONENTS "") string(REGEX REPLACE "^lib(.*)" "\\1" item "${item}")
set(OpenCV_EXTRA_COMPONENTS "")
foreach(m ${OPENCV_MODULES_PUBLIC})
list(INSERT OpenCV_LIB_COMPONENTS 0 ${${m}_MODULE_DEPS_${ocv_optkind}} ${m})
if(${m}_EXTRA_DEPS_${ocv_optkind})
list(INSERT OpenCV_EXTRA_COMPONENTS 0 ${${m}_EXTRA_DEPS_${ocv_optkind}})
endif() endif()
endforeach() endif()
if(item MATCHES "^-l")
list(APPEND _lst "${item}")
elseif(item MATCHES "[\\/]")
get_filename_component(libdir "${item}" PATH)
get_filename_component(libname "${item}" NAME_WE)
string(REGEX REPLACE "^lib(.*)" "\\1" libname "${libname}")
list(APPEND _lst "-L${libdir}" "-l${libname}")
else()
list(APPEND _lst "-l${item}")
endif()
endforeach()
set(${lst} ${_lst})
unset(_lst)
endmacro()
ocv_list_unique(OpenCV_LIB_COMPONENTS) # build the list of opencv libs and dependencies for all modules
ocv_list_unique(OpenCV_EXTRA_COMPONENTS) ocv_get_all_libs(_modules _extra _3rdparty)
ocv_list_reverse(OpenCV_LIB_COMPONENTS)
ocv_list_reverse(OpenCV_EXTRA_COMPONENTS)
#build the list of components #build the list of components
...@@ -38,57 +45,38 @@ ocv_list_reverse(OpenCV_EXTRA_COMPONENTS) ...@@ -38,57 +45,38 @@ ocv_list_reverse(OpenCV_EXTRA_COMPONENTS)
# world and contrib_world are special targets whose library should come first, # world and contrib_world are special targets whose library should come first,
# especially for static link. # especially for static link.
if(OpenCV_LIB_COMPONENTS MATCHES "opencv_world") if(_modules MATCHES "opencv_world")
list(REMOVE_ITEM OpenCV_LIB_COMPONENTS "opencv_world") set(_modules "opencv_world")
list(INSERT OpenCV_LIB_COMPONENTS 0 "opencv_world")
endif() endif()
if(OpenCV_LIB_COMPONENTS MATCHES "opencv_contrib_world") if(_modules MATCHES "opencv_contrib_world")
list(REMOVE_ITEM OpenCV_LIB_COMPONENTS "opencv_contrib_world") list(REMOVE_ITEM _modules "opencv_contrib_world")
list(INSERT OpenCV_LIB_COMPONENTS 0 "opencv_contrib_world") list(INSERT _modules 0 "opencv_contrib_world")
endif() endif()
set(OpenCV_LIB_COMPONENTS_) fix_prefix(_modules TRUE)
foreach(CVLib ${OpenCV_LIB_COMPONENTS}) fix_prefix(_extra FALSE)
fix_prefix(_3rdparty TRUE)
get_target_property(libloc ${CVLib} LOCATION_${CMAKE_BUILD_TYPE})
if(libloc MATCHES "3rdparty")
set(libpath "\${exec_prefix}/share/OpenCV/3rdparty/${OPENCV_LIB_INSTALL_PATH}")
else()
set(libpath "\${exec_prefix}/${OPENCV_LIB_INSTALL_PATH}")
endif()
list(APPEND OpenCV_LIB_COMPONENTS_ "-L${libpath}")
get_filename_component(libname ${CVLib} NAME_WE)
string(REGEX REPLACE "^lib" "" libname "${libname}")
list(APPEND OpenCV_LIB_COMPONENTS_ "-l${libname}")
endforeach()
# add extra dependencies required for OpenCV ocv_list_unique(_modules)
if(OpenCV_EXTRA_COMPONENTS) ocv_list_unique(_extra)
foreach(extra_component ${OpenCV_EXTRA_COMPONENTS}) ocv_list_unique(_3rdparty)
if(extra_component MATCHES "^-[lL]") set(OPENCV_PC_LIBS
set(libprefix "") "-L\${exec_prefix}/${OPENCV_LIB_INSTALL_PATH}"
set(libname "${extra_component}") "${_modules}"
elseif(extra_component MATCHES "[\\/]") )
get_filename_component(libdir "${extra_component}" PATH) if (BUILD_SHARED_LIBS)
list(APPEND OpenCV_LIB_COMPONENTS_ "-L${libdir}") set(OPENCV_PC_LIBS_PRIVATE "${_extra}")
get_filename_component(libname "${extra_component}" NAME_WE) else()
string(REGEX REPLACE "^lib" "" libname "${libname}") set(OPENCV_PC_LIBS_PRIVATE
set(libprefix "-l") "-L\${exec_prefix}/${OPENCV_3P_LIB_INSTALL_PATH}"
else() "${_3rdparty}"
set(libprefix "-l") "${_extra}"
set(libname "${extra_component}") )
endif()
list(APPEND OpenCV_LIB_COMPONENTS_ "${libprefix}${libname}")
endforeach()
endif() endif()
string(REPLACE ";" " " OPENCV_PC_LIBS "${OPENCV_PC_LIBS}")
list(REMOVE_DUPLICATES OpenCV_LIB_COMPONENTS_) string(REPLACE ";" " " OPENCV_PC_LIBS_PRIVATE "${OPENCV_PC_LIBS_PRIVATE}")
string(REPLACE ";" " " OpenCV_LIB_COMPONENTS "${OpenCV_LIB_COMPONENTS_}")
#generate the .pc file #generate the .pc file
set(prefix "${CMAKE_INSTALL_PREFIX}") set(prefix "${CMAKE_INSTALL_PREFIX}")
......
...@@ -796,18 +796,33 @@ macro(ocv_get_all_libs _modules _extra _3rdparty) ...@@ -796,18 +796,33 @@ macro(ocv_get_all_libs _modules _extra _3rdparty)
set(${_3rdparty} "") set(${_3rdparty} "")
foreach(m ${OPENCV_MODULES_PUBLIC}) foreach(m ${OPENCV_MODULES_PUBLIC})
get_target_property(deps ${m} INTERFACE_LINK_LIBRARIES) get_target_property(deps ${m} INTERFACE_LINK_LIBRARIES)
if(NOT deps)
set(deps "")
endif()
list(INSERT ${_modules} 0 ${deps} ${m}) list(INSERT ${_modules} 0 ${deps} ${m})
foreach (dep ${deps} ${OPENCV_LINKER_LIBS}) foreach (dep ${deps} ${OPENCV_LINKER_LIBS})
if (NOT DEFINED OPENCV_MODULE_${dep}_LOCATION) if (NOT DEFINED OPENCV_MODULE_${dep}_LOCATION)
if (TARGET ${dep}) if (TARGET ${dep})
get_target_property(_output ${dep} ARCHIVE_OUTPUT_DIRECTORY)
if ("${_output}" STREQUAL "${3P_LIBRARY_OUTPUT_PATH}")
list(INSERT ${_3rdparty} 0 ${dep}) list(INSERT ${_3rdparty} 0 ${dep})
else() else()
list(INSERT ${_extra} 0 ${dep}) list(INSERT ${_extra} 0 ${dep})
endif() endif()
else()
list(INSERT ${_extra} 0 ${dep})
endif()
endif() endif()
endforeach() endforeach()
endforeach() endforeach()
# ippicv specific handling
list(FIND ${_extra} "ippicv" ippicv_idx)
if (${ippicv_idx} GREATER -1)
list(REMOVE_ITEM ${_extra} "ippicv")
list(INSERT ${_3rdparty} 0 "ippicv")
endif()
# split 3rdparty libs and modules # split 3rdparty libs and modules
list(REMOVE_ITEM ${_modules} ${${_3rdparty}} ${${_extra}}) list(REMOVE_ITEM ${_modules} ${${_3rdparty}} ${${_extra}})
......
...@@ -9,5 +9,6 @@ includedir_new=@includedir@ ...@@ -9,5 +9,6 @@ includedir_new=@includedir@
Name: OpenCV Name: OpenCV
Description: Open Source Computer Vision Library Description: Open Source Computer Vision Library
Version: @OPENCV_VERSION_PLAIN@ Version: @OPENCV_VERSION_PLAIN@
Libs: @OpenCV_LIB_COMPONENTS@ Libs: @OPENCV_PC_LIBS@
Libs.private: @OPENCV_PC_LIBS_PRIVATE@
Cflags: -I${includedir_old} -I${includedir_new} Cflags: -I${includedir_old} -I${includedir_new}
...@@ -3,7 +3,7 @@ if (WINRT) ...@@ -3,7 +3,7 @@ if (WINRT)
endif() endif()
set(the_description "High-level GUI and Media I/O") set(the_description "High-level GUI and Media I/O")
ocv_add_module(highgui opencv_imgproc opencv_imgcodecs opencv_videoio OPTIONAL opencv_androidcamera WRAP python) ocv_add_module(highgui opencv_imgproc opencv_imgcodecs opencv_videoio WRAP python)
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
# CMake file for highgui. See root CMakeLists.txt # CMake file for highgui. See root CMakeLists.txt
......
...@@ -9,7 +9,7 @@ set(OPENCV_MODULE_IS_PART_OF_WORLD FALSE) ...@@ -9,7 +9,7 @@ set(OPENCV_MODULE_IS_PART_OF_WORLD FALSE)
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wundef) ocv_warnings_disable(CMAKE_CXX_FLAGS -Wundef)
ocv_add_module(ts opencv_core opencv_imgproc opencv_imgcodecs opencv_videoio opencv_highgui) ocv_add_module(ts INTERNAL opencv_core opencv_imgproc opencv_imgcodecs opencv_videoio opencv_highgui)
ocv_glob_module_sources() ocv_glob_module_sources()
ocv_module_include_directories() ocv_module_include_directories()
......
CXX ?= g++
CXXFLAGS += -c -Wall $(shell pkg-config --cflags opencv)
LDFLAGS += $(shell pkg-config --libs --static opencv)
all: opencv_example
opencv_example: example.o; $(CXX) $< -o $@ $(LDFLAGS)
%.o: %.cpp; $(CXX) $< -o $@ $(CXXFLAGS)
clean: ; rm -f example.o opencv_example
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment