Commit ce8d0395 authored by Pino Toscano's avatar Pino Toscano
Browse files

[CMake/glib] add support for gobject-introspection

other than a module to find (using pkg-config) gobject-introspection, this adds a macro (gir_add_introspections) to add new introspections in a directory.
its working is much similar (even the variable names used) to the Makefile version provided by gobject-repository itself, with the notable difference of a disabled libtool in the g-ir-scanner invocation.
the only additional step needed is adding two custom targets, compiled by ALL, which have the gir and the typelib files as dependencies, to make them build with the usual `make all'.
parent 78bf43d8
......@@ -93,7 +93,8 @@ if(CAIRO_FOUND)
if(GLIB_FOUND)
set(ENABLE_GLIB ON)
# Check for introspection
# TODO: GOBJECT_INTROSPECTION_CHECK([0.6.7])
macro_optional_find_package(GObjectIntrospection 0.6.7)
set(HAVE_INTROSPECTION ${INTROSPECTION_FOUND})
set(GLIB_REQ "glib-2.0 >= ${GLIB_REQUIRED} gobject-2.0 >= ${GLIB_REQUIRED} cairo >= ${CAIRO_VERSION}")
set(POPPLER_GLIB_DISABLE_DEPRECATED "${POPPLER_GLIB_DISABLE_DEPRECATED} -DG_DISABLE_DEPRECATED")
set(POPPLER_GLIB_DISABLE_SINGLE_INCLUDES "${POPPLER_GLIB_DISABLE_SINGLE_INCLUDES} -DG_DISABLE_SINGLE_INCLUDES")
......@@ -577,7 +578,7 @@ show_end_message_yesno("qt wrapper" QT3_FOUND)
show_end_message_yesno("qt4 wrapper" QT4_FOUND)
show_end_message_yesno("glib wrapper" ENABLE_GLIB)
show_end_message_yesno(" use GDK" POPPLER_WITH_GDK)
show_end_message(" introspection" "not supported with this CMake build system")
show_end_message_yesno(" introspection" INTROSPECTION_FOUND)
show_end_message_yesno("cpp wrapper" ENABLE_CPP)
show_end_message("use gtk-doc" "not supported with this CMake build system")
show_end_message_yesno("use libjpeg" ENABLE_LIBJPEG)
......
# - try to find gobject-introspection
#
# Once done this will define
#
# INTROSPECTION_FOUND - system has gobject-introspection
# INTROSPECTION_SCANNER - the gobject-introspection scanner, g-ir-scanner
# INTROSPECTION_COMPILER - the gobject-introspection compiler, g-ir-compiler
# INTROSPECTION_GENERATE - the gobject-introspection generate, g-ir-generate
# INTROSPECTION_GIRDIR
# INTROSPECTION_TYPELIBDIR
# INTROSPECTION_CFLAGS
# INTROSPECTION_LIBS
#
# Copyright (C) 2010, Pino Toscano, <pino@kde.org>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
macro(_GIR_GET_PKGCONFIG_VAR _outvar _varname)
execute_process(
COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=${_varname} gobject-introspection-1.0
OUTPUT_VARIABLE _result
RESULT_VARIABLE _null
)
if (_null)
else()
string(REGEX REPLACE "[\r\n]" " " _result "${_result}")
string(REGEX REPLACE " +$" "" _result "${_result}")
separate_arguments(_result)
set(${_outvar} ${_result} CACHE INTERNAL "")
endif()
endmacro(_GIR_GET_PKGCONFIG_VAR)
find_package(PkgConfig)
if(PKG_CONFIG_FOUND)
if(PACKAGE_FIND_VERSION_COUNT GREATER 0)
set(_gir_version_cmp ">=${PACKAGE_FIND_VERSION}")
endif()
pkg_check_modules(_pc_gir gobject-introspection-1.0${_gir_version_cmp})
if(_pc_gir_FOUND)
set(INTROSPECTION_FOUND TRUE)
_gir_get_pkgconfig_var(INTROSPECTION_SCANNER "g_ir_scanner")
_gir_get_pkgconfig_var(INTROSPECTION_COMPILER "g_ir_compiler")
_gir_get_pkgconfig_var(INTROSPECTION_GENERATE "g_ir_generate")
_gir_get_pkgconfig_var(INTROSPECTION_GIRDIR "girdir")
_gir_get_pkgconfig_var(INTROSPECTION_TYPELIBDIR "typelibdir")
set(INTROSPECTION_CFLAGS "${_pc_gir_CFLAGS}")
set(INTROSPECTION_LIBS "${_pc_gir_LIBS}")
endif()
endif()
mark_as_advanced(
INTROSPECTION_SCANNER
INTROSPECTION_COMPILER
INTROSPECTION_GENERATE
INTROSPECTION_GIRDIR
INTROSPECTION_TYPELIBDIR
INTROSPECTION_CFLAGS
INTROSPECTION_LIBS
)
# Copyright (C) 2010, Pino Toscano, <pino@kde.org>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
macro(_gir_list_prefix _outvar _listvar _prefix)
set(${_outvar})
foreach(_item IN LISTS ${_listvar})
list(APPEND ${_outvar} ${_prefix}${_item})
endforeach()
endmacro(_gir_list_prefix)
macro(gir_add_introspections introspections_girs)
set(_gir_girs)
set(_gir_typelibs)
foreach(gir IN LISTS ${introspections_girs})
set(_gir_name "${gir}")
## Transform the gir filename to something which can reference through a variable
## without automake/make complaining, eg Gtk-2.0.gir -> Gtk_2_0_gir
string(REPLACE "-" "_" _gir_name "${_gir_name}")
string(REPLACE "." "_" _gir_name "${_gir_name}")
# Namespace and Version is either fetched from the gir filename
# or the _NAMESPACE/_VERSION variable combo
set(_gir_namespace "${${_gir_name}_NAMESPACE}")
if (_gir_namespace STREQUAL "")
string(REGEX REPLACE "([^-]+)-.*" "\\1" _gir_namespace "${gir}")
endif ()
set(_gir_version "${${_gir_name}_VERSION}")
if (_gir_version STREQUAL "")
string(REGEX REPLACE ".*-([^-]+).gir" "\\1" _gir_version "${gir}")
endif ()
# _PROGRAM is an optional variable which needs it's own --program argument
set(_gir_program "${${_gir_name}_PROGRAM}")
if (NOT _gir_program STREQUAL "")
set(_gir_program "--program=${_gir_program}")
endif ()
# Variables which provides a list of things
_gir_list_prefix(_gir_libraries ${_gir_name}_LIBS "--library=")
_gir_list_prefix(_gir_packages ${_gir_name}_PACKAGES "--pkg=")
_gir_list_prefix(_gir_includes ${_gir_name}_INCLUDES "--include=")
# Reuse the LIBTOOL variable from by automake if it's set
set(_gir_libtool "--no-libtool")
add_custom_command(
COMMAND ${INTROSPECTION_SCANNER}
${INTROSPECTION_SCANNER_ARGS}
--namespace=${_gir_namespace}
--nsversion=${_gir_version}
${_gir_libtool}
${_gir_program}
${_gir_libraries}
${_gir_packages}
${_gir_includes}
${${_gir_name}_SCANNERFLAGS}
${${_gir_name}_CFLAGS}
${${_gir_name}_FILES}
--output ${CMAKE_CURRENT_BINARY_DIR}/${gir}
DEPENDS ${${_gir_name}_FILES}
${${_gir_name}_LIBS}
OUTPUT ${gir}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
VERBATIM
)
list(APPEND _gir_girs ${CMAKE_CURRENT_BINARY_DIR}/${gir})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${gir} DESTINATION share/gir-1.0)
string(REPLACE ".gir" ".typelib" _typelib "${gir}")
add_custom_command(
COMMAND ${INTROSPECTION_COMPILER}
${INTROSPECTION_COMPILER_ARGS}
--includedir=.
${CMAKE_CURRENT_BINARY_DIR}/${gir}
-o ${CMAKE_CURRENT_BINARY_DIR}/${_typelib}
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${gir}
OUTPUT ${_typelib}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
list(APPEND _gir_typelibs ${CMAKE_CURRENT_BINARY_DIR}/${_typelib})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${_typelib} DESTINATION lib${LIB_SUFFIX}/girepository-1.0)
endforeach()
add_custom_target(gir-girs ALL DEPENDS ${_gir_girs})
add_custom_target(gir-typelibs ALL DEPENDS ${_gir_typelibs})
endmacro(gir_add_introspections)
......@@ -107,3 +107,39 @@ if (GDK_FOUND)
target_link_libraries(test-poppler-glib poppler-glib ${GDK2_LIBRARIES})
endif (GDK_FOUND)
macro(_list_prefix _outvar _listvar _prefix)
set(${_outvar})
foreach(_item IN LISTS ${_listvar})
list(APPEND ${_outvar} ${_prefix}${_item})
endforeach()
endmacro(_list_prefix)
# GObject Introspection
if (HAVE_INTROSPECTION)
include(GObjectIntrospectionMacros)
set(INTROSPECTION_GIRS)
set(INTROSPECTION_SCANNER_ARGS "--add-include-path=${CMAKE_CURRENT_SOURCE_DIR}")
set(INTROSPECTION_COMPILER_ARGS "--includedir=${CMAKE_CURRENT_SOURCE_DIR}")
set(introspection_files ${poppler_glib_SRCS} ${poppler_glib_public_headers} poppler-private.h)
set(Poppler_0_16_gir "poppler-glib")
set(Poppler_0_16_gir_INCLUDES GObject-2.0 cairo-1.0)
get_directory_property(_tmp_includes INCLUDE_DIRECTORIES)
_list_prefix(_includes _tmp_includes "-I")
set(Poppler_0_16_gir_CFLAGS ${_includes})
set(Poppler_0_16_gir_LIBS poppler-glib)
_list_prefix(_abs_introspection_files introspection_files "${CMAKE_CURRENT_SOURCE_DIR}/")
list(APPEND _abs_introspection_files
${CMAKE_CURRENT_BINARY_DIR}/poppler-enums.c
${CMAKE_CURRENT_BINARY_DIR}/poppler-enums.h
)
set(Poppler_0_16_gir_FILES ${_abs_introspection_files})
if (GDK_FOUND)
list(APPEND Poppler_0_16_gir_INCLUDES Gdk-2.0)
endif ()
list(APPEND INTROSPECTION_GIRS Poppler-0.16.gir)
gir_add_introspections(INTROSPECTION_GIRS)
endif ()
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