Editing versus deleting CMakeCache.txt after moving directory - cmake

If CMake is re-executed after the source directory is moved, an error like this is given:
CMake Error: The current CMakeCache.txt directory /new-path/CMakeCache.txt is different than the directory /old-path where CMakeCache.txt was created. This may result in binaries being created in the wrong place. If you are not sure, reedit the CMakeCache.txt
What is the best approach to deal with this? It seems that deleting the cache works. Why might I want to edit CMakeCache.txt, rather than just delete it?

I think your best bet is indeed to delete the cache and re-create it. In fact, I tend to go further and remove the entire build tree if I need to move the source, but this is probably overkill.
The CMakeCache.txt file can be edited via the CMake GUI or by hand if you're sure what you're doing, but I find it's not usually worth the effort compared to re-running cmake from scratch. I guess if running CMake takes a significant amount of time (e.g. if you use ExternalProject_Add which could involve downloading and building a third-party resource), it may be preferable to modify the CMakeCache.txt.
This article provides a bit more detail about the CMakeCache.txt file and editing it. In particular it says:
The main reason for editing the cache would be to give CMake the location of a native library such as JPEG, or to stop it from using a native library and use a version of the library in your source tree.
CMake will not alter an existing entry in the cache file itself. If your CMakeLists.txt files change significantly, you will need to remove the relevant entries from the cache file. If you have not already hand-edited the cache file, you could just delete it before re-running CMake.

I applied below two command and worked for me.
flutter clean
flutter pub get

flutter clean + flutter pub get is the easiest solution

I ran into same error while running a CGAL code (which I had already compiled sometime ago) . All I did was create a new directory and copy the ".cpp" file there and run " CGAL_create_CMakelists " and then run cmake command.It worked this way. I don't exactly know but I think the error comes when you run the code which was already compiled and has its build files already in the folder(due to previous compiling).

Related

Completely Clear CMake Cache (Qt Creator)

I have come to this problem several times: Something on my system has changed so cmake got confused and cannot parse the project anymore.
When I just setup everything from scratch it works.
What I tried to solve the problem was following:
delete cmake cache
delete everything in the build folder
delete the cmakelist.txt.user
run cmake again -> problem still there
The only way I could solve it was to make a new build folder and set up the project from scratch, because some settings were still somewhere saved for the old build folder.
So where are those corrupted settings stored? and how can I reset them without having to change the folder??

ROS Kinetic 'catkin_make' Fails because PROJECT_NAME is set to Project

I have been using ROS Kinetic for a while, and today when I went to make a new catkin workspace following the ROS tutorials page (http://wiki.ros.org/catkin/Tutorials/create_a_workspace) I get a CMake Error stating that PROJECT_NAME is set to Project, which is invalid. I have never run into this issue with any of my other work spaces I have created.
I do not want to mess with toplevel.cmake out of fear of screwing up my other work spaces.
Any ideas why this is happening?
CMake Error at /opt/ros/kinetic/share/catkin/cmake/catkin_package.cmake:91 (message):
catkin_package() PROJECT_NAME is set to 'Project', which is not a valid
project name. You must call project() before calling catkin_package().
Thank you.
I was able to reproduce the above error you are getting. For that what I did is opened my CMakeLists.txt and commented the second line which defines the package Name, i.e., project(package_name). After that, I tried to build my package via catkin_make, but got below error(see the error inside yellow box):
Then, I tried to build the same package after uncommenting the above line. This time I was able to build my package(test, in my case) successfully, without any error.
CMakeLists.txt file contains project() as well as catkin_package() and the former function should be called before catkin_package() inside the file. So, project(package_name) is either missing from your CMakeLists.txt file or is commented.
If it is missing, then manually add it. If it is there, but commented then uncomment it.
Read more about the correct format of CMakeLists.txt file from here.
ironically, you'll be running : sudo apt-get install ros-<distro_name>-catkin to reinstall catkin because even if u clear your entire workspace the problem will persist due to some symbolic link or something broken in the package which will always result in the same error, upon reinstalling catkin it worked for me, knowing that I had the exact same issue.
Had to come answer this because I think I did the same thing OP did. Here's what happened: There are supposed to be TWO CMakeLists.txt in your project folder. One lives at ProjectName/src and should be read-only and should actually be a link to your /opt/ros/your-ros-distro/share/catkin/cmake/toplevel.cmake folder.
If you do like I did, and I'm assuming like OP did, and edit that file, and then use your superuser to overwrite that file, then you are (1) breaking all of your catkin projects, because ALL of the catkin projects link to this one file, AND you're misconfiguring this project because the CMakeLists.txt file you're supposed to modify actually exists a folder deeper, at ProjectName/src/ProjectName/. THIS is where you're supposed to put the CMakeLists.txt file that names your project, where your package.xml file is supposed to go, etc.
If you use superuser to force-overwrite the read-only CMakeLists.txt file then you're going to have a bad day. Fortunately you can fix that file by fixing the toplevel.cmake folder, which you can do by reinstalling the catkin package: sudo apt-get install --reinstall ros-indigo-catkin
And, to put this in terms of OP's question specifically - the project() needs to get named at the inner file, the ProjectName/src/ProjectName/CMakeLists.txt, because again the root file is read-only and should never be modified.

Is it possible to keep *.erl sources and *.beam output in the same directory with intellij-erlang?

I want to set up my HelloWorld intellij-erlang project with all files in the same directory so I can easily switch between IDEA and emacs/vim.
<my-project>/hello.erl
<my-project>/hello.beam
Now, if I configure the output directory to be the same as the source, hello.erl gets emptied as part of the build and the compilation fails.
I assumed it's something to do with copying resources to the output directory, so I've configured intellij-erlang to exclude *.erl from the resources with a !?*.erl pattern, but this does not have any effect, hello.erl still gets emptied before the compilation takes place.
As an experiment, I've also tried using separate src and out directories, and intellij-erlang always copies the *.erl to out irrespective of the resource patterns.
Based on all this, I would conclude that intellij-erlang cannot work with all files in the same directory. Have I missed anything?
Erlang programs should be build on standard OTP directory structure. Build tools like rebar (used by intellij) or erlang.mk build on this conventions. And so should all IDE's.
Intellij does it, just like you notice. And so does Emacs's plugin (that I use and can confirm). I would guess so does Vim's one.
So if you would like to be able to switch easily between your IDE's you should try to keep to this convetion of keeping you source files in src and compiled files in bin (and headers in include).

CMAKE for a build a simple framework

I have my mind crashing with cmake. After this answer I have tried to make a simple example and put it in github because there are a lot of file inside directories and could be boring copy everything here.
What I'd like to do is to build a simple frameworks for handling my qt/opencv/opengl experiments. What I like to have is a repository with those directories:
root*
|-apps
|---test1*
|
|-build
|-cmake*
|
|-modules
|---foo*
(The * signed directory are the ones with some cmake files like CmakeLists.txt or FindXXModule.cmake)
In modules i can write the modules (for example a module for face recognition, a module for draw a red cube in opengl, a module that contains my personal qt widget extension).
Than I need an easy way for create an application and link some modules on it. For that I thought to create a cmake directory where to put the FindXXModule.cmake and in the apps just say: find_package(XXModule).
Note that for now I don't care about installing this repository and the tree structure must be this one (so if I am in a apps/test2 I know I can refer to the cmake directory as ../../cmake or the module directory is ../../modules)
I have wrote a little example with the app named test1 that uses the module foo and i put it in a github repository.
For now I can compile the application test1 with cmake calling cmake path_to_test1_CmakeLists.txt and I am happy about that. But if I try to launch cmake path_to_root_CmakeLists.txt it does not work because the file Findfoo.cmake is read two time (and i did't be able to use some if for not reading it twice).
Then, if i run the test1 cmake a foo directory with cmake cache etc are created in root/cmake and I don't want it. I want all file cmake has to generate are in root/build directory.
So, those are my 2 question:
How create a CmakeLists.txt that can build all the apps and all the future test i will write in the modules directory
How avoid that launching cmake of a single app will create files in the cmake directory.
Sorry if my english and my idea of how cmake works are not good.. i hope it is clear.
EDIT:
One more thing. In Findfoo.cmake I have a bad hack: for adding the real CMakeLists.txt inside a modules/foo when I call the cmake from test1 I have to add a subdirectory that is not in the tree.. Maybe this kind of hack could be deleted reviewing the enteire structure..
As you say you want to put the whole directory structure into source control. This means these folder structure is same on every location where you do a checkout. So why creating the Findfoo.cmake if you have a relative path the the foo directory?
I suggest to put a CMakelists.txt file in to root that adds all subdirectories. To reduce confusion between files generated by CMake and original files, you should create a folder called ./build (or even ../build) and run CMake in that directory with the root directory as first argument. This creates all CMake generated files in the ./build directory and gives you the possibility to clean it up easily. This way of working is called out-of-source build and its highly recommended to use cmake in this way. See this question for an example.

How can I prevent Visual Studio from locking the xml documentation files in the bin directory?

My visual studio solution includes a web application and a unit test application. My web application uses log4net. I want to be able to use msbuild from the command-line to build my solution. However, whenever I build the solution from the command-line, I get build errors because it can't copy log4net.xml to the test project's bin directory.
The error message is:
"Unable to copy file '\bin\log4net.xml' to 'bin\Debug\log4net.xml'. Access to the path '\bin\log4net.xml' is denied."
It looks like Visual Studio is locking this file, but I can't figure out why it would need to. Is there a way to prevent VS from locking the XML documentation files in a project that it has loaded?
I've found the following solution:
In VS postbuild event or in NAnt/MSbuild script execute the cmd script
handle.exe -p devenv [Path to the folder with locked files] > handles.txt
FOR /F "skip=5 tokens=3,4 delims=: " %%i IN (handles.txt) DO handle -p %%i -c %%j -y
handle.exe is available here http://technet.microsoft.com/en-us/sysinternals/bb896655.aspx
first line of the script dumps to handles.txt all handles for files locked by VS
second line reads handle ids from the file and kills the handles
After the script is executed files may be removed/replaced/moved etc
If you're fine with omitting the xml & pdb files altogether from the output, you can pass /p:AllowedReferenceRelatedFileExtensions=none to msbuild on the command line.
(Thanks to related answer https://stackoverflow.com/a/8757941/251011 )
EDIT: If you also have problems with dll files having this error, I recently discovered an environment variable solution: https://stackoverflow.com/a/23069603/251011
I've had this problem with Visual Studio, too. We use NAnt instead of MSBuild, but the problem is the same. I was able to work around it by modifying the build file to ignore failures when copying xml documentation.
Note that this doesn't actually solve the original problem since the xml files are still locked, but this workaround was good enough for us since the actual content of our xml documentation doesn't change very often.
Krystan wrote:
You could drop this file into another directory and reference it from there or place code that uses it into a library and have the post build event on that copy it to its bin directory and then reference.
Our xml file locking problem is not in the projects bin directory, rather an external reference directory. We hit it when performing TortoiseSVN->Update where a new version is available. Assuming it's because VS is using the file for intellisense.
For those who hit this locking issue due to TortoiseSVN->Update, I'm currently experimenting with a pre-update hook which deletes the offending file(s) before updating (they will be restored if no update is needed), so far this seems to work (which is weird) but I haven't tested it thoroughly enough to say for sure. Will update this answer if it proves reliable.
Here's hoping MS fix it in VS 2010.
Basically don't check files into the bin folder, its a bad idea.
You could drop this file into another directory and reference it from there or place code that uses it into a library and have the post build event on that copy it to its bin directory and then reference.
Msbuild will then copy that to the webprojects bin directory for you :)
We have this exact issue with people checking in stuff to the bin directory, unless you absolutely have to bin directories should either not be checked in at all or just have .refresh files in there to avoid these sorts of locking issues.
Bit late on the reply, sorry :)