decrypt drsuapi attributes
[wireshark-sm.git] / cmake / modules / FindGLIB2.cmake
blob6b3876b52833b0c74414614b4f02e7c4c8537c65
2 # - Try to find the GLIB2 libraries
3 # Once done this will define
5 #  GLIB2_FOUND           - system has glib2
6 #  GLIB2_INCLUDE_DIRS    - the glib2 include directory
7 #  GLIB2_LIBRARIES       - glib2 library
8 #  GLIB2_DLL_DIR_DEBUG   - (Windows) Path to required GLib2 DLLs in debug build.
9 #  GLIB2_DLL_DIR_RELEASE - (Windows) Path to required GLib2 DLLs in release builds.
10 #  GLIB2_DLLS_DEBUG      - (Windows) List of required GLib2 DLLs in debug builds.
11 #  GLIB2_DLLS_RELEASE    - (Windows) List of required GLib2 DLLs in release builds.
13 # Copyright (c) 2008 Laurent Montel, <montel@kde.org>
15 # Redistribution and use is allowed according to the terms of the BSD license.
16 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
19 if( GLIB2_MAIN_INCLUDE_DIR AND GLIB2_LIBRARIES )
20         # Already in cache, be silent
21         set( GLIB2_FIND_QUIETLY TRUE )
22 endif()
24 include( FindWSWinLibs )
25 FindWSWinLibs( "vcpkg-export-*" "GLIB2_HINTS" )
27 if (NOT USE_REPOSITORY)
28         find_package(PkgConfig)
29         pkg_search_module( PC_GLIB2 glib-2.0 )
30 endif()
32 find_path( GLIB2_MAIN_INCLUDE_DIR
33         NAMES
34                 glib.h
35         HINTS
36                 "${PC_GLIB2_INCLUDEDIR}"
37                 "${GLIB2_HINTS}/include"
38         PATH_SUFFIXES
39                 glib-2.0
40                 glib-2.0/include
41         PATHS
42                 /opt/gnome/include
43                 /opt/local/include
44                 /sw/include
45                 /usr/include
46                 /usr/local/include
49 include(FindWSLibrary)
50 FindWSLibrary( GLIB2_LIBRARY
51         NAMES
52                 glib-2.0
53                 libglib-2.0
54         HINTS
55                 "${PC_GLIB2_LIBDIR}"
56         WIN32_HINTS
57             ${GLIB2_HINTS}
58         PATHS
59                 /opt/gnome/lib64
60                 /opt/gnome/lib
61                 /opt/lib/
62                 /opt/local/lib
63                 /sw/lib/
64                 /usr/lib64
65                 /usr/lib
68 if (USE_REPOSITORY)
69         # In the Windows vcpkg port glibconfig.h is in
70         # installed/$ARCH-windows/lib/glib-2.0/include.
71         set( glib2LibDir "${GLIB2_HINTS}/lib" )
72 else()
73         # On UNIX and UNIX-like platforms, the glibconfig.h include dir
74         # should be in glib-2.0/include in the library directory.
75         get_filename_component( glib2LibDir "${GLIB2_LIBRARY}" PATH)
76 endif()
78 find_path( GLIB2_INTERNAL_INCLUDE_DIR
79         NAMES
80                 glibconfig.h
81         HINTS
82                 "${PC_GLIB2_LIBDIR}"
83                 "${glib2LibDir}"
84                 "${GLIB2_INCLUDEDIR}"
85                 ${CMAKE_SYSTEM_LIBRARY_PATH}
86         PATH_SUFFIXES
87                 glib-2.0/include
90 if(PC_GLIB2_VERSION)
91         set(GLIB2_VERSION ${PC_GLIB2_VERSION})
92 elseif(GLIB2_INTERNAL_INCLUDE_DIR)
93         # On systems without pkg-config (e.g. Windows), search its header
94         # (available since the initial commit of GLib).
95         file(STRINGS ${GLIB2_INTERNAL_INCLUDE_DIR}/glibconfig.h GLIB_MAJOR_VERSION
96                 REGEX "#define[ ]+GLIB_MAJOR_VERSION[ ]+[0-9]+")
97         string(REGEX MATCH "[0-9]+" GLIB_MAJOR_VERSION ${GLIB_MAJOR_VERSION})
98         file(STRINGS ${GLIB2_INTERNAL_INCLUDE_DIR}/glibconfig.h GLIB_MINOR_VERSION
99                 REGEX "#define[ ]+GLIB_MINOR_VERSION[ ]+[0-9]+")
100         string(REGEX MATCH "[0-9]+" GLIB_MINOR_VERSION ${GLIB_MINOR_VERSION})
101         file(STRINGS ${GLIB2_INTERNAL_INCLUDE_DIR}/glibconfig.h GLIB_MICRO_VERSION
102                 REGEX "#define[ ]+GLIB_MICRO_VERSION[ ]+[0-9]+")
103         string(REGEX MATCH "[0-9]+" GLIB_MICRO_VERSION ${GLIB_MICRO_VERSION})
104         set(GLIB2_VERSION ${GLIB_MAJOR_VERSION}.${GLIB_MINOR_VERSION}.${GLIB_MICRO_VERSION})
105 else()
106         # When using VERSION_VAR it must be set to a valid value or undefined to
107         # mean "not found". It's not enough to use the empty string or any other CMake false boolean.
108         unset(GLIB2_VERSION)
109 endif()
111 include( FindPackageHandleStandardArgs )
112 find_package_handle_standard_args( GLIB2
113         REQUIRED_VARS   GLIB2_LIBRARY GLIB2_MAIN_INCLUDE_DIR GLIB2_INTERNAL_INCLUDE_DIR
114         VERSION_VAR     GLIB2_VERSION
117 if( GLIB2_FOUND )
118         set( GLIB2_LIBRARIES ${GLIB2_LIBRARY} )
119         # Include transitive dependencies for static linking.
120         if(UNIX AND CMAKE_FIND_LIBRARY_SUFFIXES STREQUAL ".a")
121                 find_library(PCRE_LIBRARY pcre)
122                 list(APPEND GLIB2_LIBRARIES -pthread ${PCRE_LIBRARY})
123         endif()
124         set( GLIB2_INCLUDE_DIRS ${GLIB2_MAIN_INCLUDE_DIR} ${GLIB2_INTERNAL_INCLUDE_DIR} )
125         if ( USE_REPOSITORY AND GLIB2_FOUND )
126                 set ( GLIB2_DLL_DIR_RELEASE "${GLIB2_HINTS}/bin"
127                         CACHE PATH "Path to GLib2 release DLLs"
128                 )
129                 set ( GLIB2_DLL_DIR_DEBUG "${GLIB2_HINTS}/debug/bin"
130                         CACHE PATH "Path to GLib2 debug DLLs"
131                 )
133                 # GTK+ required GObject and GIO. We probably don't.
134                 file( GLOB _glib2_dlls_release RELATIVE "${GLIB2_DLL_DIR_RELEASE}"
135                         # "${GLIB2_DLL_DIR_RELEASE}/gio-2.0-0.dll"
136                         "${GLIB2_DLL_DIR_RELEASE}/glib-2.0-0.dll"
137                         "${GLIB2_DLL_DIR_RELEASE}/gmodule-2.0-0.dll"
138                         # "${GLIB2_DLL_DIR_RELEASE}/gobject-2.0-0.dll"
139                         "${GLIB2_DLL_DIR_RELEASE}/gthread-2.0-0.dll"
140                         "${GLIB2_DLL_DIR_RELEASE}/charset-1.dll"
141                         # gnutls-3.6.3-1-win64ws ships with libffi-6.dll
142                         # "${GLIB2_DLL_DIR_RELEASE}/libffi.dll"
143                         "${GLIB2_DLL_DIR_RELEASE}/iconv-2.dll"
144                         "${GLIB2_DLL_DIR_RELEASE}/intl-8.dll"
145                 )
146                 set ( GLIB2_DLLS_RELEASE ${_glib2_dlls_release}
147                         # We're storing filenames only. Should we use STRING instead?
148                         CACHE FILEPATH "GLib 2 release DLL list"
149                 )
150                 file( GLOB _glib2_dlls_debug RELATIVE "${GLIB2_DLL_DIR_DEBUG}"
151                         # "${GLIB2_DLL_DIR_DEBUG}/gio-2.0-0.dll"
152                         "${GLIB2_DLL_DIR_DEBUG}/glib-2.0-0.dll"
153                         "${GLIB2_DLL_DIR_DEBUG}/gmodule-2.0-0.dll"
154                         # "${GLIB2_DLL_DIR_DEBUG}/gobject-2.0-0.dll"
155                         "${GLIB2_DLL_DIR_DEBUG}/gthread-2.0-0.dll"
156                         "${GLIB2_DLL_DIR_DEBUG}/charset-1.dll"
157                         # gnutls-3.6.3-1-win64ws ships with libffi-6.dll
158                         # "${GLIB2_DLL_DIR_DEBUG}/libffi.dll"
159                         "${GLIB2_DLL_DIR_DEBUG}/iconv-2.dll"
160                         "${GLIB2_DLL_DIR_DEBUG}/intl-8.dll"
161                 )
162                 set ( GLIB2_DLLS_DEBUG ${_glib2_dlls_debug}
163                         # We're storing filenames only. Should we use STRING instead?
164                         CACHE FILEPATH "GLib 2 debug DLL list"
165                 )
167                 file( GLOB _glib2_pdbs_release RELATIVE "${GLIB2_DLL_DIR_RELEASE}"
168                         "${GLIB2_DLL_DIR_RELEASE}/glib-2.0-0.pdb"
169                         "${GLIB2_DLL_DIR_RELEASE}/gmodule-2.0-0.pdb"
170                         "${GLIB2_DLL_DIR_RELEASE}/gthread-2.0-0.pdb"
171                         # "${GLIB2_DLL_DIR_RELEASE}/libcharset.pdb"
172                         # "${GLIB2_DLL_DIR_RELEASE}/libiconv.pdb"
173                         # "${GLIB2_DLL_DIR_RELEASE}/libintl.pdb"
174                 )
175                 set ( GLIB2_PDBS_RELEASE ${_glib2_pdbs_release}
176                         CACHE FILEPATH "GLib2 debug release PDB list"
177                 )
178                 file( GLOB _glib2_pdbs_debug RELATIVE "${GLIB2_DLL_DIR_DEBUG}"
179                         "${GLIB2_DLL_DIR_DEBUG}/glib-2.0-0.pdb"
180                         "${GLIB2_DLL_DIR_DEBUG}/gmodule-2.0-0.pdb"
181                         "${GLIB2_DLL_DIR_DEBUG}/gthread-2.0-0.pdb"
182                         # "${GLIB2_DLL_DIR_DEBUG}/libcharset.pdb"
183                         # "${GLIB2_DLL_DIR_DEBUG}/libiconv.pdb"
184                         # "${GLIB2_DLL_DIR_DEBUG}/libintl.pdb"
185                 )
186                 set ( GLIB2_PDBS_DEBUG ${_glib2_pdbs_debug}
187                         CACHE FILEPATH "GLib2 debug debug PDB list"
188                 )
190                 mark_as_advanced( GLIB2_DLL_DIR_RELEASE GLIB2_DLLS_RELEASE GLIB2_PDBS_RELEASE )
191                 mark_as_advanced( GLIB2_DLL_DIR_DEBUG GLIB2_DLLS_DEBUG GLIB2_PDBS_DEBUG )
192         endif()
193 elseif( GLIB2_FIND_REQUIRED )
194         message( SEND_ERROR "Package required but not found" )
195 else()
196         set( GLIB2_LIBRARIES )
197         set( GLIB2_MAIN_INCLUDE_DIRS )
198         set( GLIB2_DLL_DIR_RELEASE )
199         set( GLIB2_DLL_DIR_DEBUG )
200         set( GLIB2_PDBS_RELEASE )
201         set( GLIB2_PDBS_DEBUG )
202         set( GLIB2_DLLS )
203 endif()
205 mark_as_advanced( GLIB2_INCLUDE_DIRS GLIB2_LIBRARIES )