Skip to content

Commit

Permalink
Improve package version detection when pkg-config not installed
Browse files Browse the repository at this point in the history
  • Loading branch information
fspindle committed Mar 20, 2024
1 parent 065750b commit dc6112a
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 14 deletions.
3 changes: 2 additions & 1 deletion cmake/FindComedi.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ find_library(COMEDI_LIBRARIES
if(COMEDI_LIBRARIES AND COMEDI_INCLUDE_DIRS)
set(COMEDI_FOUND TRUE)

vp_get_version_from_pkg("comedilib" COMEDI_VERSION)
get_filename_component(COMEDI_LIB_DIR ${COMEDI_LIBRARIES} PATH)
vp_get_version_from_pkg("comedilib" "${COMEDI_LIB_DIR}/pkgconfig" COMEDI_VERSION)

else()
set(COMEDI_FOUND FALSE)
Expand Down
3 changes: 2 additions & 1 deletion cmake/FindDC1394.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ else(NOT UNIX)

endif()

vp_get_version_from_pkg("libdc1394-2" DC1394_VERSION)
get_filename_component(DC1394_LIB_DIR ${DC1394_LIBRARY} PATH)
vp_get_version_from_pkg("libdc1394-2" "${DC1394_LIB_DIR}/pkgconfig" DC1394_VERSION)

endif()

Expand Down
3 changes: 2 additions & 1 deletion cmake/FindDMTX.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ find_library(DMTX_LIBRARIES
if(DMTX_INCLUDE_DIRS AND DMTX_LIBRARIES)
set(DMTX_FOUND TRUE)

vp_get_version_from_pkg("libdmtx" DMTX_VERSION)
get_filename_component(DMTX_LIB_DIR ${DMTX_LIBRARIES} PATH)
vp_get_version_from_pkg("libdmtx" "${DMTX_LIB_DIR}/pkgconfig" DMTX_VERSION)

else()
set(DMTX_FOUND FALSE)
Expand Down
7 changes: 4 additions & 3 deletions cmake/FindGSL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ else()
if(BUILD_SUCCEED1)
set(GSL_FOUND TRUE)

vp_get_version_from_pkg("gsl" GSL_VERSION)

get_filename_component(GSL_LIB_DIR ${GSL_gsl_LIBRARY} PATH)
vp_get_version_from_pkg("gsl" "${GSL_LIB_DIR}/pkgconfig" GSL_VERSION)
else()
set(GSL_FOUND FALSE)
endif()
Expand All @@ -167,7 +167,8 @@ else()
if(BUILD_SUCCEED2)
set(GSL_FOUND TRUE)

vp_get_version_from_pkg("gsl" GSL_VERSION)
get_filename_component(GSL_LIB_DIR ${GSL_gsl_LIBRARY} PATH)
vp_get_version_from_pkg("gsl" "${GSL_LIB_DIR}/pkgconfig" GSL_VERSION)
else()
set(GSL_FOUND FALSE)
endif()
Expand Down
2 changes: 1 addition & 1 deletion cmake/FindLIBFREENECT.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ if(LIBFREENECT_LIBRARY AND LIBFREENECT_HPP_INCLUDE_DIR AND LIBFREENECT_H_INCLUDE
set(LIBFREENECT_FOUND TRUE)

get_filename_component(LIBFREENECT_LIB_DIR ${LIBFREENECT_LIBRARY} PATH)
vp_get_version_from_pkg("libfreenect" LIBFREENECT_VERSION)
vp_get_version_from_pkg("libfreenect" "${LIBFREENECT_LIB_DIR}/pkgconfig" LIBFREENECT_VERSION)
else()
set(LIBFREENECT_FOUND FALSE)
endif()
Expand Down
6 changes: 5 additions & 1 deletion cmake/FindLIBUSB_1.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ if(LIBUSB_1_LIBRARY AND LIBUSB_1_INCLUDE_DIR)
set(LIBUSB_1_LIBRARIES ${LIBUSB_1_LIBRARY})
set(LIBUSB_1_FOUND TRUE)

vp_get_version_from_pkg("libusb-1.0" LIBUSB_1_VERSION)
get_filename_component(LIBUSB_1_LIB_DIR ${LIBUSB_1_LIBRARY} PATH)
vp_get_version_from_pkg("libusb" "${LIBUSB_1_LIB_DIR}/pkgconfig" LIBUSB_1_VERSION)
if(NOT LIBUSB_1_VERSION)
vp_get_version_from_pkg("libusb-1.0" "${LIBUSB_1_LIB_DIR}/pkgconfig" LIBUSB_1_VERSION)
endif()
else()
set(LIBUSB_1_FOUND FALSE)
endif()
Expand Down
3 changes: 2 additions & 1 deletion cmake/FindMyGTK2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ if(UNIX OR WIN32)
${GTK2_glib_LIBRARY}
${GTK2_gobject_LIBRARY})

vp_get_version_from_pkg("gtk+-2.0" GTK2_VERSION)
get_filename_component(GTK2_LIB_DIR ${GTK2_gtk_LIBRARY} PATH)
vp_get_version_from_pkg("gtk+-2.0" "${GTK2_LIB_DIR}/pkgconfig" GTK2_VERSION)

if(GTK2_gmodule_LIBRARY)
list(APPEND GTK2_LIBRARIES ${GTK2_gmodule_LIBRARY})
Expand Down
3 changes: 2 additions & 1 deletion cmake/FindMyPNG.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ if(UNIX)
set(PNG_INCLUDE_DIRS ${PNG_INCLUDE_DIR})
set(PNG_LIBRARIES ${PNG_LIBRARY})

vp_get_version_from_pkg("libpng" PNG_VERSION_STRING)
get_filename_component(PNG_LIB_DIR ${PNG_LIBRARY} DIRECTORY)
vp_get_version_from_pkg("libpng" "${PNG_LIB_DIR}/pkgconfig" PNG_VERSION_STRING)

set(PNG_FOUND TRUE)

Expand Down
3 changes: 2 additions & 1 deletion cmake/FindNetlib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ else(WIN32)
set(NETLIB_LIBRARIES ${NETLIB_LIBRARY_LAPACK} ${NETLIB_LIBRARY_BLAS})
set(NETLIB_FOUND TRUE)

vp_get_version_from_pkg("lapack" NETLIB_VERSION)
get_filename_component(NETLIB_LIB_DIR ${NETLIB_LIBRARY_LAPACK} PATH)
vp_get_version_from_pkg("lapack" "${NETLIB_LIB_DIR}/pkgconfig" NETLIB_VERSION)

endif()
endif(WIN32)
Expand Down
3 changes: 2 additions & 1 deletion cmake/FindV4L2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ else(NOT UNIX)
set(V4L2_LIBRARIES ${V4L2_LIBRARY_LIBV4L2} ${V4L2_LIBRARY_LIBV4LCONVERT})
set(V4L2_FOUND TRUE)

vp_get_version_from_pkg("libv4l2" V4L2_VERSION)
get_filename_component(V4L2_LIB_DIR ${V4L2_LIBRARY_LIBV4L2} PATH)
vp_get_version_from_pkg("libv4l2" "${V4L2_LIB_DIR}/pkgconfig" V4L2_VERSION)
else()
set(V4L2_FOUND FALSE)
endif()
Expand Down
3 changes: 2 additions & 1 deletion cmake/FindZBAR.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ if(ZBAR_FOUND)
vp_parse_header("${ZBAR_INCLUDE_DIRS}/config.h" ZBAR_VERSION_LINES LIB_VERSION_MAJOR LIB_VERSION_MINOR LIB_VERSION_REVISION)
set(ZBAR_VERSION "${LIB_VERSION_MAJOR}.${LIB_VERSION_MINOR}.${LIB_VERSION_REVISION}")
else()
vp_get_version_from_pkg("zbar" ZBAR_VERSION)
get_filename_component(ZBAR_LIB_DIR ${ZBAR_LIBRARIES} PATH)
vp_get_version_from_pkg("zbar" "${ZBAR_LIB_DIR}/pkgconfig" ZBAR_VERSION)
endif()
endif()

Expand Down
6 changes: 5 additions & 1 deletion cmake/VISPUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1332,7 +1332,7 @@ macro(vp_parse_header4 LIBNAME HDR_PATH DEFINE_NAME OUTPUT_VAR)
endmacro()

# Get package version from pkg-config
macro(vp_get_version_from_pkg LIBNAME OUTPUT_VAR)
macro(vp_get_version_from_pkg LIBNAME PKG_PATH OUTPUT_VAR)
find_package(PkgConfig)
if(PkgConfig_FOUND)
# Since pkg_check_modules updates not only <xxx>_VERSION but also <xxx>_FOUND, <xxx>_INCLUDE_DIRS and <xxx>_LIBRARIES
Expand Down Expand Up @@ -1360,6 +1360,10 @@ macro(vp_get_version_from_pkg LIBNAME OUTPUT_VAR)
if(${LIBNAME_UPPER}_VERSION)
set(${OUTPUT_VAR} ${${LIBNAME_UPPER}_VERSION})
endif()
elseif(EXISTS "${PKG_PATH}/${LIBNAME}.pc")
# Consider the case where pkg-config is not installed
file(STRINGS "${PKG_PATH}/${LIBNAME}.pc" line_to_parse REGEX "^Version:[ \t]+[0-9.]*.*$" LIMIT_COUNT 1)
string(REGEX REPLACE ".*Version: ([^ ]+).*" "\\1" ${OUTPUT_VAR} "${line_to_parse}" )
endif()
endmacro()

Expand Down

0 comments on commit dc6112a

Please sign in to comment.