Skip to content

Commit

Permalink
chore: add dtk dbus generate function
Browse files Browse the repository at this point in the history
Log: steal from qt
  • Loading branch information
Decodetalkers authored and kegechen committed Nov 17, 2023
1 parent f790bab commit 1dfa31c
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 1 deletion.
11 changes: 11 additions & 0 deletions LICENSES/BSD-3-Clause.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Copyright (c) <year> <owner>.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. 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.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

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 HOLDER OR CONTRIBUTORS 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.
74 changes: 74 additions & 0 deletions cmake/DtkTools/DtkDBusMacros.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Copyright 2005-2011 Kitware, Inc.
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause

include(MacroAddFileDependencies)
include(CMakeParseArguments)

function(dtk_add_dbus_interface _sources _interface _relativename)
get_filename_component(_infile ${_interface} ABSOLUTE)
get_filename_component(_basepath ${_relativename} DIRECTORY)
get_filename_component(_basename ${_relativename} NAME)
set(_header "${CMAKE_CURRENT_BINARY_DIR}/${_relativename}.h")
set(_impl "${CMAKE_CURRENT_BINARY_DIR}/${_relativename}.cpp")

if(${QT_VERSION_MAJOR} EQUAL "5")
if(_basepath)
set(_moc "${CMAKE_CURRENT_BINARY_DIR}/${_basepath}/${_basename}.moc")
else()
set(_moc "${CMAKE_CURRENT_BINARY_DIR}/${_basename}.moc")
endif()
else()
if(_basepath)
set(_moc "${CMAKE_CURRENT_BINARY_DIR}/${_basepath}/moc_${_basename}.cpp")
else()
set(_moc "${CMAKE_CURRENT_BINARY_DIR}/moc_${_basename}.cpp")
endif()
endif()

get_source_file_property(_nonamespace ${_interface} NO_NAMESPACE)
if(_nonamespace)
set(_params -N -m)
else()
set(_params -m)
endif()

get_source_file_property(_classname ${_interface} CLASSNAME)
if(_classname)
set(_params ${_params} -c ${_classname})
endif()

get_source_file_property(_include ${_interface} INCLUDE)
if(_include)
set(_params ${_params} -i ${_include})
endif()

add_custom_command(OUTPUT "${_impl}" "${_header}"
COMMAND ${DTK_XML2CPP} ${_params} -p ${_relativename} ${_infile}
DEPENDS ${_infile} ${DTK_XML2CPP}
VERBATIM
)

set_source_files_properties("${_impl}" "${_header}" PROPERTIES
SKIP_AUTOMOC TRUE
SKIP_AUTOUIC TRUE
)

qt_generate_moc("${_header}" "${_moc}")

list(APPEND ${_sources} "${_impl}" "${_header}")
set_property(SOURCE "${_impl}" APPEND PROPERTY OBJECT_DEPENDS "${_moc}")
set(${_sources} ${${_sources}} PARENT_SCOPE)
endfunction()

function(dtk_add_dbus_interfaces _sources)
foreach(_current_FILE ${ARGN})
get_filename_component(_infile ${_current_FILE} ABSOLUTE)
get_filename_component(_basename ${_current_FILE} NAME)
# get the part before the ".xml" suffix
string(TOLOWER ${_basename} _basename)
string(REGEX REPLACE "(.*\\.)?([^\\.]+)\\.xml" "\\2" _basename ${_basename})
dtk_add_dbus_interface(${_sources} ${_infile} ${_basename}interface)
endforeach()
set(${_sources} ${${_sources}} PARENT_SCOPE)
endfunction()
2 changes: 1 addition & 1 deletion cmake/DtkTools/DtkSettingsToolsMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function(DTK_CREATE_I18N_FROM_JSON _generated_file_list _input_json_file _output
get_filename_component(_input_json_abs_path ${_input_json_file} ABSOLUTE)
get_filename_component(_input_json_abs_dir ${_input_json_abs_path} DIRECTORY)
set (_output_cpp_abs_path ${_input_json_abs_dir}/${_output_cpp_file_name})

if (DTK_SETTINGS_TOOLS_FOUND)
add_custom_command(OUTPUT ${_output_cpp_abs_path}
COMMAND ${DTK_SETTINGS_TOOLS_EXECUTABLE}
Expand Down
1 change: 1 addition & 0 deletions cmake/DtkTools/DtkToolsConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ endif ()

include("${CMAKE_CURRENT_LIST_DIR}/Dtk@[email protected]")
include("${CMAKE_CURRENT_LIST_DIR}/Dtk@[email protected]")
include("${CMAKE_CURRENT_LIST_DIR}/DtkDBusMacros.cmake")

get_target_property(DTK_XML2CPP Dtk@DTK_VERSION_MAJOR@::Xml2Cpp LOCATION)
3 changes: 3 additions & 0 deletions dtkcore.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ install(FILES cmake/DtkTools/DtkSettingsToolsMacros.cmake
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Dtk${DTK_VERSION_MAJOR}Tools"
RENAME Dtk${DTK_VERSION_MAJOR}SettingsToolsMacros.cmake)

install(FILES cmake/DtkTools/DtkDBusMacros.cmake
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Dtk${DTK_VERSION_MAJOR}Tools")

if (NOT DTK_VERSION_MAJOR)
set(DCONFIG_DEPRECATED_FUNCS [=[
# deprecated since dtk6
Expand Down

0 comments on commit 1dfa31c

Please sign in to comment.