Author Topic: New plugin: Premake5 exporter (premake5cb)  (Read 5422 times)

Offline cacb

  • Regular
  • ***
  • Posts: 484
New plugin: Premake5 exporter (premake5cb)
« 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 https://github.com/arnholm/premake5cb , please see the README documentation with screenshots there.

An example Code::Blocks workspace at https://github.com/arnholm/pm5example1 .

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!

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13438
    • Travis build status
Re: New plugin: Premake5 exporter (premake5cb)
« Reply #1 on: July 20, 2021, 12:15:01 pm »
If you look at https://github.com/obfuscated/cb_editor_navigation you could probably add a minimal autotools build system.
This would make packaging your plugin possible for linux distros.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline cacb

  • Regular
  • ***
  • Posts: 484
Re: New plugin: Premake5 exporter (premake5cb)
« Reply #2 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!

Offline cacb

  • Regular
  • ***
  • Posts: 484
Re: New plugin: Premake5 exporter (premake5cb)
« Reply #3 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  https://github.com/chris-be/premake-codeblocks  codeblocks


Using the https://github.com/arnholm/pm5example1 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.

Offline cacb

  • Regular
  • ***
  • Posts: 484
Re: New plugin: Premake5 exporter (premake5cb)
« Reply #4 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:
Code
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
Code
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.
« Last Edit: July 28, 2021, 05:02:20 pm by cacb »