How to use custom build?

已完成

Issue:  my project does not use cmake, instead I create a "fake" CmakeLists.txt file which contains all headers but no build targets. This works amazingly, CLion parses all code and all headers correctly. However I also want to debug my apps.

So far I found two solutions:

1) Create external tool in "Settings -> Tools -> External Tools". In run configuration add "Before Launch" -> "Run external tool" and select that external tool.

External tool needs to know what to build, so I put: Working Directory = $FileDir$

This works almost ideally. Two issues:  1) gcc errors on console are unclickable, you cannot click to navigate to that file:line.  2) you need to open some file of that directory in editor. If you editor is now in other dir and you hit "debug" - it will try to build wrong dir.

2) Create "Custom Build Target".  This menu is extremely hidden, jetbrains want to make our life hard :(

It is in: "Tools -> Build -> Custom Build Target -> Plus sign to create new target -> Click triple dot menu -> Plus sign"

(note: if you need to modify it -- you need to do all those 6 clicks again)

This allows you to enter custom command, e.g. "make". But this tool ignores "$FileDir$" variable. So your "make" program will always run in home dir (or the dir where CLion was launched from).

You can hard-code path and run make, in such case it works beautifully. And gcc errors are clickable, you can jump to file:line.

 

So the main issue: you need to do those 6 clicks and you need to create separate target with hard-coded path for all you applications.

Ideally I would love CLion to allow specifying work dir of custom build tool inside Run Configuration.

评论操作 固定链接

Hello!

Custom build targets are intended exactly for your scenario - https://www.jetbrains.com/help/clion/custom-build-targets.html.

Also instead of creating a fake CMakeLists.txt file, you can create a compilation database for your project and open it in CLion - https://www.jetbrains.com/help/clion/compilation-database.html.

0
评论操作 固定链接

Anna, I am sorry, have you read my question?  Let me re-phrase it: I use Custom build targets which is created exactly with instruction by your link. It works fine to "rebuilding whole project". The issue is: "it does not work to rebuild part of project". There is no way to pass current run program to build toolchain. The workaround "create separate external build tool" for every sub-dir of my project is insane, because it requires lots amount of time.

 

> Also instead of creating a fake CMakeLists.txt file, you can create a compilation database

It does not matter: fake CMakeLists.txt or fake compilation_database.json. Is it a matter of preference. I use both methods, I like cmake much more because it allows me to manually fine tune CLion.

0
评论操作 固定链接

Sorry for the misunderstanding. Indeed Custom build targets might not be very convenient. Feel free to create an issue with your suggestions in our tracker: https://youtrack.jetbrains.com/issues/CPP.

>This allows you to enter custom command, e.g. "make". But this tool ignores "$FileDir$" variable. So your "make" program will always run in home dir (or the dir where CLion was launched from).

You can use the $FileDir$ macro in the Working directory field:

>I use both methods, I like cmake much more

Since you use CMake, you can try using the add_custom_target CMake command - https://cmake.org/cmake/help/latest/command/add_custom_target.html

0
评论操作 固定链接

> this tool ignores "$FileDir$" variable

> You can use the $FileDir$ macro in the Working directory field

 

:)

0
评论操作 固定链接

> Feel free to create an issue with your suggestions in our tracker: https://youtrack.jetbrains.com/issues/CPP.

haha looks like there are already many tickets about custom build tools, and they dated since 2016

This one is particularly about custom build tool ignoring all macros

And this one is abusive but kind of true that custom build tools are extremely badly designed

 

Anyway, I raise my ticket: https://youtrack.jetbrains.com/issue/CPP-29587/Allow-passing-parameters-to-custom-build-tool

0

请先登录再写评论。