Warning, /frameworks/kconfig/KF6ConfigMacros.cmake is written in an unsupported language. File is not indexed.
0001 # KCONFIG_ADD_KCFG_FILES (SRCS_VAR [GENERATE_MOC] [USE_RELATIVE_PATH] file1.kcfgc ... fileN.kcfgc) 0002 # KCONFIG_ADD_KCFG_FILES (<target> [GENERATE_MOC] [USE_RELATIVE_PATH] file1.kcfgc ... fileN.kcfgc) (since 5.67) 0003 # Use this to add KDE config compiler files to your application/library. 0004 # Use optional GENERATE_MOC to generate moc if you use signals in your kcfg files. 0005 # Use optional USE_RELATIVE_PATH to generate the classes in the build following the given 0006 # relative path to the file. 0007 # <target> must not be an alias. 0008 # 0009 # SPDX-FileCopyrightText: 2006-2009 Alexander Neundorf <neundorf@kde.org> 0010 # SPDX-FileCopyrightText: 2006, 2007, Laurent Montel <montel@kde.org> 0011 # SPDX-FileCopyrightText: 2007 Matthias Kretz <kretz@kde.org> 0012 # 0013 # SPDX-License-Identifier: BSD-3-Clause 0014 0015 include(CMakeParseArguments) 0016 0017 function(KCONFIG_ADD_KCFG_FILES _target_or_source_var) 0018 set(options GENERATE_MOC USE_RELATIVE_PATH) 0019 cmake_parse_arguments(ARG "${options}" "" "" ${ARGN}) 0020 0021 if(TARGET ${_target_or_source_var}) 0022 get_target_property(aliased_target ${_target_or_source_var} ALIASED_TARGET) 0023 if(aliased_target) 0024 message(FATAL_ERROR "Target argument passed to kconfig_add_kcfg_files must not be an alias: ${_target_or_source_var}") 0025 endif() 0026 endif() 0027 0028 set(sources) 0029 foreach(_current_FILE ${ARG_UNPARSED_ARGUMENTS}) 0030 get_filename_component(_tmp_FILE ${_current_FILE} ABSOLUTE) 0031 get_filename_component(_abs_PATH ${_tmp_FILE} PATH) 0032 0033 if(ARG_USE_RELATIVE_PATH) # Process relative path only if the option was set 0034 # Get relative path 0035 get_filename_component(_rel_PATH ${_current_FILE} PATH) 0036 0037 if(IS_ABSOLUTE ${_rel_PATH}) 0038 # We got an absolute path 0039 set(_rel_PATH "") 0040 endif() 0041 endif() 0042 0043 get_filename_component(_basename ${_tmp_FILE} NAME_WE) 0044 # If we had a relative path and we're asked to use it, then change the basename accordingly 0045 if(_rel_PATH) 0046 set(_basename ${_rel_PATH}/${_basename}) 0047 endif() 0048 0049 # if the file name in the kcfgc is changed, we need to rerun cmake 0050 set_property(DIRECTORY APPEND 0051 PROPERTY CMAKE_CONFIGURE_DEPENDS ${_tmp_FILE} 0052 ) 0053 0054 file(READ ${_tmp_FILE} _contents) 0055 string(REGEX MATCH "File=([^\n]+\\.kcfg)\n" "" "${_contents}") 0056 set(_kcfg_FILENAME "${CMAKE_MATCH_1}") 0057 if(NOT _kcfg_FILENAME) 0058 string(REGEX MATCH "File=([^\n]+\\.kcfg).*\n" "" "${_contents}") 0059 if(CMAKE_MATCH_1) 0060 message(WARNING "${_tmp_FILE}: Broken \"File\" field, make sure it's pointing at the right file") 0061 set(_kcfg_FILENAME "${CMAKE_MATCH_1}") 0062 else() 0063 message(WARNING "Couldn't read the \"File\" field in ${_tmp_FILE}") 0064 set(_kcfg_FILENAME "${_basename}.kcfg") 0065 endif() 0066 endif() 0067 0068 string(REGEX MATCH "HeaderExtension=([^\n]+)\n" "" "${_contents}") 0069 if(CMAKE_MATCH_1) 0070 set(_kcfg_header_EXT "${CMAKE_MATCH_1}") 0071 else() 0072 set(_kcfg_header_EXT "h") 0073 endif() 0074 0075 set(_src_FILE ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.cpp) 0076 set(_header_FILE ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.${_kcfg_header_EXT}) 0077 set(_moc_FILE ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.moc) 0078 set(_kcfg_FILE ${_abs_PATH}/${_kcfg_FILENAME}) 0079 # Maybe the .kcfg is a generated file? 0080 if(NOT EXISTS "${_kcfg_FILE}") 0081 set(_kcfg_FILE ${CMAKE_CURRENT_BINARY_DIR}/${_kcfg_FILENAME}) 0082 endif() 0083 0084 if(NOT EXISTS "${_kcfg_FILE}") 0085 message(FATAL_ERROR "${_kcfg_FILENAME} not found; tried in ${_abs_PATH} and ${CMAKE_CURRENT_BINARY_DIR}") 0086 endif() 0087 0088 # make sure the directory exist in the build directory 0089 if(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/${_rel_PATH}") 0090 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${_rel_PATH}) 0091 endif() 0092 0093 # the command for creating the source file from the kcfg file 0094 add_custom_command(OUTPUT ${_header_FILE} ${_src_FILE} 0095 COMMAND KF6::kconfig_compiler 0096 ARGS ${_kcfg_FILE} ${_tmp_FILE} -d ${CMAKE_CURRENT_BINARY_DIR}/${_rel_PATH} 0097 MAIN_DEPENDENCY ${_tmp_FILE} 0098 DEPENDS ${_kcfg_FILE} KF6::kconfig_compiler) 0099 0100 set_source_files_properties(${_header_FILE} ${_src_FILE} PROPERTIES 0101 SKIP_AUTOMOC ON 0102 SKIP_AUTOUIC ON 0103 ) 0104 0105 if(ARG_GENERATE_MOC) 0106 list(APPEND sources ${_moc_FILE}) 0107 qt_generate_moc(${_header_FILE} ${_moc_FILE}) 0108 set_property(SOURCE ${_src_FILE} APPEND PROPERTY OBJECT_DEPENDS ${_moc_FILE} ) 0109 endif() 0110 0111 list(APPEND sources ${_src_FILE} ${_header_FILE}) 0112 endforeach(_current_FILE) 0113 0114 if(TARGET ${_target_or_source_var}) 0115 target_sources(${_target_or_source_var} PRIVATE ${sources}) 0116 else() 0117 set(${_target_or_source_var} ${${_target_or_source_var}} ${sources} PARENT_SCOPE) 0118 endif() 0119 0120 endfunction(KCONFIG_ADD_KCFG_FILES)