Merge lp:~dobey/cmake-extras/add-gdbus into lp:cmake-extras

Proposed by dobey on 2017-02-24
Status: Merged
Approved by: dobey on 2017-02-28
Approved revision: 67
Merged at revision: 68
Proposed branch: lp:~dobey/cmake-extras/add-gdbus
Merge into: lp:cmake-extras
Diff against target: 286 lines (+252/-0)
6 files modified
debian/tests/control (+10/-0)
debian/tests/gdbus (+25/-0)
examples/gdbus-demo/CMakeLists.txt (+50/-0)
examples/gdbus-demo/main.cpp (+62/-0)
examples/gdbus-demo/org.freedesktop.DBus.xml (+18/-0)
src/GDbus/GDbusConfig.cmake (+87/-0)
To merge this branch: bzr merge lp:~dobey/cmake-extras/add-gdbus
Reviewer Review Type Date Requested Status
Pete Woods Approve on 2017-02-28
Charles Kerr (community) 2017-02-24 Approve on 2017-02-28
Review via email: mp+318280@code.launchpad.net

Commit message

Add a module for using gdbus-codegen code with cmake.

To post a comment you must log in.
Charles Kerr (charlesk) wrote :

LGTM. Even past the standardization into cmake-extras, the implementation has some nice cleanups compared to the roll-your-own versions in the indicators.

Optional comments inline, plus a needinfo about CMAKE_CXX_STANDARD

review: Needs Information
dobey (dobey) :
Charles Kerr (charlesk) :
review: Approve
Pete Woods (pete-woods) wrote :

Some trivial fixes inline.

review: Needs Fixing
Pete Woods (pete-woods) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/tests/control'
2--- debian/tests/control 2017-02-10 23:01:22 +0000
3+++ debian/tests/control 2017-02-28 17:40:01 +0000
4@@ -55,3 +55,13 @@
5 libglib2.0-dev,
6 pkg-config,
7 uuid-runtime,
8+
9+Tests: gdbus
10+Restrictions: allow-stderr
11+Depends:
12+ build-essential,
13+ cmake,
14+ cmake-extras,
15+ dbus,
16+ libglib2.0-dev,
17+ pkg-config,
18
19=== added file 'debian/tests/gdbus'
20--- debian/tests/gdbus 1970-01-01 00:00:00 +0000
21+++ debian/tests/gdbus 2017-02-28 17:40:01 +0000
22@@ -0,0 +1,25 @@
23+#!/bin/bash
24+
25+# autopkgtest check: Build a trivial project that uses the
26+# find_package(GDbus) macro.
27+# (C) 2017 Canonical Ltd.
28+
29+set -euo pipefail
30+IFS=$'\n\t'
31+
32+tempdir=$(mktemp --tmpdir="${AUTOPKGTEST_TMP:-/tmp}" -d)
33+trap "rm -rf $tempdir" 0 INT QUIT ABRT PIPE TERM
34+
35+srcdir="$(pwd)/examples/gdbus-demo"
36+bindir="${tempdir}/build"
37+installdir="${tempdir}/install"
38+
39+mkdir -p "${bindir}"
40+
41+# Move into bindir temporarily
42+(
43+ cd "${bindir}"
44+ cmake "${srcdir}" -DCMAKE_INSTALL_PREFIX="${installdir}"
45+ make
46+ make ARGS+="--output-on-failure" test
47+)
48
49=== added directory 'examples/gdbus-demo'
50=== added file 'examples/gdbus-demo/CMakeLists.txt'
51--- examples/gdbus-demo/CMakeLists.txt 1970-01-01 00:00:00 +0000
52+++ examples/gdbus-demo/CMakeLists.txt 2017-02-28 17:40:01 +0000
53@@ -0,0 +1,50 @@
54+cmake_minimum_required(VERSION 3.1)
55+project(gdbus-demo)
56+
57+set (CMAKE_CXX_STANDARD 14)
58+if(CMAKE_COMPILER_IS_GNUCC)
59+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic")
60+endif()
61+enable_testing()
62+
63+include(GNUInstallDirs)
64+find_package(GDbus)
65+find_package(PkgConfig REQUIRED)
66+
67+pkg_check_modules(
68+ GLIB REQUIRED
69+ gio-unix-2.0
70+ glib-2.0
71+)
72+include_directories(${GLIB_INCLUDE_DIRS})
73+include_directories(${CMAKE_CURRENT_BINARY_DIR})
74+
75+add_gdbus_codegen(
76+ DBUS_STANDARD
77+ dbus-standard
78+ org.freedesktop
79+ org.freedesktop.DBus.xml
80+ )
81+
82+add_gdbus_codegen(
83+ DBUS_NAMESPACED
84+ dbus-namespaced
85+ org.freedesktop
86+ org.freedesktop.DBus.xml
87+ NAMESPACE "DBus"
88+ )
89+
90+add_executable(
91+ test-gdbus
92+
93+ main.cpp
94+ ${DBUS_STANDARD_SOURCES}
95+ ${DBUS_NAMESPACED_SOURCES}
96+ )
97+target_link_libraries(
98+ test-gdbus
99+
100+ ${GLIB_LDFLAGS}
101+ )
102+
103+add_test(test-gdbus test-gdbus)
104
105=== added file 'examples/gdbus-demo/main.cpp'
106--- examples/gdbus-demo/main.cpp 1970-01-01 00:00:00 +0000
107+++ examples/gdbus-demo/main.cpp 2017-02-28 17:40:01 +0000
108@@ -0,0 +1,62 @@
109+#include "dbus-standard.h"
110+#include "dbus-namespaced.h"
111+
112+#include <memory>
113+#include <gio/gio.h>
114+#include <glib.h>
115+
116+using namespace std;
117+
118+namespace {
119+
120+static void test_standard()
121+{
122+ GError* error{nullptr};
123+ shared_ptr<DBus> proxy(dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
124+ G_DBUS_PROXY_FLAGS_NONE,
125+ "org.freedesktop.DBus",
126+ "/",
127+ nullptr,
128+ &error),
129+ &g_object_unref);
130+ g_assert_null(error);
131+ g_assert_nonnull(proxy.get());
132+
133+ gchar* result_id{nullptr};
134+ dbus_call_get_id_sync(proxy.get(), &result_id, nullptr, &error);
135+ g_assert_null(error);
136+
137+ g_assert_nonnull(result_id);
138+ g_free(result_id);
139+}
140+
141+static void test_namespaced()
142+{
143+ GError* error{nullptr};
144+ shared_ptr<DBusDBus> proxy(dbus_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
145+ G_DBUS_PROXY_FLAGS_NONE,
146+ "org.freedesktop.DBus",
147+ "/",
148+ nullptr,
149+ &error),
150+ &g_object_unref);
151+ g_assert_null(error);
152+ g_assert_nonnull(proxy.get());
153+
154+ gchar* result_id{nullptr};
155+ dbus_dbus_call_get_id_sync(proxy.get(), &result_id, nullptr, &error);
156+ g_assert_null(error);
157+
158+ g_assert_nonnull(result_id);
159+ g_free(result_id);
160+}
161+
162+}
163+
164+int main(int argc, char** argv) {
165+ g_test_init(&argc, &argv, nullptr);
166+ g_test_add_func("/gdbus-demo/generated", test_standard);
167+ g_test_add_func("/gdbus-demo/namespaced", test_namespaced);
168+
169+ return g_test_run();
170+}
171
172=== added file 'examples/gdbus-demo/org.freedesktop.DBus.xml'
173--- examples/gdbus-demo/org.freedesktop.DBus.xml 1970-01-01 00:00:00 +0000
174+++ examples/gdbus-demo/org.freedesktop.DBus.xml 2017-02-28 17:40:01 +0000
175@@ -0,0 +1,18 @@
176+<!DOCTYPE node PUBLIC
177+"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
178+"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd" >
179+<node name="/" xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd">
180+ <interface name="org.freedesktop.DBus">
181+
182+ <method name="GetId">
183+ <arg name="id" direction="out" type="s">
184+ </arg>
185+ </method>
186+
187+ <method name="ListNames">
188+ <arg name="names" direction="out" type="as">
189+ </arg>
190+ </method>
191+
192+ </interface>
193+</node>
194
195=== added directory 'src/GDbus'
196=== added file 'src/GDbus/GDbusConfig.cmake'
197--- src/GDbus/GDbusConfig.cmake 1970-01-01 00:00:00 +0000
198+++ src/GDbus/GDbusConfig.cmake 2017-02-28 17:40:01 +0000
199@@ -0,0 +1,87 @@
200+# Copyright (C) 2017 Canonical Ltd
201+#
202+# This program is free software: you can redistribute it and/or modify
203+# it under the terms of the GNU Lesser General Public License version 3 as
204+# published by the Free Software Foundation.
205+#
206+# This program is distributed in the hope that it will be useful,
207+# but WITHOUT ANY WARRANTY; without even the implied warranty of
208+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
209+# GNU Lesser General Public License for more details.
210+#
211+# You should have received a copy of the GNU Lesser General Public License
212+# along with this program. If not, see <http://www.gnu.org/licenses/>.
213+
214+#.rst:
215+# GDbus
216+# -----
217+#
218+# A `gdbus-codegen` module for CMake.
219+#
220+# Finds ths ``gdbus-codegen`` executable and adds the
221+# :command:`add_gdbus_codegen` command.
222+#
223+# In order to find the ``gdbus-codegen`` executable, it uses the
224+# :variable:`GDBUS_CODEGEN_EXECUTABLE` variable.
225+
226+### Find the executable
227+find_program(GDBUS_CODEGEN_EXECUTABLE gdbus-codegen)
228+
229+### Handle standard args
230+include(FindPackageHandleStandardArgs)
231+
232+find_package_handle_standard_args(
233+ GDbus
234+ REQUIRED_VARS
235+ GDBUS_CODEGEN_EXECUTABLE
236+ HANDLE_COMPONENTS
237+)
238+
239+#.rst:
240+#.. command:: add_gdbus_codegen
241+#
242+# Generates C code and header file from XML service description, and
243+# sets the :variable:<VARIABLE_PREFIX>_SOURCES variable with the newly
244+# generated source files. This variable should be added to the list of
245+# sources for your :command:add_executable or :command:add_library target.
246+#
247+# add_gdbus_codegen(<VARIABLE_PREFIX> <NAME> <PREFIX> <SERVICE_XML> [NAMESPACE])
248+#
249+# For example:
250+#
251+# .. code-block:: cmake
252+#
253+# add_gdbus_codegen(DBUS_PROXY
254+# dbus-proxy
255+# org.freedesktop
256+# org.freedesktop.DBus.xml
257+# )
258+#
259+function(ADD_GDBUS_CODEGEN VARIABLE_PREFIX NAME PREFIX SERVICE_XML)
260+ set(_options ALL)
261+ set(_oneValueArgs NAMESPACE)
262+
263+ cmake_parse_arguments(_ARG "${_options}" "${_oneValueArgs}" "" ${ARGN})
264+
265+ get_filename_component(_ABS_SERVICE_XML ${SERVICE_XML} ABSOLUTE)
266+
267+ set(_NAMESPACE "")
268+ if(_ARG_NAMESPACE)
269+ set(_NAMESPACE "--c-namespace=${_ARG_NAMESPACE}")
270+ endif()
271+
272+ set(_OUTPUT_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/${NAME}")
273+ set(_OUTPUT_FILES "${_OUTPUT_PREFIX}.c" "${_OUTPUT_PREFIX}.h")
274+ set("${VARIABLE_PREFIX}_SOURCES" "${_OUTPUT_FILES}" PARENT_SCOPE)
275+ add_custom_command(
276+ OUTPUT ${_OUTPUT_FILES}
277+ COMMAND "${GDBUS_CODEGEN_EXECUTABLE}"
278+ --interface-prefix ${PREFIX}
279+ --generate-c-code="${NAME}"
280+ ${_NAMESPACE}
281+ ${_ABS_SERVICE_XML}
282+ BYPRODUCTS ${_OUTPUT_FILES}
283+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
284+ DEPENDS ${_ABS_SERVICE_XML}
285+ )
286+endfunction()

Subscribers

People subscribed via source and target branches

to all changes: