Author Topic: Export to CMake  (Read 12903 times)

Offline seasoned_geek

  • Multiple posting newcomer
  • *
  • Posts: 10
Export to CMake
« on: November 22, 2021, 02:21:57 pm »
All,

Since the CMake created Code::Blocks project doesn't allow for debugging I thought I would ask.

Does Code::Blocks provide a feature/plug-in that will correctly export a Code::Blocks project to a CMakeLists.txt file? This would neatly solve the problem.

Thanks,

Offline sodev

  • Regular
  • ***
  • Posts: 497
Re: Export to CMake
« Reply #1 on: November 22, 2021, 02:39:56 pm »
To achieve what? Generate a CodeBlocks project from CMake to "export" that generated project to CMake again to do what? Generate something else from that generated CMake "project"? Your source is already CMake, use that one directly instead?

Offline seasoned_geek

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Export to CMake
« Reply #2 on: November 22, 2021, 07:32:56 pm »
To achieve what? Generate a CodeBlocks project from CMake to "export" that generated project to CMake again to do what? Generate something else from that generated CMake "project"? Your source is already CMake, use that one directly instead?

It's a two stage process.

The bulk of the system can be developed in a Ubuntu VM. You could compile and debug over 90% there.

The target device build process must use cmake inside of a container. This is the build process. For development we can include a GDB server so one can perform remote debugging.

The younger team members don't know how to use Emacs. Code::Blocks would be good for them but we must be able to utilize CMake, not try to figure out the CMakeLists.txt file __after__ they've "made it work" in the IDE.

The problem with the cmake generation of a Code::Blocks project file is that it is treated as "foreign" by Code::Blocks. You cannot debug.

It appears most IDEs have rather abysmal CMake support. CodeLite most definitely failed despite all of its claims.

I hope this clarifies the situation.

Thank you for your time.



Offline sodev

  • Regular
  • ***
  • Posts: 497
Re: Export to CMake
« Reply #3 on: November 22, 2021, 08:47:49 pm »
I am not familiar with the CMake generator for CodeBlocks nor the limitations of CodeBlocks when using external Makefiles, maybe the generator is flawed or CodeBlocks just can't debug when using external Makefiles. However, i'm quite confident such CodeBlocks -> CMake export will never exist, this is just not how CMake works.

It's quite sad, but CodeBlocks didn't age well. Since you are using CMake, you have basically two options: Use an IDE that CMake can generate project files for or use an IDE that can use CMake directly. Regarding your specific requirements i can highly suggest to take a look at VSCode. Not only does it have native CMake support that allows to build and debug out-of-the-box with zero configuration (depending on how well your CMake files are crafted and what is required to run the configuration step), it also has this neat Remote Development feature. This allows VSCode, while running on a host system, to connect to a container (or anything else that has ssh) and run the build inside there.

Offline seasoned_geek

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Export to CMake
« Reply #4 on: November 22, 2021, 09:57:00 pm »
I am not familiar with the CMake generator for CodeBlocks nor the limitations of CodeBlocks when using external Makefiles, maybe the generator is flawed or CodeBlocks just can't debug when using external Makefiles. However, i'm quite confident such CodeBlocks -> CMake export will never exist, this is just not how CMake works.

It's quite sad, but CodeBlocks didn't age well. Since you are using CMake, you have basically two options: Use an IDE that CMake can generate project files for or use an IDE that can use CMake directly. Regarding your specific requirements i can highly suggest to take a look at VSCode. Not only does it have native CMake support that allows to build and debug out-of-the-box with zero configuration (depending on how well your CMake files are crafted and what is required to run the configuration step), it also has this neat Remote Development feature. This allows VSCode, while running on a host system, to connect to a container (or anything else that has ssh) and run the build inside there.

VSCode not really an option as there are security issues.

CMake generates Code::Blocks project files. It's just that Code::Blocks isn't polite about using them.

So far every IDE that has made the claim of CMake support has failed, at least every one I've looked at.

Emacs appears to be state of the art. It doesn't try to pull down new software or updates while you are building (major security flaw with VSCode) and it doesn't care who generated the Makefile. It appears to debug anything.

Really wanted Code::Blocks to work.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: Export to CMake
« Reply #5 on: November 23, 2021, 02:01:07 am »
Really wanted Code::Blocks to work.

No, you wanted it to work without putting in a major effort on your part!

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline cacb

  • Lives here!
  • ****
  • Posts: 536
Re: Export to CMake
« Reply #6 on: November 23, 2021, 04:45:28 pm »
All,

Since the CMake created Code::Blocks project doesn't allow for debugging I thought I would ask.

Does Code::Blocks provide a feature/plug-in that will correctly export a Code::Blocks project to a CMakeLists.txt file? This would neatly solve the problem.

Thanks,

I am not aware of a C::B to CMake plugin, but I wrote an experimantal C::B to premake5 plugin, see this post .

Premake is an alternative to CMake, with similar objectives. Premake can generate C::B project files. Although I realise that CMake is a de facto standard, I find premake easier to deal with.

In theory, you could use the CMake plugin for premake to generate CMakeLists.txt, but I would not bet on that working too well.

Offline seasoned_geek

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Export to CMake
« Reply #7 on: November 23, 2021, 05:12:30 pm »
Really wanted Code::Blocks to work.

No, you wanted it to work without putting in a major effort on your part!

Tim S.

Given this conversation has been around since 2014

https://forums.codeblocks.org/index.php?topic=19193.0

and CMake went to the effort of generating Code::Blocks project files, and the only thing that isn't working is debugging. That appears to be deliberately blocked. Even Gedehttp://gede.dexar.se/ can do the debugging. It doesn't care what Makefile created the objects and executable because GDB doesn't care.


Offline seasoned_geek

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Export to CMake
« Reply #8 on: November 23, 2021, 05:19:41 pm »

I am not aware of a C::B to CMake plugin, but I wrote an experimantal C::B to premake5 plugin, see this post .

Premake is an alternative to CMake, with similar objectives. Premake can generate C::B project files. Although I realise that CMake is a de facto standard, I find premake easier to deal with.

In theory, you could use the CMake plugin for premake to generate CMakeLists.txt, but I would not bet on that working too well.

Thanks for your response. If I get time I will look into it.

For now, if they want to use Code::Blocks they have to:

  • Edit CMakeLists.txt
  • cmake . -G "CodeBlocks - Unix Makefiles"
  • Edit and compile all of the source files. Repeating this process when they add new source files
  • Use Gede to debug

I really don't know why (or maybe I just missed it) Code::Blocks doesn't have a Debug menu option that lets you navigate to a binary like Gede does. Gdb is Gdb.

Offline AndrewCot

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 678
Re: Export to CMake
« Reply #9 on: November 23, 2021, 10:58:27 pm »
You can download the CMake and/or C::B source code and find where the problem is (assuming it's not your setup as you are having allot of issues) and fix the issue and then send in a patch to the appropriate app devs following their process.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: Export to CMake
« Reply #10 on: November 24, 2021, 04:39:10 am »
I really don't know why (or maybe I just missed it) Code::Blocks doesn't have a Debug menu option that lets you navigate to a binary like Gede does. Gdb is Gdb.

Try "Debug" -> "Attach to process" it might do what you want.
I have never used it.

And, if you have not already tried this try it.
Project -> Set program arguments
Host application

Tim S.
« Last Edit: November 24, 2021, 04:41:33 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline cacb

  • Lives here!
  • ****
  • Posts: 536
Re: Export to CMake
« Reply #11 on: November 24, 2021, 09:36:59 am »
Thanks for your response. If I get time I will look into it.

For now, if they want to use Code::Blocks they have to:

  • Edit CMakeLists.txt
  • cmake . -G "CodeBlocks - Unix Makefiles"
  • Edit and compile all of the source files. Repeating this process when they add new source files
  • Use Gede to debug
I forgot to say that Code::Blocks is supported in Premake5 as an "action" that must be installed separately
https://github.com/chris-be/premake-codeblocks

I really don't know why (or maybe I just missed it) Code::Blocks doesn't have a Debug menu option that lets you navigate to a binary like Gede does. Gdb is Gdb.

As for the issue of debugging applications built with CMake, maybe it can be resolved without changing C::B, that is the first thing I would check. Debug -> Attach to Process is perhaps a way? If that doesn't solve it. perhaps a simple patch to C::B will?

Btw. Gede looks nice. I was never 100% satisfied with the builtin debugger in Code::Blocks. On Windows I use the MSVC compiler in Code::Blocks, but launch the Visual Studio debugger from the C::B Tools menu. I will try the same approach on Linux with Gede and see what happens, thanks for the idea.

Offline jordi

  • Multiple posting newcomer
  • *
  • Posts: 22
Re: Export to CMake
« Reply #12 on: December 10, 2021, 09:56:30 pm »
Hi all,
I am a newbie in codeblocks and cmake programs but I did a test with a cmake project in https://gitlab.com/CLIUtils/modern-cmake/tree/master/examples/simple-project
Effectively, codeblocks debugger is not working with
cmake . -G "CodeBlocks - Unix Makefiles"
Because with the above command you are compiling without the debugging compiler option.
I've tried with the next command
jordi@debian:~/test/cmake/simple-project/build$ cmake  -G "CodeBlocks - Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug ..
and codeblocks debugger works correctly.
Regards

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Export to CMake
« Reply #13 on: December 11, 2021, 03:39:04 pm »
Btw. Gede looks nice. I was never 100% satisfied with the builtin debugger in Code::Blocks. On Windows I use the MSVC compiler in Code::Blocks, but launch the Visual Studio debugger from the C::B Tools menu. I will try the same approach on Linux with Gede and see what happens, thanks for the idea.

C::B's debugger need to be improved, OBF's has an gdb-mi debugger plugin implemented several years ago. But I think he does not have time to maintain it.

I see gede also has a gdbmiparser.cpp file as its source code.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.