Commit 238d2dab authored by Mike Gabriel's avatar Mike Gabriel

Import Upstream version 1.3+17.04.20170310

parents
cmake_minimum_required(VERSION 3.0.2)
project(cmake-extras)
include(GNUInstallDirs)
# Modules using the newer find_package() "config" extension mechanism.
install(
DIRECTORY "src/"
DESTINATION "${CMAKE_INSTALL_DATADIR}/cmake/"
USE_SOURCE_PERMISSIONS
)
# Modules installed directly to CMAKE_ROOT
# TODO: migrate these to the above tree, since installing to
# CMAKE_ROOT is frowned upon.
install(
DIRECTORY "modules/"
DESTINATION "${CMAKE_ROOT}/Modules/"
USE_SOURCE_PERMISSIONS
)
#
# Copyright (C) 2015 Canonical Ltd.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
cmake_minimum_required(VERSION 3.0.2)
project(copyrighttest-demo LANGUAGES C CXX)
include(CTest)
enable_testing()
find_package(CopyrightTest REQUIRED)
add_copyright_test(
SOURCE_DIR ${CMAKE_SOURCE_DIR}
IGNORE_DIR ${CMAKE_BINARY_DIR}
TEST_NAME must_fail_1
)
#
# HACK: The licensecheck -c option is broken in zesty:
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=842368
# once this is fixed, we need to re-enable the tests
# that use INCLUDE_PATTERN.
#
#add_copyright_test(
# SOURCE_DIR ${CMAKE_SOURCE_DIR}
# IGNORE_DIR ${CMAKE_BINARY_DIR}
# INCLUDE_PATTERN \\.cpp$
# TEST_NAME must_fail_2
#)
#
#add_copyright_test(
# SOURCE_DIR ${CMAKE_SOURCE_DIR}
# IGNORE_DIR ${CMAKE_BINARY_DIR}
# INCLUDE_PATTERN \\.cpp$|\\.h$
# IGNORE_PATTERN no_copyright\\.h$
# TEST_NAME must_fail_3
#)
add_copyright_test(
SOURCE_DIR ${CMAKE_SOURCE_DIR}
IGNORE_PATTERN \\.h$
TEST_NAME must_fail_4
)
add_copyright_test(
SOURCE_DIR ${CMAKE_SOURCE_DIR}
IGNORE_DIR ${CMAKE_BINARY_DIR}
IGNORE_PATTERN no_copyright
TEST_NAME must_succeed_1
)
#add_copyright_test(
# SOURCE_DIR ${CMAKE_SOURCE_DIR}
# IGNORE_DIR ${CMAKE_BINARY_DIR}
# INCLUDE_PATTERN \\.cpp$
# IGNORE_PATTERN no_copyright\\.cpp$
# TEST_NAME must_succeed_2
#)
add_copyright_test(
SOURCE_DIR ${CMAKE_SOURCE_DIR}
IGNORE_DIR ${CMAKE_BINARY_DIR}
INCLUDE_PATTERN \\.cpp$|\\.h$
IGNORE_PATTERN no_copyright\\.h$|no_copyright\\.cpp$
TEST_NAME must_succeed_3
)
/*
* Copyright (C) 2015 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Copyright (C) 2015 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
cmake_minimum_required(VERSION 3.1)
project(doxygenbuilder-demo LANGUAGES C CXX)
include(GNUInstallDirs)
add_subdirectory(doc)
find_package(DoxygenBuilder)
add_doxygen(
doc
PROJECT_NAME
"doxygenbuilder-demo"
INPUT
"${CMAKE_SOURCE_DIR}/src/"
"${CMAKE_CURRENT_SOURCE_DIR}/pages"
EXAMPLE_PATH
"${CMAKE_SOURCE_DIR}/examples/"
STRIP_FROM_PATH
"${CMAKE_SOURCE_DIR}/src/"
STRIP_FROM_INC_PATH
"${CMAKE_SOURCE_DIR}/src/"
EXCLUDE_PATTERNS
*/internal/*
EXCLUDE_SYMBOLS
*::internal*
*::Priv
INSTALL
"${CMAKE_INSTALL_DATAROOTDIR}/doc/doxygenbuilder-demo"
XML
ALL
)
/*!
\mainpage DoxygenBuilder Demo
\tableofcontents
\section sec_introduction Introduction
This is the introduction.
\include example-1.cpp
*/
#include <my-namespace/my-class.h>
using namespace MyNamespace;
int main(int argc, char** argv) {
//! [Creating the class.]
MyClass foo;
//! [Creating the class.]
//! [Calling my method.]
foo.myMethod("hello");
//! [Calling my method.]
//! [Calling my other method.]
return foo.myOtherMethod();
//! [Calling my other method.]
}
#include <string>
#pragma once
/**
* @brief My namespace
*
* My namespace description.
*/
namespace MyNamespace {
/**
* @brief My class brief.
*
* My class description.
*/
class MyClass {
public:
MyClass();
~MyClass() = default;
/**
* @brief My method brief.
* @param arg a string argument.
*
* My method description. Here is an example of calling my method:
* * @snippet example-1.cpp Calling my method.
*/
void myMethod(const std::string& arg) const;
/**
* @brief My other method brief.
*
* My other method description. Here is an example of calling my
* other method:
* @snippet example-1.cpp Calling my other method.
*/
int myOtherMethod();
};
}
cmake_minimum_required(VERSION 3.0.2)
project(findgmock-demo LANGUAGES C CXX)
# find_package(GMock) will find the Google Mock source, and add it to
# this project's build. It will create the targets gtest, gtest_main,
# gmock, and gmock_main.
find_package(GMock)
add_executable(test-suite test-suite.cpp)
target_link_libraries(test-suite gtest_main)
#include <gtest/gtest.h>
TEST(Suite, Success)
{
EXPECT_EQ(42, 42);
}
TEST(Suite, Failure)
{
FAIL();
}
cmake_minimum_required(VERSION 3.1)
project(gdbus-demo)
set (CMAKE_CXX_STANDARD 14)
if(CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic")
endif()
enable_testing()
include(GNUInstallDirs)
find_package(GDbus)
find_package(PkgConfig REQUIRED)
pkg_check_modules(
GLIB REQUIRED
gio-unix-2.0
glib-2.0
)
include_directories(${GLIB_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
set(SOURCES
main.cpp
)
add_gdbus_codegen(
SOURCES
dbus-standard
org.freedesktop
org.freedesktop.DBus.xml
)
add_gdbus_codegen(
SOURCES
dbus-namespaced
org.freedesktop
org.freedesktop.DBus.xml
NAMESPACE "DBus"
)
add_executable(
test-gdbus
${SOURCES}
)
target_link_libraries(
test-gdbus
${GLIB_LDFLAGS}
)
add_test(test-gdbus test-gdbus)
#include "dbus-standard.h"
#include "dbus-namespaced.h"
#include <memory>
#include <gio/gio.h>
#include <glib.h>
using namespace std;
namespace {
static void test_standard()
{
GError* error{nullptr};
shared_ptr<DBus> proxy(dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
G_DBUS_PROXY_FLAGS_NONE,
"org.freedesktop.DBus",
"/",
nullptr,
&error),
&g_object_unref);
g_assert_null(error);
g_assert_nonnull(proxy.get());
gchar* result_id{nullptr};
dbus_call_get_id_sync(proxy.get(), &result_id, nullptr, &error);
g_assert_null(error);
g_assert_nonnull(result_id);
g_free(result_id);
}
static void test_namespaced()
{
GError* error{nullptr};
shared_ptr<DBusDBus> proxy(dbus_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
G_DBUS_PROXY_FLAGS_NONE,
"org.freedesktop.DBus",
"/",
nullptr,
&error),
&g_object_unref);
g_assert_null(error);
g_assert_nonnull(proxy.get());
gchar* result_id{nullptr};
dbus_dbus_call_get_id_sync(proxy.get(), &result_id, nullptr, &error);
g_assert_null(error);
g_assert_nonnull(result_id);
g_free(result_id);
}
}
int main(int argc, char** argv) {
g_test_init(&argc, &argv, nullptr);
g_test_add_func("/gdbus-demo/generated", test_standard);
g_test_add_func("/gdbus-demo/namespaced", test_namespaced);
return g_test_run();
}
<!DOCTYPE node PUBLIC
"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd" >
<node name="/" xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd">
<interface name="org.freedesktop.DBus">
<method name="GetId">
<arg name="id" direction="out" type="s">
</arg>
</method>
<method name="ListNames">
<arg name="names" direction="out" type="as">
</arg>
</method>
</interface>
</node>
cmake_minimum_required(VERSION 3.1)
project(intltool-demo)
enable_testing()
include(GNUInstallDirs)
find_package(GSettings)
set (DEFAULT_UUID_VALUE "" CACHE STRING "Default UUID to use in schema.")
set (DEFAULT_UUID "'${DEFAULT_UUID_VALUE}'")
add_schema ("static.gschema.xml")
configure_file ("generated.gschema.xml.in" "generated.gschema.xml")
add_schema ("generated.gschema.xml")
compile_schemas(${CMAKE_CURRENT_BINARY_DIR})
<schemalist>
<schema id="com.canonical.cmake-extras.generated-test" path="/com/canonical/cmake-extras/generated-test/">
<key name="install-id" type="s">
<default>@DEFAULT_UUID@</default>
<summary>Just a test</summary>
<description>No really, it's just a test.</description>
</key>
</schema>
</schemalist>
<schemalist>
<schema id="com.canonical.cmake-extras.static-test" path="/com/canonical/cmake-extras/static-test/">
<key name="use-gsettings" type="b">
<default>false</default>
<summary>Just a test</summary>
<description>No really, it's just a test.</description>
</key>
</schema>
</schemalist>
cmake_minimum_required(VERSION 3.1)
project(includechecker-demo LANGUAGES C CXX)
include(GNUInstallDirs)
find_package(PkgConfig REQUIRED)
pkg_check_modules(
GLIB REQUIRED
glib-2.0
gobject-2.0
)
include_directories(${GLIB_INCLUDE_DIRS})
set (CMAKE_CXX_STANDARD 14)
if(CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic")
endif()
enable_testing()
add_subdirectory(test)
#pragma once
#include <memory>
#include <glib-object.h>
namespace demolib {
namespace bad {
inline std::unique_ptr<GObject, decltype(&g_object_unref)> make_gobject() {
return std::unique_ptr<GObject, decltype(&g_object_unref)>(G_OBJECT(g_object_new(G_TYPE_OBJECT, nullptr)), &g_object_unref);
}
}
}
#pragma once
#include <string>
#include <memory>
namespace demolib {
inline std::unique_ptr<std::string> new_unique_string() {
return std::make_unique<std::string>("hi");
}
}
#pragma once
#include <glib.h>
#include <glib-object.h>
find_package(IncludeChecker REQUIRED)
include_directories("${CMAKE_SOURCE_DIR}/include")
function(add_demolib_test NAME PREFIX)
add_executable(
"${NAME}"
"${PREFIX}${NAME}.cpp"
)
target_link_libraries(
"${NAME}"
${GLIB_LDFLAGS}
)
add_test(
"${NAME}"
"${NAME}"
)
endfunction()
add_demolib_test("good-header-test" "")
add_demolib_test("bad-header-test" "bad/")
set(INCLUDE_CHECK_FORBIDDEN "glib.h" CACHE STRING "")
set(INCLUDE_CHECK_ALLOWED "bad/bad-header.h:glib.h" CACHE STRING "")
set(INCLUDE_CHECK_IGNORE "internal" CACHE STRING "")
add_include_check(
demolib-include-check
DIRECTORIES
"${CMAKE_SOURCE_DIR}/include"
FORBIDDEN
${INCLUDE_CHECK_FORBIDDEN}
ALLOWED
${INCLUDE_CHECK_ALLOWED}
IGNORE
${INCLUDE_CHECK_IGNORE}
FILE_EXTENSIONS
".h"
".hxx"
COMPILER_OPTIONS
"-std=gnu++14"
)
#include <demolib/bad/bad-header.h>
using namespace std;
namespace {
static void test_make_gobject() {
auto o = demolib::bad::make_gobject();
}
}
int main(int argc, char** argv) {
g_test_init (&argc, &argv, NULL);
g_test_add_func("/includechecker-demo/bad-header/test_make_gobject", test_make_gobject);
return g_test_run();
}
#include <demolib/good-header.h>
#include <glib.h>
using namespace std;
namespace {
static void test_new_unique_string() {
auto s = demolib::new_unique_string();
g_assert_cmpstr(s->c_str(), ==, "hi");
}
}
int main(int argc, char** argv) {
g_test_init (&argc, &argv, NULL);
g_test_add_func("/includechecker-demo/good-header/test_new_unique_string", test_new_unique_string);
return g_test_run();
}
cmake_minimum_required(VERSION 3.1)
project(intltool-demo LANGUAGES C CXX)
include(GNUInstallDirs)
find_package(PkgConfig REQUIRED)
find_package(Intltool REQUIRED)
pkg_check_modules(
GLIB REQUIRED
glib-2.0
gio-2.0
)
include_directories(${GLIB_INCLUDE_DIRS})
set(GETTEXT_PACKAGE "intltool-demo")
set(LOCALE_DIR "${CMAKE_INSTALL_FULL_DATADIR}/locale")
set (CMAKE_CXX_STANDARD 14)
if(CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic")
endif()
add_subdirectory(po)
add_subdirectory(src)
intltool_update_potfile(
ALL
KEYWORDS "_" "_:1,2" "N_" "N_:1,2"
POTFILES_TEMPLATE "POTFILES.in.in"
GETTEXT_PACKAGE ${GETTEXT_PACKAGE}
COPYRIGHT_HOLDER "Foocorp Ltd."
FILE_GLOBS "${CMAKE_SOURCE_DIR}/*.gschema.xml.in"
FILTER ".*test.*"
)
intltool_install_translations(
ALL
GETTEXT_PACKAGE ${GETTEXT_PACKAGE}
)
[type: gettext/ini] src/foo.ini.in
@GENERATED_POTFILES@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR Foocorp Ltd.
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-01-04 14:51+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: ../src/foo.ini.in.h:1
msgid "FooApp"
msgstr "FooApp translated"
#: ../src/foo.ini.in.h:2
msgid "FooApp is really great"
msgstr "FooApp is really great translated"
#. Plain gettext translation from extracted string in this .cpp file
#: ../src/main.cpp:49
msgid "Hello FooApp!"
msgstr "Hello translated FooApp!"
#. The schemas file entries
#: ../translated.gschema.xml.in.h:1
msgid "Just a test"
msgstr "Translated test mate"
#: ../translated.gschema.xml.in.h:2
msgid "No really, it's just a test."
msgstr "G'day mate, it's a test!"
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR Foocorp Ltd.
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-01-09 10:27+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
find_package(GSettings REQUIRED)
# INI file with translations embedded
intltool_merge_translations(
"foo.ini.in"
"foo.ini"
ALL
UTF8
)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/foo.ini"
DESTINATION ${CMAKE_INSTALL_DATADIR}/fooapp
)