~ted/indicator-network/add-title

« back to all changes in this revision

Viewing changes to cmake/UseGObjectIntrospection.cmake

  • Committer: Tarmac
  • Author(s): Pete Woods
  • Date: 2013-08-27 14:43:59 UTC
  • mfrom: (273.1.5 cmake)
  • Revision ID: tarmac-20130827144359-n3jdv10adh2x5gms
Re-write build scripts in preparation for merging the secret agent codebase and tests.

Approved by Charles Kerr, PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2010, Pino Toscano, <pino@kde.org>
 
2
#
 
3
# Redistribution and use is allowed according to the terms of the BSD license.
 
4
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
 
5
 
 
6
include(ListOperations)
 
7
 
 
8
macro(_gir_list_prefix _outvar _listvar _prefix)
 
9
  set(${_outvar})
 
10
  foreach(_item IN LISTS ${_listvar})
 
11
    list(APPEND ${_outvar} ${_prefix}${_item})
 
12
  endforeach()
 
13
endmacro(_gir_list_prefix)
 
14
 
 
15
macro(gir_add_introspections introspections_girs)
 
16
 
 
17
  foreach(gir IN LISTS ${introspections_girs})
 
18
 
 
19
    set(_gir_name "${gir}")
 
20
 
 
21
    ## Transform the gir filename to something which can reference through a variable
 
22
    ## without automake/make complaining, eg Gtk-2.0.gir -> Gtk_2_0_gir
 
23
    string(REPLACE "-" "_" _gir_name "${_gir_name}")
 
24
    string(REPLACE "." "_" _gir_name "${_gir_name}")
 
25
 
 
26
    # Namespace and Version is either fetched from the gir filename
 
27
    # or the _NAMESPACE/_VERSION variable combo
 
28
    set(_gir_namespace "${${_gir_name}_NAMESPACE}")
 
29
    if (_gir_namespace STREQUAL "")
 
30
      string(REGEX REPLACE "([^-]+)-.*" "\\1" _gir_namespace "${gir}")
 
31
    endif ()
 
32
    set(_gir_version "${${_gir_name}_VERSION}")
 
33
    if (_gir_version STREQUAL "")
 
34
      string(REGEX REPLACE ".*-([^-]+).gir" "\\1" _gir_version "${gir}")
 
35
    endif ()
 
36
 
 
37
    # _PROGRAM is an optional variable which needs it's own --program argument
 
38
    set(_gir_program "${${_gir_name}_PROGRAM}")
 
39
    if (NOT _gir_program STREQUAL "")
 
40
      set(_gir_program "--program=${_gir_program}")
 
41
    endif ()
 
42
 
 
43
    # Variables which provides a list of things
 
44
    _gir_list_prefix(_gir_libraries ${_gir_name}_LIBS "--library=")
 
45
    _gir_list_prefix(_gir_packages ${_gir_name}_PACKAGES "--pkg=")
 
46
    _gir_list_prefix(_gir_includes ${_gir_name}_INCLUDES "--include=")
 
47
    _gir_list_prefix(_gir_export_packages ${_gir_name}_EXPORT_PACKAGES "--pkg-export=")
 
48
 
 
49
    # Reuse the LIBTOOL variable from by automake if it's set
 
50
    set(_gir_libtool "--no-libtool")
 
51
 
 
52
    add_custom_command(
 
53
      COMMAND ${INTROSPECTION_SCANNER}
 
54
              ${INTROSPECTION_SCANNER_ARGS}
 
55
              --namespace=${_gir_namespace}
 
56
              --nsversion=${_gir_version}
 
57
              ${_gir_libtool}
 
58
              ${_gir_program}
 
59
              ${_gir_libraries}
 
60
              ${_gir_packages}
 
61
              ${_gir_includes}
 
62
              ${_gir_export_packages}
 
63
              ${${_gir_name}_SCANNERFLAGS}
 
64
              ${${_gir_name}_CFLAGS}
 
65
              ${${_gir_name}_FILES}
 
66
              --output ${CMAKE_CURRENT_BINARY_DIR}/${gir}
 
67
      DEPENDS ${${_gir_name}_FILES}
 
68
              ${${_gir_name}_LIBS}
 
69
      OUTPUT ${gir}
 
70
      WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
 
71
      VERBATIM
 
72
    )
 
73
    install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${gir} DESTINATION share/gir-1.0)
 
74
 
 
75
    string(REPLACE ".gir" ".typelib" _typelib "${gir}")
 
76
    add_custom_command(
 
77
      COMMAND ${INTROSPECTION_COMPILER}
 
78
              ${INTROSPECTION_COMPILER_ARGS}
 
79
              --includedir=.
 
80
              ${CMAKE_CURRENT_BINARY_DIR}/${gir}
 
81
              -o ${CMAKE_CURRENT_BINARY_DIR}/${_typelib}
 
82
      DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${gir}
 
83
      OUTPUT ${_typelib}
 
84
      WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
 
85
    )
 
86
    install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${_typelib} DESTINATION ${CMAKE_INSTALL_LIBDIR}/girepository-1.0)
 
87
 
 
88
    add_custom_target(gir-${gir} ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${gir})
 
89
    add_custom_target(gir-typelibs-${_typelib} ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${_typelib})
 
90
  endforeach()
 
91
 
 
92
endmacro(gir_add_introspections)
 
93
 
 
94
macro(gir_get_cflags _output)
 
95
  get_directory_property(_tmp_includes INCLUDE_DIRECTORIES)
 
96
  list_prefix(_includes _tmp_includes "-I")
 
97
  get_directory_property(_tmp_compile_definitions COMPILE_DEFINITIONS)
 
98
  list_prefix(_compile_definitions _tmp_compile_definitions "-D")
 
99
  set(${_output} ${_includes} ${_compile_definitions})
 
100
endmacro(gir_get_cflags)