Skip to content
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.

[WIP] Port to KDevelop 5 #23

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
81 changes: 50 additions & 31 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,53 +1,72 @@
cmake_minimum_required(VERSION 3.0.0)

project(kdevkernel)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)

find_package(KDE4 4.7.0 REQUIRED)
find_package(KDevPlatform 1.2.60 REQUIRED)
find_package(ECM REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH})

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
# TODO Check these min versions
set(MIN_KDEV_VERSION "5.1.80")
set(MIN_QT_VER "5.5.0")
set(MIN_KF_VER "5.15.0")

# Find what is the prefix of the KDevelop installation
set(KDevelop_Include_DIR "include/kdevelop")
find_path(KDevelop_PREFIX ${KDevelop_Include_DIR})
set(KDevelop_Include_Full_DIR ${KDevelop_PREFIX}/${KDevelop_Include_DIR})
message(STATUS "KDevelop headers : " ${KDevelop_Include_Full_DIR})

set(KDevPlatform_Include_DIR "include/kdevplatform")
set(KDevPlatform_Include_Full_DIR ${KDevelop_PREFIX}/${KDevPlatform_Include_DIR})
message(STATUS "KDevPlatform headers : " ${KDevPlatform_Include_Full_DIR})

include(KDECompilerSettings NO_POLICY_SCOPE)
include(ECMAddTests)
include(ECMInstallIcons)
include(KDEInstallDirs)
include(KDECMakeSettings)
include(FeatureSummary)

find_package(Qt5 ${MIN_QT_VER} CONFIG REQUIRED Core Gui Widgets Test)
find_package(KF5 ${MIN_KF_VER} REQUIRED COMPONENTS ItemModels TextEditor)
find_package(KDevelop ${MIN_KDEV_VERSION} REQUIRED)
find_package(KDevPlatform ${MIN_KDEV_VERSION} REQUIRED CONFIG)

include_directories(
${KDE4_INCLUDES}
${KDEVPLATFORM_INCLUDE_DIR}
${KDEVPLATFORM_INCLUDE_DIR}/../kdevelop
${KDevPlatform_Include_Full_DIR}
${KDevelop_Include_Full_DIR}
${KDevPlatform_DIR}
${KDevelop_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_SOURCE_DIR}
${CMAKE_PREFIX_PATH}/include/kdevelop
)

set(kdevkernel_plugin_SRCS
kdevkernelplugin.cpp
)

kde4_add_plugin(kdevkernel
${kdevkernel_plugin_SRCS})
target_link_libraries(kdevkernel
${KDEVPLATFORM_PROJECT_LIBRARIES}
${KDEVPLATFORM_INTERFACES_LIBRARIES}
${KDEVPLATFORM_UTIL_LIBRARIES}
${KDEVPLATFORM_OUTPUTVIEW_LIBRARIES}
config/projectconfigpage.cpp
)

set (kdevkernel_kcm_SRCS
kcm_kdevkernel.cpp
kdevkernelconfigwidget.cpp
ki18n_wrap_ui(kdevkernel_plugin_SRCS
config/projectconfigpage.ui
)

kde4_add_ui_files(kdevkernel_kcm_SRCS kdevkernelconfigwidget.ui)
kde4_add_kcfg_files(kdevkernel_kcm_SRCS kcfg_kdevkernelconfig.kcfgc)
kde4_add_plugin(kcm_kdevkernel ${kdevkernel_kcm_SRCS})
target_link_libraries(kcm_kdevkernel ${KDE4_KIO_LIBS} ${KDEVPLATFORM_INTERFACES_LIBRARIES} ${KDEVPLATFORM_LANGUAGE_LIBRARIES} ${KDEVPLATFORM_PROJECT_LIBRARIES} ${KDEVPLATFORM_UTIL_LIBRARIES})

install(
TARGETS kdevkernel
kcm_kdevkernel
DESTINATION ${PLUGIN_INSTALL_DIR}
kconfig_add_kcfg_files(kdevkernel_plugin_SRCS
config/projectconfig.kcfgc
)

install(
FILES kdevkernel.desktop
kcm_kdevkernel.desktop
DESTINATION ${SERVICES_INSTALL_DIR}
kdevplatform_add_plugin(kdevkernel JSON kdevkernel.json SOURCES ${kdevkernel_plugin_SRCS})

target_link_libraries(kdevkernel
KDev::Interfaces
KDev::Project
KDev::OutputView
KDev::Util
)

add_subdirectory(icons)
feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
KDevelop Linux Kernel Development Plugin
========================================

## This branch contains ported code to KF5/Qt5/KDevelop 5. It generally works but with a lot of bugs!

This plugin offers a "Linux Kernel" project type to KDevelop that makes it easy and comfortable to work on the Linux kernel.

The raw KDevelop comes with extremely useful cross-reference and code parsing tools, but they do not apply well to the Linux kernel. Problems are:
Expand Down
25 changes: 25 additions & 0 deletions config/projectconfig.kcfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd">
<kcfgfile arg="true" />

<group name="KDevKernel">
<entry name="buildDir" key="BuildDir" type="Path">
<label>Selected build directory.</label>
</entry>
<entry name="arch" key="Arch" type="String">
<label>Selected architecture.</label>
</entry>
<entry name="defconfig" key="Defconfig" type="String">
<label>Selected defconfig.</label>
</entry>
<entry name="crossCompiler" key="CrossCompiler" type="Path">
<label>Selected defconfig.</label>
</entry>
<entry name="validFiles" key="ValidFiles" type="StringList">
<label>User-specified valid files which would be otherwise ignored.</label>
</entry>
</group>
</kcfg>
3 changes: 3 additions & 0 deletions config/projectconfig.kcfgc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
File=projectconfig.kcfg
NameSpace=KDevKernel
ClassName=ProjectConfig
131 changes: 131 additions & 0 deletions config/projectconfigpage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
* Copyright (C) 2012 Alexandre Courbot <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "projectconfigpage.h"
#include "ui_projectconfigpage.h"

#include "../kdevkernelconfig.h"

#include "projectconfig.h"

#include <interfaces/iproject.h>
#include <util/path.h>

namespace KDevKernel
{

ProjectConfigPage::ProjectConfigPage(KDevelop::IPlugin* plugin, KDevelop::IProject* project, QWidget* parent)
: ConfigPage(plugin, new ProjectConfig, parent)
, ui(new Ui::ProjectConfigPage)
{
this->project = project;

configSkeleton()->setSharedConfig(project->projectConfiguration());
configSkeleton()->load();

ui->setupUi(this);

connect(ui->kcfg_arch, QOverload<const QString &>::of(&KComboBox::currentIndexChanged), this, &ProjectConfigPage::archChanged);
}

ProjectConfigPage::~ProjectConfigPage() = default;

QString ProjectConfigPage::name() const
{
return i18n("kdev-kernel");
}

QString ProjectConfigPage::fullName() const
{
return i18n("Linux Kernel Project Manager");
}

QIcon ProjectConfigPage::icon() const
{
return QIcon::fromTheme(QStringLiteral("kdevkernel"));
}

void ProjectConfigPage::apply()
{
KConfigGroup cg = configSkeleton()->sharedConfig()->group(KERN_KGROUP);
KDevelop::Path projectRoot = project->path();

if (!ui->kcfg_buildDir->url().isEmpty())
cg.writeEntry(KERN_BDIR, ui->kcfg_buildDir->url());
else cg.deleteEntry(KERN_BDIR);

cg.writeEntry(KERN_ARCH, ui->kcfg_arch->currentText());

if (!ui->kcfg_crossCompiler->url().isEmpty()) {
QString cc(ui->kcfg_crossCompiler->url().toLocalFile());
cc.remove("file://");

if (cc.endsWith("gcc")) {
QString crossPrefix(cc.mid(0, cc.size() - 3));
cg.writeEntry(KERN_CROSS, crossPrefix);
} else {
// TODO notify error
}
} else cg.deleteEntry(KERN_CROSS);

// Remove the .config file if configuration changed. This will trigger
// the corresponding make rule from the plugin the next time we parse.
if (ui->kcfg_defconfig->currentText() != cg.readEntry(KERN_DEFCONFIG, "")) {
KDevelop::Path buildDir(cg.readEntry(KERN_BDIR, projectRoot.toUrl()));
// buildDir.adjustPath(KUrl::AddTrailingSlash);
QFile dotConfig(KDevelop::Path(buildDir, ".config").toLocalFile());
if (dotConfig.exists()) dotConfig.remove();
}

cg.writeEntry(KERN_DEFCONFIG, ui->kcfg_defconfig->currentText());

ConfigPage::apply();
}

void ProjectConfigPage::reset()
{
KConfigGroup cg = configSkeleton()->sharedConfig()->group(KERN_KGROUP);

// Fill in the arch values
KDevelop::Path projectRoot = project->path();
QDir archDir(KDevelop::Path(projectRoot, "arch").toLocalFile());
archDir.setFilter(QDir::Dirs);
foreach (const QString &archEntry, archDir.entryList()) {
if (archEntry.startsWith('.')) continue;
ui->kcfg_arch->addItem(archEntry);
}

ui->kcfg_buildDir->setStartDir(projectRoot.toUrl());
ui->kcfg_crossCompiler->setStartDir(QUrl("/usr/bin/"));

ConfigPage::reset();
}

void ProjectConfigPage::archChanged(const QString &arch)
{
ui->kcfg_defconfig->clear();

QUrl projectRoot = project->path().toUrl();
projectRoot.setPath(projectRoot.path() + "/");
QDir configDirs(projectRoot.resolved(QUrl(QString("arch/%1/configs").arg(arch))).toLocalFile());
foreach (const QString &configFile, configDirs.entryList()) {
if (configFile.startsWith('.')) continue;
ui->kcfg_defconfig->addItem(configFile.left(configFile.size() - QString("_defconfig").size()));
}
}

}
47 changes: 28 additions & 19 deletions kdevkernelconfigwidget.h → config/projectconfigpage.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,48 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef KDEVKERNELCONFIGWIDGET_H
#define KDEVKERNELCONFIGWIDGET_H
#ifndef KDEVKERNEL_PROJECTCONFIGPAGE_H
#define KDEVKERNEL_PROJECTCONFIGPAGE_H

#include <kconfiggroup.h>
#include "ui_kdevkernelconfigwidget.h"

#include <QWidget>
#include <QString>

class KConfig;
#include "interfaces/configpage.h"

namespace KDevelop
{
class IProject;
class Path;
}

class KDevKernelConfigWidget : public QWidget, public Ui::KDevKernelConfigWidget
namespace KDevKernel
{

namespace Ui
{
class ProjectConfigPage;
}

class ProjectConfigPage : public KDevelop::ConfigPage
{
Q_OBJECT

public:
KDevKernelConfigWidget(QWidget *parent, const QString &projectRoot);
void loadFrom(KConfig *config);
void saveTo(KConfig *config, KDevelop::IProject *project);
void loadDefaults();
ProjectConfigPage(KDevelop::IPlugin* plugin, KDevelop::IProject* project, QWidget* parent);
~ProjectConfigPage() override;

QString name() const override;
QString fullName() const override;
QIcon icon() const override;

signals:
void changed();
void apply() override;
void reset() override;

private slots:
private Q_SLOTS:
void archChanged(const QString &arch);

private:
const QString _projectRoot;
QScopedPointer<Ui::ProjectConfigPage> ui;
KDevelop::IProject* project;
};

#endif
}

#endif // KDEVKERNEL_PROJECTCONFIGPAGE_H
Loading