Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: cacb on November 14, 2020, 10:20:05 am

Title: C::B Workspace/project to cmake or premake?
Post by: cacb on November 14, 2020, 10:20:05 am
Hi, this may be a naive question, but anyway....

I have lots of Code::Blocks workspaces with several projects dependent on each other. I find this way of working quite excellent so that is fine and I want to keep it that way. My projects use C::B global variables a lot.

Now someone approached me and said they want to build my stuff using CMake . But I don't find it tempting to use CMake as a build system during development (even within C::B), but I can see it would be nice to offer as a "deployment build system". 

Therefore: Have anyone considered automatic generation of CMake files (CMakeLists.txt) or similar for premake from Code::Blocks workspace and project files? I know cbp2make exists for plain make files, so what I am asking for would be kind of similar, but targeting CMake /Premake.

A C::B plugin that allowed export of a C::B workspace to CMake or Premake would bee nice...

Thoughts?

Title: Re: C::B Workspace/project to cmake or premake?
Post by: oBFusCATed on November 14, 2020, 12:12:04 pm
I doubt it would be possible or it would work well.
Fitting the C::B model of projects to CMakes might not match 1:1 and then there would be problems.
Also CMake requires the build system to be out-of-tree and most CB projects are in-tree.

CMake is meant to be used the other way - you write the cmake files by hand and it generates the ide projects/build system.
Title: Re: C::B Workspace/project to cmake or premake?
Post by: cacb on November 14, 2020, 12:43:45 pm
I doubt it would be possible or it would work well.
I guess that is a "no" to my question if anyone have given it a thought for C::B, but I have seen discussions elsewhere of the same idea. But of course, the fact that I have not found such a tool could mean you are right. But I am not convinced.

CMake is meant to be used the other way - you write the cmake files by hand and it generates the ide projects/build system.
Of course I know that, but I disagree with this way of thinking, as maintaining the CMakeLists.txt (or premake equivalent) file would be a nightmare + several other arguments that I will not go into here. C::B projects are well defined in .cbp files, so I can't see why they can not be transformed into CMake or Premake input. If there is an argument about "out-of-tree", well then put the generated CMakeLists.txt (or premake equivalent)  file elsewhere.

In any case, it looks like my main question is answered: No such plugin or external tool exists. So if it becomes a real need, I probably have to create it myself.
Title: Re: C::B Workspace/project to cmake or premake?
Post by: oBFusCATed on November 14, 2020, 12:54:57 pm
If you cannot find it with a simple search in your favourite search engine or github, then probably it doesn't exists.

BTW: CMake is a lot more powerful than our own build system would ever be and it is slow and stupid, but that is how life work not-perfect solutions win at the end.
BTW2: The current integration of cmake is not ideal, it should be the other way round CB should parse cmakefiles and generate the projects somehow. Someday if I get to do the other build system (meson) I'll see if there is a better way. :)
Title: Re: C::B Workspace/project to cmake or premake?
Post by: alexchen on December 18, 2020, 07:37:49 pm
How about generating just simple Make files from CB?  This is our challenge:  we need to build the same source on multiple platforms, Windows, macOS and Linux. Both Windows and macOS's IDE, VS/Xcdoe, can launch the build with command line interface.  CB also has the capability to build from command line but it still needs to pop up a GUI window. If fails with requirement of GTK if I try to launch the command line build from a TTY console.  And we also encounter occasional CB crash in wxGTK library.  We would like to use CB for development build and be able to run Makefile in production builds. 
I remember seeing older version of CB that offers an option to export the project to Makefile.  Do I remember it wrong?
Title: Re: C::B Workspace/project to cmake or premake?
Post by: oBFusCATed on December 18, 2020, 08:33:10 pm
Search for cb2make.
Title: Re: C::B Workspace/project to cmake or premake?
Post by: stahta01 on December 19, 2020, 12:10:34 am
Search for cb2make.

cbp2make if I recall correctly
Title: Re: C::B Workspace/project to cmake or premake?
Post by: oBFusCATed on December 19, 2020, 08:57:41 am
Yes, my mistake.
Title: Re: C::B Workspace/project to cmake or premake?
Post by: cacb on December 20, 2020, 06:46:50 pm
I remember seeing older version of CB that offers an option to export the project to Makefile.  Do I remember it wrong?
cbp2make should be available in your current installation, at least it is in mine. It may do what you want, but I never quite figured it out 100%

If I get the required time and inspiration I may try to prototype C::B to CMake or premake and see what happens. In my mind the C::B build system serves a different purpose (developer build system) compared to CMake or premake (deployment build system), so to me it makes sense to try. Even if it didn't work for all projects it might be useful.
Title: Re: C::B Workspace/project to cmake or premake?
Post by: oBFusCATed on December 21, 2020, 01:14:13 pm
@cacb:
CMake already supports Code::Blocks. With cmake it is the other way round - you write the build system and you get the project files. Generating cmake files from cbp files doesn't make too much sense. Also given the specifics of cmake it might be really hard task to do (cmake has some policies, which a cbp workspace might not follow and then it would be really hard to do the mapping).

There is a thing called cmake-server, but it seems deprecated O_O...
So now there is this https://cmake.org/cmake/help/latest/manual/cmake-file-api.7.html#manual:cmake-file-api(7)
Probably support for it might be more useful.

Meson is another build system which works similarly to cmake. And there the idea is to do an introspection of it (there is an api).

p.s. I plan in the distant future to make a ninja-build generator...
Title: Re: C::B Workspace/project to cmake or premake?
Post by: cacb on December 22, 2020, 05:58:57 pm
CMake already supports Code::Blocks. With cmake it is the other way round - you write the build system and you get the project files. Generating cmake files from cbp files doesn't make too much sense. Also given the specifics of cmake it might be really hard task to do (cmake has some policies, which a cbp workspace might not follow and then it would be really hard to do the mapping).
I know this is the conventional thinking, but I am turning it around anyway. To me, Code::Blocks is the natural development environment during lots of code changing, source files coming and going. For this I am using C::B project files, and I am not willing to give that up and somehow use CMake instead during development.

With released code the situation is different, with stable source files and end user building the software. In that scenario, something like CMake, Premake (or Meson as you mentioned) makes more sense. So to me it does make sense to derive e.g. CMakeLists.txt from Code::Blocks project files. Now, you are probably right to say this is not possible in all cases and I get that. But if I am able to do it for my projects given some rules of how I set up project files, and maybe some user input when generating CMake files I can live with that just fine.


I have almost zero experience with creating CMakeLists.txt, but when I tried yesterday it appeared (https://github.com/arnholm/dep3) you have to list all the source files explicitly, so that alone is a motivation for deriving from a Code::blocks project file. Then there are other things you can extract, such as target type, compiler options and dependencies. I will think more about it and experiment.

Title: Re: C::B Workspace/project to cmake or premake?
Post by: oBFusCATed on December 22, 2020, 06:26:56 pm
It seems that you have experience only with going the project way.
You have to gain some native cmake experience before you could make good decisions what is best or usable.
Title: Re: C::B Workspace/project to cmake or premake?
Post by: user2024 on February 08, 2024, 03:59:25 pm

BTW2: The current integration of cmake is not ideal, it should be the other way round CB should parse cmakefiles and generate the projects somehow. Someday if I get to do the other build system (meson) I'll see if there is a better way. :)
Do you mean something like generating a reasonable codeblocks project from this strange cmakelists.txt file? If so, that would be very useful, because I found a lot of projects on the net that use this cmakelists.txt, but converting them into a codeblocks project doesn't work. For this conversion into codeblocks project I use the latest version of cmake, but the program is just rubbish.
Title: Re: C::B Workspace/project to cmake or premake?
Post by: sodev on February 08, 2024, 08:05:00 pm
CMake is the future! Finally the C++ world is getting some sort of standard build system that does not only drive automated builds but can also be used by any IDE. Finally you don't have to maintain multiple build systems to make your CI and users happy.

However, this requires that your favorite IDE does support CMake, which CodeBlocks currently doesn't, and it doesn't look like it will in the near future.
Title: Re: C::B Workspace/project to cmake or premake?
Post by: user2024 on February 08, 2024, 08:30:42 pm
However, this requires that your favorite IDE does support CMake,
And which IDE does that?
Title: Re: C::B Workspace/project to cmake or premake?
Post by: cacb on February 08, 2024, 09:48:49 pm
CMake is the future! Finally the C++ world is getting some sort of standard build system that does not only drive automated builds but can also be used by any IDE. Finally you don't have to maintain multiple build systems to make your CI and users happy.

However, this requires that your favorite IDE does support CMake, which CodeBlocks currently doesn't, and it doesn't look like it will in the near future.
I have had the mixed pleasure of using CMake integrated into VScode for C++ development. What I said earlier in this thread still stands. Using CMake hasn't convinced me it is the future, on the contrary.

By the way I did write a C::B to premake plugin to test out the idea
https://gitlab.com/arnholm/premake5cb
Title: Re: C::B Workspace/project to cmake or premake?
Post by: sodev on February 08, 2024, 10:58:17 pm
There is definately a learning curve using CMake, this out-of-tree approach feels pretty strange when you are used to the in-tree approach, but today i don't want to go back anymore. I was using CodeBlocks + Premake for around 10 years (in the beginning without Premake) but in the opposite direction like your plugin, Premake was my source and i generated CodeBlocks projects and Makefiles from it. CMake is still not there in the C++ world where Gradle is in the Java world, due to the nature of native code probably will never be, but i like the progress i see. Yes, i remember the past when i was annoyed about that CMakeLists.txt file in libraries i wanted to use and looked for alternatives, now im annoyed when that file is not there :).

About other IDEs with CMake integration, there is an overview here (https://cmake.org/cmake/help/latest/guide/ide-integration/index.html), the only one i am really using is VSCode. Yes, there is also a learning curve, especially if you are used to classic desktop applications, maybe its easier for "digital natives" who have never seen anything else than web-stuff :P. But once you found the proper extensions and made the right settings, its a pretty awesome IDE :).
Title: Re: C::B Workspace/project to cmake or premake?
Post by: Wkerry on February 09, 2024, 09:08:57 am
If you want to use CMAKE seach the forum for CMAKE plugins and ask why has it not progressed as I have no idea what happened to the dev who was working on it last.
Title: Re: C::B Workspace/project to cmake or premake?
Post by: user2024 on February 09, 2024, 01:25:57 pm

By the way I did write a C::B to premake plugin to test out the idea

And what about the opposite direction, premake to C::B?
Title: Re: C::B Workspace/project to cmake or premake?
Post by: cacb on February 10, 2024, 11:02:46 am

By the way I did write a C::B to premake plugin to test out the idea

And what about the opposite direction, premake to C::B?
They do exist, I have one installed under Kubuntu 22.04
https://github.com/chris-be/premake-codeblocks

These days I just use Code::Blocks.
Title: Re: C::B Workspace/project to cmake or premake?
Post by: cacb on February 10, 2024, 10:16:36 pm
Slightly off topic comment: On the principles of build systems, I like the ideas put forward in this video

Better Way to Build C
https://www.youtube.com/watch?v=mLUhSPD4F2k

It is not a fully developed idea and if I did it I would use simple C++. But one important argument is why use an 'incomprehensible' script like CMake when you already have a much more powerful and familiar language like C++ when you are developing a C++ application?. The whole build system could be simple C++ source code which is easily bootstrapped and used for building an application.  It even knows which compiler used for bootstrapping it and will be used for building the application. Something like that seems appealing even as an incomplete idea.
Title: Re: C::B Workspace/project to cmake or premake?
Post by: user2024 on February 10, 2024, 11:29:02 pm

They do exist, I have one installed under Kubuntu 22.04
https://github.com/chris-be/premake-codeblocks

These days I just use Code::Blocks.
And can this thing turn this cmakelist.txt into a Code::Blocks? Does it only work on Linux and only with this clang?