Changeset View
Changeset View
Standalone View
Standalone View
cmake/FindGObjectIntrospection.cmake
- This file was added.
1 | # FindGObjectIntrospection.cmake | ||||
---|---|---|---|---|---|
2 | # <https://github.com/nemequ/gnome-cmake> | ||||
3 | # | ||||
4 | # License: | ||||
5 | # | ||||
6 | # Copyright (c) 2016 Evan Nemerson <evan@nemerson.com> | ||||
7 | # | ||||
8 | # Permission is hereby granted, free of charge, to any person | ||||
9 | # obtaining a copy of this software and associated documentation | ||||
10 | # files (the "Software"), to deal in the Software without | ||||
11 | # restriction, including without limitation the rights to use, copy, | ||||
12 | # modify, merge, publish, distribute, sublicense, and/or sell copies | ||||
13 | # of the Software, and to permit persons to whom the Software is | ||||
14 | # furnished to do so, subject to the following conditions: | ||||
15 | # | ||||
16 | # The above copyright notice and this permission notice shall be | ||||
17 | # included in all copies or substantial portions of the Software. | ||||
18 | # | ||||
19 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||||
20 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||||
21 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||||
22 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||||
23 | # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||||
24 | # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||
25 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||||
26 | # DEALINGS IN THE SOFTWARE. | ||||
27 | | ||||
28 | find_program(GObjectIntrospection_COMPILER_EXECUTABLE g-ir-compiler) | ||||
29 | find_program(GObjectIntrospection_SCANNER_EXECUTABLE g-ir-scanner) | ||||
30 | | ||||
31 | if(CMAKE_INSTALL_FULL_DATADIR) | ||||
32 | set(GObjectIntrospection_REPOSITORY_DIR "${CMAKE_INSTALL_FULL_DATADIR}/gir-1.0") | ||||
33 | else() | ||||
34 | set(GObjectIntrospection_REPOSITORY_DIR "${CMAKE_INSTALL_PREFIX}/share/gir-1.0") | ||||
35 | endif() | ||||
36 | | ||||
37 | if(CMAKE_INSTALL_FULL_LIBDIR) | ||||
38 | set(GObjectIntrospection_TYPELIB_DIR "${CMAKE_INSTALL_FULL_LIBDIR}/girepository-1.0") | ||||
39 | else() | ||||
40 | set(GObjectIntrospection_TYPELIB_DIR "${CMAKE_INSTALL_LIBDIR}/girepository-1.0") | ||||
41 | endif() | ||||
42 | | ||||
43 | if(GObjectIntrospection_COMPILER_EXECUTABLE) | ||||
44 | # Imported target | ||||
45 | add_executable(g-ir-compiler IMPORTED) | ||||
46 | set_property(TARGET g-ir-compiler PROPERTY IMPORTED_LOCATION "${GObjectIntrospection_COMPILER_EXECUTABLE}") | ||||
47 | endif() | ||||
48 | | ||||
49 | if(GObjectIntrospection_SCANNER_EXECUTABLE) | ||||
50 | # Imported target | ||||
51 | add_executable(g-ir-scanner IMPORTED) | ||||
52 | set_property(TARGET g-ir-scanner PROPERTY IMPORTED_LOCATION "${GObjectIntrospection_SCANNER_EXECUTABLE}") | ||||
53 | endif() | ||||
54 | | ||||
55 | include(FindPackageHandleStandardArgs) | ||||
56 | find_package_handle_standard_args(GObjectIntrospection | ||||
57 | REQUIRED_VARS | ||||
58 | GObjectIntrospection_COMPILER_EXECUTABLE | ||||
59 | GObjectIntrospection_SCANNER_EXECUTABLE) | ||||
60 | | ||||
61 | function(gobject_introspection_compile TYPELIB) | ||||
62 | set (options DEBUG VERBOSE) | ||||
63 | set (oneValueArgs MODULE SHARED_LIBRARY) | ||||
64 | set (multiValueArgs FLAGS INCLUDE_DIRS) | ||||
65 | cmake_parse_arguments(GObjectIntrospection_COMPILER "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) | ||||
66 | unset (options) | ||||
67 | unset (oneValueArgs) | ||||
68 | unset (multiValueArgs) | ||||
69 | | ||||
70 | get_filename_component(TYPELIB "${TYPELIB}" ABSOLUTE | ||||
71 | BASE_DIR "${CMAKE_CURRENT_BINARY_DIR}") | ||||
72 | | ||||
73 | if(GObjectIntrospection_COMPILER_DEBUG) | ||||
74 | list(APPEND GObjectIntrospection_COMPILER_FLAGS "--debug") | ||||
75 | endif() | ||||
76 | | ||||
77 | if(GObjectIntrospection_COMPILER_VERBOSE) | ||||
78 | list(APPEND GObjectIntrospection_COMPILER_FLAGS "--verbose") | ||||
79 | endif() | ||||
80 | | ||||
81 | if(GObjectIntrospection_SHARED_LIBRARY) | ||||
82 | list(APPEND GObjectIntrospection_COMPILER_FLAGS "--shared-library" "${GObjectIntrospection_SHARED_LIBRARY}") | ||||
83 | endif() | ||||
84 | | ||||
85 | foreach(include_dir ${GObjectIntrospection_COMPILER_INCLUDE_DIRS}) | ||||
86 | list(APPEND GObjectIntrospection_COMPILER_FLAGS "--includedir" "${include_dir}") | ||||
87 | endforeach() | ||||
88 | | ||||
89 | add_custom_command( | ||||
90 | OUTPUT "${TYPELIB}" | ||||
91 | COMMAND g-ir-compiler | ||||
92 | ARGS | ||||
93 | "-o" "${TYPELIB}" | ||||
94 | ${GObjectIntrospection_COMPILER_FLAGS} | ||||
95 | ${GObjectIntrospection_COMPILER_UNPARSED_ARGUMENTS} | ||||
96 | DEPENDS | ||||
97 | ${GObjectIntrospection_COMPILER_UNPARSED_ARGUMENTS}) | ||||
98 | endfunction() |