QtCreator is failing to run CMake after updating - cmake

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.

Related

Can Kdevelop 5.0 still load existing external cmake project

I know that KDevelop 4 was able to import CMake projects (hand written CMakeLists.txt not generated by KDevelop) ... but now after I installed ubuntu 18.04 it seems this is not possible anymore (the Project > Open/Import Project dialog simply refuse take CMakeLists.txt when I click on it )? Or I miss something?
I tried to run cmake .. -DCMAKE_EXPORT_COMPILE_COMMANDS
as described here but it refuse with error message:
prokop#s2-041:~/git/SimpleSimulationEngine/cpp/Build$ cmake .. -DCMAKE_EXPORT_COMPILE_COMMANDS
Parse error in command line argument: -DCMAKE_EXPORT_COMPILE_COMMANDS
Should be: VAR:type=value
CMake Error: No cmake script provided.
CMake Error: Problem processing arguments. Aborting.
EDIT
OK, so according to the advice below I run
cmake .. -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
and now it generate compile_commands.json but I still cannot open it with KDevelope ... the Import Project dialog still shows everything gray and inactive (see screenshots below). Not sure if it matters that I run KDevelop under xubuntu 18.04 LTS (not Kubuntu) and Gnome-Flashback Desktop environment.
This should still work in KDevelop 5. There's no need to run cmake -DCMAKE_EXPORT_COMPILE_COMMANDS .., KDevelop will do it for you.
The version of KDevelop packaged in Ubuntu 18.04 is rather old and has many known bugs, please try the 5.4.2 AppImage and see if that resolves your problem.
You should put the path to your source (top-level CMakeLists.txt file) at the end of your command, after any options.
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..
Here is the command line syntax documentation.
Edit: As Tsyvarev points out, CMake specifically complains about your -D syntax, which is missing the assignment to ON.

CMake Error: cmake don't find source directory or CMakeLists.txt (installing Ogre3D)

so I've tried to use the cmake on ogre to install it but every time I use the command in the directory build :
cmake ..
I've got this error which show up :
CMake Error: The source directory "/home/.../TPs/ogre" does not exist.
Specify --help for usage, or press the help button on the CMake GUI.
and after doing :
cmake .. -DCMAKE_MODULE_PATH=/usr/share/OGRE/cmake/modules/
the error transformed in :
CMake Error: The source directory "/home/.../TPs/ogre" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.
although it got a CMakeLists.txt.
I've got cmake 2.8.XXX version and python 2.7.XXX, I've tried to use cmake-gui but it also gave me an error about the CMakeCache ...
So do you have any advice?
EDIT : Ok it works, moral of the story, even if you strongly want it, don't ever put '\' in folder names !
Be sure you have activated your virtual env. If you are not, then delete previus build folder. Activate virtual env you want. Make new build folder inside opencv. Then execute cmake.

Why qtcreator does not store my CMake command line?

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 ;)

Cmake Error: could not load cache

I'm using Cmake to try to build a project for Eclipse. When I try running Cmake, I get the following error:
Error: could not load cache
Error: Batch build stopped due to Eclipse CDT4 - Unix Makefiles error.
---- Time Elapsed: 3 secs ----
Error: could not load cache
Error: Batch build stopped due to Eclipse CDT4 - Unix Makefiles error.
I'm completely stumped on what might be causing this. I know that I'm running Cmake in the correct directory and the CMakeCache.txt file is present. Could someone point me in the right direction to solve this?
If you are using the CLion, you can use File---"Reload CMake Project".
I meet this problem after using git force pull, and Reload CMake Project solves it.
Remove the CMakeCache.txt and try again. You probably had a bad cmake setup.
I have faced the same problem and solved it using the terminal.
Delete the cached/configurations files as we will get them again.
To configure the project run cmake .
Build the project using cmake --build .
run cmake --configure . it should generate required files.
I ran into this recently using JetBrains CLion and the above instructions were helpful but not directly, I was able to reload the project using the "cog" drop down in the CMake tab:
If you are absolutely positive that you are running the build command from the binary directory, this error probably means that you have had an issue during the configuration/generation step that you should have ran before trying the build. You can try to configure again to check (cmake your-build-dir)
I would advise running the Gui and trying to load the cache to see if you get a more explicit error (although I doubt it).
Another possibility would be to try to create a new clean build directory and take it from there.
In your example Eclipse must run something like
cmake --build folder_name --target all
and I opt that the *folder_name* is bad in this case. You probably messed something up in Eclipse.
For me it helps to select CMake tab (next to Run, TODO) in CLion. Then click the Reload CMakeProject button.
I got this error on Windows WSL with ubuntu
~/tmp/cmake$ cmake --build ./build
Error: could not load cache
I was able to fix the above error by running the following cmds in order:
% cmake -S . -B ./build
% cmake --build ./build
The above solution was derived from this post.
If you are using Visual Studio 2019, close Visual Studio, delete .vs and out folders then rebuild your project.
I removed the .cxx and other ide-generated files to the recycle.bin, except app.iml. Then I restarted Android Studio, and eventually it worked fine.
The solution that worked for me using VisualStudio 2017 was choosing:
CMake --> Cache --> Generate (from the top menu)
Apart from the already given answers, it might be due to the wrong commands or in wrong order.
To be precise, for me, it was due to
cmake -B build -G Ninja
cmake --build .
The "cmake --build ." command will throw the Could Not Load Cache error.
The problem is the build directory is given as '.' which doesn't have the cache or whatever files cmake generates, so correct command was 'cmake --build build'... and fixed !
There maybe trillion other ways but my solution was this.
For eg, it happened with the repo -> https://github.com/adi-g15/worldlinesim, though may show the same for other repos too.
For Ubuntu users, provide the source code open-pose path in the CMake-GUI.
P.S I had this issue and my path was not set there.
Most probably the issue is you have not wrote the correct name of the Visual Studio version you have installed during the build file preparation:
cmake .. -G "Visual Studio 16 2019" (note if you have VS 2016 you should change in in there)
The most realistic answer and personal experienced answer is
If you are using Clion and building files with IDE
And getting the error Cmake Error: could not load cache
Because you have accidentally deleted the cache file (like me: permanently and cant get back) or there is other problems or other problems
Then do this:
Run -> Clean
Run -> Build
And your project will be working all fine
cmake -B ./build(dest dir)
cmake --build ./build(

Is there a way to get errors when a CMake command fails?

I am writing a script and started working with the install command (for copying files) and it is not working. CMake configure/generate does not show any errors (i.e. it does not stop and no warnings/errors show related to this command) and the command does not seem to be working, because I don't see any files being copied.
Since I am new, I am wondering:
How can I tell that install failed (perhaps the source directory was wrong, or the destination directory was wrong)? It appears to be failing silently.
Are there error codes I can check to see what went wrong?
When is install called? When I click configure? Or when the project is built?
I am on Windows.
To the general question, there are a number of ways to get more verbose output from CMake - I just learned a third for gnarly errors:
to debug CMake recipes, I like using the message command and you can even iterate over directories and issue messages*
e.g. message( STATUS "SQLITE3_LIB: ${SQLITE3_LIB} SQLITE3_PATH: ${SQLITE3_PATH}") # prints SQLITE3_LIB and SQLITE3_PATH variables
perform verbose builds to troubleshoot your build itself
run make VERBOSE=1 (with make, ninja -v with ninja, etc.) to help you troubleshoot the process, such as cmake -DYOUR_OPTION="insert values" ~/path/to/files/ && make VERBOSE=1
if you ever find an inscrutable error, I just learned that we can run strace on the failing command - this can be a bit overwhelming, but can help when you have exhausted #1 and #2
I just used strace /usr/bin/cmake -E copy_directory $MY_SOURCE_PATH $MY_DEST_PATH to try to understand why a copy was failing
*I have used DLRdave's answer to a different question to print out the INCLUDE_DIRS:
get_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
foreach(dir ${dirs})
message(STATUS "dir='${dir}'")
endforeach()
When you add an install command to your CMakeLists.txt, you get a new target created called "install".
In order to actually install the chosen files/targets, you need to build this install target. It's not automatically built as part of the "ALL" target.
For example, if you're using Visual Studio, the "INSTALL" target should appear in the "CMakePredefinedTargets" folder of the Solution Explorer. Just selecting this target and building it will cause the solution to be built and the selected items installed.
If any part of the build or install process fails, the notifications should then be apparent.