diff --git a/KF5ConfigMacros.cmake b/KF5ConfigMacros.cmake --- a/KF5ConfigMacros.cmake +++ b/KF5ConfigMacros.cmake @@ -75,8 +75,23 @@ set(_kcfg_FILENAME "${_basename}.kcfg") endif() endif() - set(_src_FILE ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.cpp) - set(_header_FILE ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.h) + + string(REGEX MATCH "HeaderExtension=([^\n]+)\n" "" "${_contents}") + if(CMAKE_MATCH_1) + set(_kcfg_header_EXT "${CMAKE_MATCH_1}") + else() + set(_kcfg_header_EXT "h") + endif() + + string(REGEX MATCH "SourceExtension=([^\n]+)\n" "" "${_contents}") + if(CMAKE_MATCH_1) + set(_kcfg_src_EXT "${CMAKE_MATCH_1}") + else() + set(_kcfg_src_EXT "cpp") + endif() + + set(_src_FILE ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.${_kcfg_src_EXT}) + set(_header_FILE ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.${_kcfg_header_EXT}) set(_moc_FILE ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.moc) set(_kcfg_FILE ${_abs_PATH}/${_kcfg_FILENAME}) # Maybe the .kcfg is a generated file? diff --git a/autotests/kconfig_compiler/CMakeLists.txt b/autotests/kconfig_compiler/CMakeLists.txt --- a/autotests/kconfig_compiler/CMakeLists.txt +++ b/autotests/kconfig_compiler/CMakeLists.txt @@ -241,3 +241,11 @@ ecm_add_test(TEST_NAME test_translation_kde_domain ${test_translation_kde_domain_SRCS}) target_link_libraries(test_translation_kde_domain KF5::ConfigGui) + +########### next target ############### + +set(test_fileextensions_SRCS test_fileextensions_main.cxx) +gen_kcfg_test_source(test_fileextensions test_fileextensions_SRCS) + +ecm_add_test(TEST_NAME test_fileextensions ${test_fileextensions_SRCS}) +target_link_libraries(test_fileextensions KF5::ConfigGui) diff --git a/autotests/kconfig_compiler/test_fileextensions.kcfg b/autotests/kconfig_compiler/test_fileextensions.kcfg new file mode 100644 --- /dev/null +++ b/autotests/kconfig_compiler/test_fileextensions.kcfg @@ -0,0 +1,16 @@ + + + + + + + + Enable automatic saving of calendars to have calendars saved automatically. + false + + + + diff --git a/autotests/kconfig_compiler/test_fileextensions.kcfgc b/autotests/kconfig_compiler/test_fileextensions.kcfgc new file mode 100644 --- /dev/null +++ b/autotests/kconfig_compiler/test_fileextensions.kcfgc @@ -0,0 +1,7 @@ +# Code generation options for kconfig_compiler_kf5 +File=test_fileextensions.kcfg +Singleton=true +ClassName=TestFileExtensions +SetUserTexts=true +HeaderExtension=hxx +SourceExtension=cxx diff --git a/autotests/kconfig_compiler/test_fileextensions_main.cxx b/autotests/kconfig_compiler/test_fileextensions_main.cxx new file mode 100644 --- /dev/null +++ b/autotests/kconfig_compiler/test_fileextensions_main.cxx @@ -0,0 +1,32 @@ +/* +Copyright 2019 Friedrich W. H. Kossebau + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include "test_fileextensions.hxx" +#include + +int main(int argc, char **argv) +{ + QGuiApplication app(argc, argv); + Q_UNUSED(app); + TestFileExtensions *t = TestFileExtensions::self(); + delete t; + return 0; +} diff --git a/src/kconfig_compiler/README.dox b/src/kconfig_compiler/README.dox --- a/src/kconfig_compiler/README.dox +++ b/src/kconfig_compiler/README.dox @@ -96,6 +96,18 @@ programname.kcfg Name of kcfg file containing the options the class is generated for + + HeaderExtension + string + h + Extension to use for the name of the generated C++ header files. Since KF 5.57 + + + SourceExtension + string + cpp + Extension to use for the name of the generated C++ source file. Since KF 5.57 + NameSpace string diff --git a/src/kconfig_compiler/checkkcfg.pl b/src/kconfig_compiler/checkkcfg.pl --- a/src/kconfig_compiler/checkkcfg.pl +++ b/src/kconfig_compiler/checkkcfg.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -if ( @ARGV != 1 ) { +if ( @ARGV < 1 ) { print STDERR "Missing arg: filename\n"; exit 1; } @@ -10,8 +10,10 @@ $file =~ /^(.*)\.[^\.]*$/; $filebase = $1; -$file_h = "$filebase.h"; -$file_cpp = "$filebase.cpp"; +$header_extension = @ARGV > 1 ? $ARGV[1] : "h"; +$source_extension = @ARGV > 2 ? $ARGV[2] : "cpp"; +$file_h = "$filebase.$header_extension"; +$file_cpp = "$filebase.$source_extension"; $kcfgc = $file . "c"; diff --git a/src/kconfig_compiler/kconfig_compiler.cpp b/src/kconfig_compiler/kconfig_compiler.cpp --- a/src/kconfig_compiler/kconfig_compiler.cpp +++ b/src/kconfig_compiler/kconfig_compiler.cpp @@ -108,6 +108,8 @@ translationSystem = QtTranslation; } qCategoryLoggingName = codegenConfig.value(QStringLiteral("CategoryLoggingName"), QString()).toString(); + headerExtension = codegenConfig.value(QStringLiteral("HeaderExtension"), QStringLiteral("h")).toString(); + sourceExtension = codegenConfig.value(QStringLiteral("SourceExtension"), QStringLiteral("cpp")).toString(); } public: @@ -131,6 +133,8 @@ QStringList mutators; QStringList defaultGetters; QString qCategoryLoggingName; + QString headerExtension; + QString sourceExtension; bool allMutators; bool setUserTexts; bool allDefaultGetters; @@ -1742,8 +1746,8 @@ } #endif - QString headerFileName = baseName + ".h"; - QString implementationFileName = baseName + ".cpp"; + QString headerFileName = baseName + '.' + cfg.headerExtension; + QString implementationFileName = baseName + '.' + cfg.sourceExtension; QString mocFileName = baseName + ".moc"; QString cppPreamble; // code to be inserted at the beginnin of the cpp file, e.g. initialization of static values @@ -2199,7 +2203,7 @@ if (cfg.customAddons) { h << " // Include custom additions" << endl; - h << " #include \"" << filenameOnly(baseName) << "_addons.h\"" << endl; + h << " #include \"" << filenameOnly(baseName) << "_addons." << cfg.headerExtension << '"' << endl; } h << "};" << endl << endl;