Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Plugins development => Topic started by: cacb on July 20, 2021, 12:08:30 pm

Title: New plugin: Premake5 exporter (premake5cb)
Post by: cacb on July 20, 2021, 12:08:30 pm
Hi all,

I have many Code::Blocks workspaces and enjoy the IDE, thanks for the great work done by the C::B developers!  Sometimes, however, I need to share my work with others who do not use Code::Blocks. Some people expect Visual Studio solutions for example, so I was considering how to do it.

It was suggested to me to maintain a separate CMake script along the C::B workspace/projects, but that idea did not appeal to me. I do want the convenience of Code::Blocks, I don't want to maintain a parallel build system and finally I think the CMake syntax is awful and difficult.  Therefore, a different idea was instead to create a Code::Blocks plugin to automatically generate a  Premake5 ( script, because Premake5 seems well structured and well documented. It can generate GNU makefiles as well as Visual Studio solutions. Thus, the idea of Premake5 exporter ( plugin for Code::Blocks was born.

Of course, some will say this can never work and it is a bad idea. In a way it is true, because there will always be examples that don't work properly. Still, if I can apply some assumptions and make it work for my Code::Blocks workspaces, it is still useful to me, and quite possibly to others as well.

You can find the plugin at , please see the README documentation with screenshots there.

An example Code::Blocks workspace at .

The plugin currently builds on Linux only, it is possible that the project file does not correspond 100% to other plugins, I had to tweak it to make it work, but it does work fine here, and it is even possible to generate the required Visual Studio solution with premake5 under Linux.

If you have constructive suggestions, please share. This is somewhat experimental at this stage!
Title: Re: New plugin: Premake5 exporter (premake5cb)
Post by: oBFusCATed on July 20, 2021, 12:15:01 pm
If you look at you could probably add a minimal autotools build system.
This would make packaging your plugin possible for linux distros.
Title: Re: New plugin: Premake5 exporter (premake5cb)
Post by: cacb on July 20, 2021, 01:53:43 pm
Thanks, that would indeed be a good idea. I have zero experience with autotools, and even looking at your example I am quite mystified about what to do. If someone wants to help with that, I would be happy to include it!
Title: Re: New plugin: Premake5 exporter (premake5cb)
Post by: cacb on July 24, 2021, 12:53:40 pm
It sometimes possible to perform a "roundtrip" :

Code::Blocks workspace  ---(1)--> Premake5 script  ---(2)--> Code::Blocks workspace

(1) is obviously done using the Premake5 exporter ( plugin

(2) is done using a Premake5 plugin generating Code::Blocks workspaces :-)

To install and use (2)

cd ~
mkdir ./.premake
cd .premake
git clone  codeblocks

Using the example, add the following to the pm5example1_premake5.lua file:

require "codeblocks"

Then run Premake5
premake5 --file=pm5example1_premake5.lua codeblocks

The result is a new set of Code::Blocks .workspace and .cbp files in a subfolder.
Title: Re: New plugin: Premake5 exporter (premake5cb)
Post by: cacb on July 26, 2021, 08:54:43 pm
Premake5 exporter has been updated to better accommodate generating for several build systems at once. For example, you may want to generate both linux makefiles and Visual Studio solution files at the same time, but keep them separate. The only difference when generating these files is the Premake5 action ( specified on the command line (the file pm5example1_premake5.lua is generated by Premake5 exporter ):

Run premake5 to generate makefiles:
m5example1$ premake5 --file=pm5example1_premake5.lua gmake2
Building configurations...
Running action 'gmake2'...
Generated build/gmake2/Makefile...
Generated build/gmake2/long/path/staticlib1/Makefile...
Generated build/gmake2/dynlib1/Makefile...
Generated build/gmake2/testconsole/Makefile...

Run premake5 to generate Visual Studio files
pm5example1$ premake5 --file=pm5example1_premake5.lua vs2019
Building configurations...
Running action 'vs2019'...
Generated build/vs2019/pm5example1.sln...
Generated build/vs2019/long/path/staticlib1/staticlib1.vcxproj...
Generated build/vs2019/dynlib1/dynlib1.vcxproj...
Generated build/vs2019/testconsole/testconsole.vcxproj...

Generating for different build systems is now better organised in separate folders under the common 'build' root.