[GTK] Use --version-script only on Linux
[WebKit-https.git] / Source / cmake / FindGObjectIntrospection.cmake
1 # - Try to find gobject-introspection
2 # Once done, this will define
3 #
4 #  INTROSPECTION_FOUND - system has gobject-introspection
5 #  INTROSPECTION_SCANNER - the gobject-introspection scanner, g-ir-scanner
6 #  INTROSPECTION_COMPILER - the gobject-introspection compiler, g-ir-compiler
7 #  INTROSPECTION_GENERATE - the gobject-introspection generate, g-ir-generate
8 #  INTROSPECTION_GIRDIR
9 #  INTROSPECTION_TYPELIBDIR
10 #  INTROSPECTION_CFLAGS
11 #  INTROSPECTION_LIBS
12 #
13 # Copyright (C) 2010, Pino Toscano, <pino@kde.org>
14 # Copyright (C) 2014 Igalia S.L.
15 #
16 # Redistribution and use is allowed according to the terms of the BSD license.
17
18 macro(_GIR_GET_PKGCONFIG_VAR _outvar _varname _extra_args)
19     execute_process(
20         COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=${_varname} ${_extra_args} gobject-introspection-1.0
21         OUTPUT_VARIABLE _result
22         RESULT_VARIABLE _null
23     )
24
25     if (_null)
26     else ()
27         string(REGEX REPLACE "[\r\n]" " " _result "${_result}")
28         string(REGEX REPLACE " +$" ""  _result "${_result}")
29         separate_arguments(_result)
30         set(${_outvar} ${_result} CACHE INTERNAL "")
31     endif ()
32 endmacro(_GIR_GET_PKGCONFIG_VAR)
33
34 find_package(PkgConfig)
35 if (PKG_CONFIG_FOUND)
36     if (PACKAGE_FIND_VERSION_COUNT GREATER 0)
37         set(_gir_version_cmp ">=${PACKAGE_FIND_VERSION}")
38     endif ()
39     pkg_check_modules(_pc_gir gobject-introspection-1.0${_gir_version_cmp})
40     if (_pc_gir_FOUND)
41         set(INTROSPECTION_FOUND TRUE)
42         _gir_get_pkgconfig_var(INTROSPECTION_SCANNER "g_ir_scanner" "")
43         _gir_get_pkgconfig_var(INTROSPECTION_COMPILER "g_ir_compiler" "")
44         _gir_get_pkgconfig_var(INTROSPECTION_GENERATE "g_ir_generate" "")
45         _gir_get_pkgconfig_var(INTROSPECTION_GIRDIR "girdir" "")
46         _gir_get_pkgconfig_var(INTROSPECTION_TYPELIBDIR "typelibdir" "")
47         set(INTROSPECTION_CFLAGS "${_pc_gir_CFLAGS}")
48         set(INTROSPECTION_LIBS "${_pc_gir_LIBS}")
49     endif ()
50 endif ()
51
52 mark_as_advanced(
53     INTROSPECTION_SCANNER
54     INTROSPECTION_COMPILER
55     INTROSPECTION_GENERATE
56     INTROSPECTION_GIRDIR
57     INTROSPECTION_TYPELIBDIR
58     INTROSPECTION_CFLAGS
59     INTROSPECTION_LIBS
60 )