Improper use of CACHE vars in DCA CMake
In many places (see here for example https://github.com/CompFUSE/DCA/blob/12c6c1279139994e8eb1656806f4fbb235f49296/cmake/dca_cuda.cmake#L10-L12 ) vars are set and made CACHE vars. This is annoying because if you compile WITH cuda, then change the option later to turn it off, the variable is not set (CACHE vars are not ovewritten unless FORCE is used), so you have to manaully edit the cache, or wipe it. Example cmake -DDCA_WITH_CUDA=ON blah blah build and test ok cmake -DDCA_WITH_CUDA=OFF blah blah
CMake Error at src/linalg/blas/CMakeLists.txt:4 (CUDA_ADD_LIBRARY):
Unknown CMake command "CUDA_ADD_LIBRARY".
cuda is still on even though you asked for it off. Same with MPI, and all the other vars that are CACHE when they should not be.
So I noticed this was the "style" when I started working on this cmake and I admit to propograting it further. So when I reconfigure I've taken to either wiping the build directory or making a new one. Do we have any legitimate reason for it other than not wanting to deal with people thinking the build is broken when it gets in a strange state from being reconfigured?
Do we have any legitimate reason for it other than not wanting to deal with people thinking the build is broken when it gets in a strange state from being reconfigured?
I'm not sure what the 'it' you refer to here is. Do you mean - "Do we have a legitimate reason for using the cache vars?" I don't think so. I will be happy to go over the cmake and clean it up if others agree that he way we're doing it is a bit annoying. Or maybe you mean, "Do we have a legitimate reason for wanting to clean it up?" - The answer is a big yes. It's very annoying to turn vars on and off and have the build go wrong. When testing all the PR's we're reviewing, I'm building locally, with cuda, without, with mpi, (and changing model, profiler etc sometimes), on every PR, to see if anything breaks.
If you can allow changing cache vars while providing defaults for unset variables, you should definitely do it!
You can change CACHE vars, by using the FORCE option, but then there's no point making them cache vars any more. I would like to make them normal vars. I have a patch for MPI/CUDA/HPX so far and I will fix the others as well.