Why qtcreator does not store my CMake command line? - cmake

I am using qtcreator 3.2.1 with CMake. I often add or remove files to my projects (i.e. to the CMakeLists.txt files) and the standard way to have these files shown in the Projects view is to run CMake from the Projects tab: no problem so far.
My problem comes in when I actually run CMake: I always have to re-enter the CMake commad line, it seems qtcreator does not store it and it is a pain in my workflow.
Anyone having the same problem as I do? Or even better, a fix?
Thanks,
Antoine.

CMake is actually running correctly within qtcreator. Forget about this question: things are straightforward in qtcreator and work as well as in plain CMake:
- at the first time you run CMake you need to enter the command line
- it is then stored into the CMakeCache
- so the next time you run CMake you can simply click on "Run CMake" with a blank command line
Easy!
PS: thanks to pmr for showing me the right direction ;)

Related

QtCreator is failing to run CMake after updating

I've been using QtCreator as my CMake IDE for a long time in Ubuntu. Today I was notified there was an update. So I updated and it looks like I can't compile CMake projects anymore.
This is the error I get when I run CMake from the IDE.
error: The source directory "/tmp/QtCreator-jNrmHx/qtc-cmake-OgPpycUx" does not appear to contain CMakeLists.txt.Specify --help for usage, or press the help button on the CMake GUI.
Any ideas what could be the problem?
I had a similar issue when setting up a new build config with QtC 4.14.
In "CMake Initial parameters", make sure that there is no empty lines, and that each option is one per line. I then deleted the temp source folder re-ran CMake.

I need to add -DCMAKE_EXPORT_COMPILE_COMMANDS=ON to cmake permanently

I use llvm for a few projects and I'd like to add this command line argument along with the path to llvm to my cmake permanently so I don't have to keep using it every time I run cmake.
I'd also prefer that cmake doesn't break when using it for projects which don't involve llvm.
Thanks
You can add it to CMakeLists.txt directly. Simply add somewhere near the top of the project:
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
Not quite what you had in mind, but other than writing a script to run the command with flags, i don't think it's possible.

Clion and CMake messages

I just started using the Clion IDE. Maybe this is written somewhere but I haven't seen it in a Google search. If I put a message() call in my CMake script, where in Clion can I see the output? These message calls are the only way that I know how to debug my CMake scripts.
Use message(WARNING ...) instead of message(...). Warnings go to stderr.
Another possible workaround:
disable "cmake auto-reload" if it is enabled
after you changed something in your cmake file, don't trigger "Reload changes"
run/build your project
When clion starts a build, it realizes the cmake files are not up-to-date and reloads them, but like other build output it is displayed inside the Messages tab.
Warning and errors are displayed, but other messages are currently suppressed. However, there is a feature request concerning this issue.
As of CLion 2016.2.2,
Build #CL-162.1967.7, CLion is displaying CMake message(STATUS) output in its Messages tool window (Alt+0) during Build (Ctrl+F9) when a project is first built after changes to CMakeLists.txt. But as noted in the other answers, this output doesn't show in CLion's CMake tool window (as many would prefer).
Update: Above I wrote that CLion "is displaying message(STATUS) output." I now find that this occurs intermittently. #Michael wrote that this happens if you skip cmake reload after modifying your cmake file, but I've found CLion sometimes does not display any CMake output in its Messages tool window even under this condition. So far I haven't discovered the exact circumstances that make CLion show CMake message(STATUS) output, will report back here when/if I do.
Big Update: CLion opens 2016.3 EAP: user-defined literals, CMake output, C11 keywords completion and more. See in particular:CMake output window: a separate I think it fixes this whole problem: CLion 2016.3 EAP adds a new tab that contains CMake command output.
Of course, this is EAP, which comes with JetBrains' caveat:
It is important to distinguish EAP from traditional pre-release
software. Please note that the quality of EAP versions may at times be
way below even usual beta standards.
So use it at your own risk, but you may judge this a risk worth taking if you need the CMake debugging.

How to find the CMake command line I used for the build?

This is what typically happens. I get source code that has cmake build scripts. I create a build subdirectory, change to it, run cmake <options> ... Depending upon the project and its dependencies I have to repeat the last step until it finds all necessary dependencies and generates makefiles. I successfully build and use the project. Few days pass, I forget about this installation. Then one day I'm trying to setup the same project on another machine and now I can't recall what exact CMake command line I used in the past to get things working.
I still have the old build directory on the old machine. Can I find the cmake command line I used in the past, by looking into some of the autogenerated files in the build directory? I was expecting CMake would just put the exact command line I used in one of these files in commented form. But if it does so, I haven't found it yet.
How can I find the original CMake command line I used?
You can't.
Original CMake command can be guessed from analysis of CMakeCache.txt
As a workaround, you could always create a simple wrapper to store the original command line used. Something along these lines:
#!/bin/bash
echo "$#" > cmake_command.log
$#

CMake Configure File Build Rule

I'm using CMake for my build system and in the project, we will have a bunch of configuration files. Some of them will just need to be copied over, some will need to be modified per computer. I'm currently using CMake's "configure_file" command to copy/replace parts of the file. This works great, and I love how I can use any variable from CMake in the configure routine.
But if you change the original file, CMake will not pick this up and you have to rerun cmake for it to configure the directory. When I run "make", I want it to pick up that I've changed the file and rerun configure.
It will also reconfigure files always, even if the file it is overwriting is newer. I want it to act like a custom target.
I think I can do this with add_custom_command, but I don't think I can run a CMake command from add_custom_command. So is there anyway to duplicate the behaviour that configure_file does in CMake?
I recently upgraded to CMake 2.8. It seems like it automatically has the exact behavior I wanted.
I do not think this has an easy answer. I see two options:
To trigger a re-run of cmake if an input changes, you might be able to make your input file depend on CMakeLists.txt.
To run a cmake command as part of and add_custom_command, there is the variable ${CMAKE_COMMAND}, which will give you the path to the running cmake. You could, as part of the configure step, generate a fragment of CMake code (that calls configure_file) that is invoked using the -P option. Either pass substitutions on the command line using -D, or write them to the CMake fragment.