From 813ad9093f7d7d7a37af255bbe676b9988502b60 Mon Sep 17 00:00:00 2001 From: Robert Tari Date: Fri, 15 Oct 2021 00:28:09 +0200 Subject: Add CMake files --- cmake/FindGObjectIntrospection.cmake | 61 ++++++++++++++++++++++++++++++++++++ cmake/FindVala.cmake | 57 +++++++++++++++++++++++++++++++++ cmake/GdbusCodegen.cmake | 36 +++++++++++++++++++++ 3 files changed, 154 insertions(+) create mode 100644 cmake/FindGObjectIntrospection.cmake create mode 100644 cmake/FindVala.cmake create mode 100644 cmake/GdbusCodegen.cmake (limited to 'cmake') diff --git a/cmake/FindGObjectIntrospection.cmake b/cmake/FindGObjectIntrospection.cmake new file mode 100644 index 0000000..2073c3c --- /dev/null +++ b/cmake/FindGObjectIntrospection.cmake @@ -0,0 +1,61 @@ +# - 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, +# +# 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 +) diff --git a/cmake/FindVala.cmake b/cmake/FindVala.cmake new file mode 100644 index 0000000..a638735 --- /dev/null +++ b/cmake/FindVala.cmake @@ -0,0 +1,57 @@ +# - Find Vala +# This module looks for valac. +# This module defines the following values: +# VALA_FOUND +# VALA_COMPILER +# VALA_VERSION +# VAPI_GEN +# VAPI_GEN_VERSION + +#============================================================================= +# Copyright Přemysl Janouch 2011 +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY +# OF SUCH DAMAGE. +#============================================================================= + +find_program (VALA_COMPILER "valac") + +if (VALA_COMPILER) + execute_process (COMMAND ${VALA_COMPILER} --version + OUTPUT_VARIABLE VALA_VERSION) + string (REGEX MATCH "[.0-9]+" VALA_VERSION "${VALA_VERSION}") +endif (VALA_COMPILER) + +find_program (VAPI_GEN "vapigen") + +if (VAPI_GEN) + execute_process (COMMAND ${VAPI_GEN} --version + OUTPUT_VARIABLE VAPI_GEN_VERSION) + string (REGEX MATCH "[.0-9]+" VAPI_GEN_VERSION "${VAPI_GEN_VERSION}") +endif (VAPI_GEN) + +include (FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS (Vala + REQUIRED_VARS VALA_COMPILER + VERSION_VAR VALA_VERSION) + +mark_as_advanced (VALA_COMPILER VALA_VERSION VAPI_GEN) + diff --git a/cmake/GdbusCodegen.cmake b/cmake/GdbusCodegen.cmake new file mode 100644 index 0000000..5261ba8 --- /dev/null +++ b/cmake/GdbusCodegen.cmake @@ -0,0 +1,36 @@ +cmake_minimum_required(VERSION 3.13) +if(POLICY CMP0011) + cmake_policy(SET CMP0011 NEW) +endif(POLICY CMP0011) + +find_program(GDBUS_CODEGEN NAMES gdbus-codegen DOC "gdbus-codegen executable") +if(NOT GDBUS_CODEGEN) + message(FATAL_ERROR "Excutable gdbus-codegen not found") +endif() + +macro(add_gdbus_codegen outfiles name prefix service_xml) + add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${name}.h" "${CMAKE_CURRENT_BINARY_DIR}/${name}.c" + COMMAND "${GDBUS_CODEGEN}" + --interface-prefix "${prefix}" + --generate-c-code "${name}" + "${service_xml}" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS ${ARGN} "${service_xml}" + ) + list(APPEND ${outfiles} "${CMAKE_CURRENT_BINARY_DIR}/${name}.c") +endmacro(add_gdbus_codegen) + +macro(add_gdbus_codegen_with_namespace outfiles name prefix namespace service_xml) + add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${name}.h" "${CMAKE_CURRENT_BINARY_DIR}/${name}.c" + COMMAND "${GDBUS_CODEGEN}" + --interface-prefix "${prefix}" + --generate-c-code "${name}" + --c-namespace "${namespace}" + "${service_xml}" + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS ${ARGN} "${service_xml}" + ) + list(APPEND ${outfiles} "${CMAKE_CURRENT_BINARY_DIR}/${name}.c") +endmacro(add_gdbus_codegen_with_namespace) -- cgit v1.2.3