1// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#include "cxxplugin.h"
6
7#include "cmake/cmakegenerator.h"
8#include "ninja/ninjagenerator.h"
9#include "cmake/builder/mainframe/cmakebuildergenerator.h"
10#include "cmake/option/optioncmakegenerator.h"
11#include "cmake/project/mainframe/properties/targetsmanager.h"
12#include "cmake/project/mainframe/cmakeprojectgenerator.h"
13#include "ninja/project/ninjaprojectgenerator.h"
14#include "ninja/builder/mainframe/ninjabuildergenerator.h"
15#include "ninja/option/optionninjagenerator.h"
16
17#include "services/language/languageservice.h"
18#include "services/project/projectservice.h"
19#include "services/option/optionservice.h"
20
21using namespace dpfservice;
22
23void CxxPlugin::initialize()
24{
25 qInfo() << __FUNCTION__;
26}
27
28bool CxxPlugin::start()
29{
30 qInfo() << __FUNCTION__;
31 auto &ctx = dpfInstance.serviceContext();
32 LanguageService *languageService = ctx.service<LanguageService>(LanguageService::name());
33 if (languageService) {
34 QString errorString;
35 bool ret = languageService->regClass<CMakeGenerator>(CMakeGenerator::toolKitName(), &errorString);
36 if (!ret) {
37 qCritical() << errorString;
38 } else {
39 ret = languageService->create<CMakeGenerator>(CMakeGenerator::toolKitName(), &errorString);
40 if (!ret) {
41 qCritical() << errorString;
42 }
43 }
44
45 ret = languageService->regClass<NinjaProjectGenerator>(NinjaProjectGenerator::toolKitName(), &errorString);
46 if (!ret) {
47 qCritical() << errorString;
48 } else {
49 ret = languageService->create<NinjaProjectGenerator>(NinjaProjectGenerator::toolKitName(), &errorString);
50 if (!ret) {
51 qCritical() << errorString;
52 }
53 }
54 }
55
56 ProjectService *projectService = ctx.service<ProjectService>(ProjectService::name());
57 if (projectService) {
58 QString errorString;
59 projectService->implGenerator<CmakeProjectGenerator>(CmakeProjectGenerator::toolKitName(), &errorString);
60 }
61
62 if (projectService && !projectService->getActiveTarget) {
63 using namespace std::placeholders;
64 projectService->getActiveTarget = std::bind(&TargetsManager::getActivedTargetByTargetType, TargetsManager::instance(), _1);
65 }
66 if (projectService) {
67 QString errorString;
68 projectService->implGenerator<NinjaProjectGenerator>(NinjaProjectGenerator::toolKitName(), &errorString);
69 }
70
71 OptionService *optionService = ctx.service<OptionService>(OptionService::name());
72 if (!optionService) {
73 qCritical() << "Failed, not found option service!";
74 abort();
75 }
76 optionService->implGenerator<OptionCmakeGenerator>(OptionCmakeGenerator::kitName());
77 optionService->implGenerator<OptionNinjaGenerator>(OptionNinjaGenerator::kitName());
78
79 BuilderService *builderService = ctx.service<BuilderService>(BuilderService::name());
80 if (builderService) {
81 QString errorString;
82 bool retCmake = builderService->regClass<CMakeBuilderGenerator>(CMakeBuilderGenerator::toolKitName(), &errorString);
83 if (retCmake) {
84 builderService->create<CMakeGenerator>(CMakeGenerator::toolKitName(), &errorString);
85 }
86 bool retNinja = builderService->regClass<NinjaBuilderGenerator>(NinjaBuilderGenerator::toolKitName(), &errorString);
87 if (retNinja) {
88 builderService->create<NinjaBuilderGenerator>(NinjaBuilderGenerator::toolKitName(), &errorString);
89 }
90 }
91 return true;
92}
93
94dpf::Plugin::ShutdownFlag CxxPlugin::stop()
95{
96 qInfo() << __FUNCTION__;
97 return Sync;
98}
99
100
101