Skip to content

Commit

Permalink
CMake: bail out if minimum GLib version is not satisfied
Browse files Browse the repository at this point in the history
Require glibconfig.h to be found and extract the version from this file,
this has been present since the original GLib commit and is still
present in the meson build system introduced with 2.53.4.

Bug: 15706
Change-Id: I2e938a339d48d6815ed7cc46462735b93418377f
Reviewed-on: https://code.wireshark.org/review/32894
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: João Valverde <j@v6e.pt>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
(cherry picked from commit 5c47854155273f2468db48fbdce9d969e71519a8)
Reviewed-on: https://code.wireshark.org/review/32899
  • Loading branch information
Lekensteyn committed Apr 19, 2019
1 parent 2a9e0e2 commit 86db127
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
3 changes: 1 addition & 2 deletions CMakeLists.txt
Expand Up @@ -994,9 +994,8 @@ endmacro()

# The minimum package list
find_package(Git)
set(GLIB2_MIN_VERSION 2.32.0)
reset_find_package(GLIB2 GLIB2_MAIN_INCLUDE_DIR GLIB2_INTERNAL_INCLUDE_DIR)
find_package(GLIB2 REQUIRED)
find_package(GLIB2 "2.32.0" REQUIRED)
include_directories(SYSTEM ${GLIB2_INCLUDE_DIRS})
reset_find_package(GMODULE2)
find_package(GMODULE2)
Expand Down
35 changes: 24 additions & 11 deletions cmake/modules/FindGLIB2.cmake
Expand Up @@ -24,19 +24,14 @@ FindWSWinLibs( "glib2-*" "GLIB2_HINTS" )

if (NOT WIN32)
find_package(PkgConfig)

if( GLIB2_MIN_VERSION )
pkg_search_module( GLIB2 glib-2.0>=${GLIB2_MIN_VERSION} )
else()
pkg_search_module( GLIB2 glib-2.0 )
endif()
pkg_search_module( PC_GLIB2 glib-2.0 )
endif()

find_path( GLIB2_MAIN_INCLUDE_DIR
NAMES
glib.h
HINTS
"${GLIB2_INCLUDEDIR}"
"${PC_GLIB2_INCLUDEDIR}"
"${GLIB2_HINTS}/include"
PATH_SUFFIXES
glib-2.0
Expand All @@ -54,7 +49,7 @@ find_library( GLIB2_LIBRARY
glib-2.0
libglib-2.0
HINTS
"${GLIB2_LIBDIR}"
"${PC_GLIB2_LIBDIR}"
"${GLIB2_HINTS}/lib"
PATHS
/opt/gnome/lib64
Expand Down Expand Up @@ -83,11 +78,29 @@ find_path( GLIB2_INTERNAL_INCLUDE_DIR

)

if(PC_GLIB2_VERSION)
set(GLIB2_VERSION ${PC_GLIB2_VERSION})
elseif(GLIB2_INTERNAL_INCLUDE_DIR)
# On systems without pkg-config (e.g. Windows), search its header
# (available since the initial commit of GLib).
file(STRINGS ${GLIB2_INTERNAL_INCLUDE_DIR}/glibconfig.h GLIB_MAJOR_VERSION
REGEX "#define[ ]+GLIB_MAJOR_VERSION[ ]+[0-9]+")
string(REGEX MATCH "[0-9]+" GLIB_MAJOR_VERSION ${GLIB_MAJOR_VERSION})
file(STRINGS ${GLIB2_INTERNAL_INCLUDE_DIR}/glibconfig.h GLIB_MINOR_VERSION
REGEX "#define[ ]+GLIB_MINOR_VERSION[ ]+[0-9]+")
string(REGEX MATCH "[0-9]+" GLIB_MINOR_VERSION ${GLIB_MINOR_VERSION})
file(STRINGS ${GLIB2_INTERNAL_INCLUDE_DIR}/glibconfig.h GLIB_MICRO_VERSION
REGEX "#define[ ]+GLIB_MICRO_VERSION[ ]+[0-9]+")
string(REGEX MATCH "[0-9]+" GLIB_MICRO_VERSION ${GLIB_MICRO_VERSION})
set(GLIB2_VERSION ${GLIB_MAJOR_VERSION}.${GLIB_MINOR_VERSION}.${GLIB_MICRO_VERSION})
else()
set(GLIB2_VERSION "")
endif()

include( FindPackageHandleStandardArgs )
find_package_handle_standard_args( GLIB2
DEFAULT_MSG
GLIB2_LIBRARY
GLIB2_MAIN_INCLUDE_DIR
REQUIRED_VARS GLIB2_LIBRARY GLIB2_MAIN_INCLUDE_DIR GLIB2_INTERNAL_INCLUDE_DIR
VERSION_VAR GLIB2_VERSION
)

if( GLIB2_FOUND )
Expand Down

0 comments on commit 86db127

Please sign in to comment.