Author Topic: New plugin to create Makefile project with existing code  (Read 7775 times)

Offline christo

  • Multiple posting newcomer
  • *
  • Posts: 25
New plugin to create Makefile project with existing code
« on: August 30, 2023, 06:19:30 am »
https://github.com/josephch/CBMakefileProjectWithExistingCode

More details are available in README.md.

It is similar to the feature in eclipse CDT.

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Re: New plugin to create Makefile project with existing code
« Reply #1 on: August 30, 2023, 06:52:54 am »
https://github.com/josephch/CBMakefileProjectWithExistingCode

More details are available in README.md.

It is similar to the feature in eclipse CDT.

I see, in the readme, that there is some problem with clangd_client.
Can you give me a 1,2,3 type steps to recreate the problem? I'd like to help resolve this if I can.

Offline christo

  • Multiple posting newcomer
  • *
  • Posts: 25
Re: New plugin to create Makefile project with existing code
« Reply #2 on: August 30, 2023, 07:13:55 am »
I see, in the readme, that there is some problem with clangd_client.
Can you give me a 1,2,3 type steps to recreate the problem? I'd like to help resolve this if I can.
1. Build and install MakefileProjectWithExistingCode plugin
2. Restart C::B and make sure no other projects are open.
3. In the File menu, select "Makefile Project With Existing Code"  and add any directory which contains C++ files.
You can see that in the projects pane, project is not listed properly. you can see following print repeated in the console.
Quote
GetLSPclient: No associated pClient in m_LSP_Clients[pProject]

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Re: New plugin to create Makefile project with existing code
« Reply #3 on: September 05, 2023, 06:40:42 pm »
@Christo
I've made some mods to clangd_client to more properly handle a custom makefile project.

Because a makefile project most likely does not contain all the info needed by clangd to properly parse a translation unit, it gets a large number of lines marked as errors.

I've adjusted clangd_client to pause parsing when the activated project is marked "custom makefile".
But the user can force parsing by unticking "Pause parsing (toggle)" for the project entry in the Projects tree.

Parsing can also be invoked by choosing "Reparse this project" in the Projects entry.
See the snapshot jpg below.

You might also consider adding ".cache" to the list of excluded files. Clangd keeps a lot of .idx files in that directory.

Just a thought to avoid confusing other plugins, you might consider the following (maybe overly cautious) changes:
The close will flush any status other plugins might be holding. And the new open will load a cleanly saved project that other plugins may have missed with just a "SetProject()" call.
To do this, I've commented some lines of your code. You may have to adjust as you see fit.

Code
    else
    {
        //projectManager->BeginLoadingProject();
        prj->SetMakefileCustom(true);
        prj->AddBuildTarget("all");

        wxArrayInt targets;
        targets.Add(0);

        projectManager->AddMultipleFilesToProject(filelist, prj, targets);
        Manager::Get()->GetLogManager()->Log(wxString::Format(_("%s Added %d files!"), pluginName, (int)filelist.GetCount()));
        prj->SetModified(true);
        prj->CalculateCommonTopLevelPath();
        prj->Save();
        //projectManager->EndLoadingProject(prj);

        if (!projectManager->IsLoadingWorkspace())
        {
            //- projectManager->SetProject(prj);
            /** Close a project.
              * @param project A pointer to the project to close.
              * @param dontsave Force not (!) saving the project on close.
              * @param refresh Force a refresh of the project tree after closing a project.
              * @return True if project was closed, false if not.
              */
            bool ok = projectManager->CloseProject(prj, /*bool dontsave =*/ true, /*bool refresh =*/ true);

            /** Load a project from disk. This function, internally, uses IsOpen()
            * so that the same project can't be loaded twice.
            * @param filename The project file's filename.
            * @param activateIt Active the project after loading.
            * @return If the function succeeds, a pointer to the newly opened project
            * is returned. Else the return value is NULL.
            */
            //cbProject* LoadProject(const wxString& filename, bool activateIt = true);
           cbProject* prj = projectManager->LoadProject(fileName, true);

        }
        projectManager->GetUI().RebuildTree();
        ret = true;
    }
    return ret;

Your plugin works well on Windows also with the following added target:
Code
			<Target title="to_wn_wx32_64">
<Option output="bin/MakefileProjectWithExistingCode" prefix_auto="1" extension_auto="1" />
<Option object_output=".objs/to_codeblocks_wx32" />
<Option type="3" />
<Option compiler="gcc" />
<Option parameters="--debug-log --multiple-instance --no-splash-screen --verbose -p debug --no-dde --no-check-associations /p debug" />
<Option host_application="$(CODEBLOCKS)/../devel32_64/codeblocks.exe" />
<Option run_host_application_in_terminal="0" />
<Compiler>
<Add option="-g" />
<Add directory="$(#wx32.include)" />
<Add directory="$(#wx32.lib)/gcc_dll/mswu" />
<Add directory="$(#cb)/include" />
<Add directory="$(#cb)/sdk/wxscintilla/include" />
<Add directory="$(#cb)/include/tinyxml" />
</Compiler>
<Linker>
<Add library="wxmsw32u" />
<Add library="codeblocks" />
<Add directory="$(#wx32.lib)/gcc_dll" />
<Add directory="$(#cb)/devel32_64" />
<Add directory="$(#cb)/devel32" />
</Linker>
<ExtraCommands>
<Add before="cmd.exe /c echo CodeBlocks: $(codeblocks)" />
<Add before="cmd.exe /c echo cb: $(#cb)" />
<Add before="cmd.exe /c echo LinkFrom: $(#cb)\devel32_64" />
<Add after="zip -j9 .\bin\MakefileProjectWithExistingCode.zip manifest.xml" />
<Add after="cmd /c copy bin\MakefileProjectWithExistingCode.zip $(CODEBLOCKS)\..\devel32_64\share\codeblocks\" />
<Add after="cmd /c copy bin\MakefileProjectWithExistingCode.dll $(CODEBLOCKS)\..\devel32_64\share\codeblocks\plugins\" />
<Mode after="always" />
</ExtraCommands>
</Target>


Thanks for your work.
« Last Edit: September 05, 2023, 07:33:53 pm by Pecan »

Offline christo

  • Multiple posting newcomer
  • *
  • Posts: 25
Re: New plugin to create Makefile project with existing code
« Reply #4 on: September 05, 2023, 08:00:13 pm »
@Pecan, thank you. Changed the plugin according to your suggestions.

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2778
Re: New plugin to create Makefile project with existing code
« Reply #5 on: September 06, 2023, 07:17:45 pm »
@Christo

There's an error in the .cbp for Windows.
The line:
Code
<Add alias="All" targets="default;to_codeblocks_wx28;to_codeblocks_wx30;to_codeblocks_wx31;to_codeblocks_wx32;to_codeblocks_wx33;" />
"

should be:
Code
Add alias="All" targets="to_wn_wx32_64;" />

else the Windows project will not compile when the target is set to "All"

Offline christo

  • Multiple posting newcomer
  • *
  • Posts: 25
Re: New plugin to create Makefile project with existing code
« Reply #6 on: September 06, 2023, 08:21:06 pm »
Thanks @Pecan, corrected project file for Windows.