[IPOL discuss] 2 cmake questions

Juan Cardelino juan.cardelino at gmail.com
Mon Nov 28 12:45:23 CET 2011


> Doesn't work:
> * cmake ./        OK, creates Makefile
> * make            OK, builds the program
> * cmake clean     CMake Error: The source dir. ".../clean" does not exist.
> * make clean      OK, removes the program
> * cmake distclean CMake Error: The source dir. ".../distclean" does not exist.
> * make distclean  make: *** No rule to make target `distclean'.  Stop.
>

This should not work, see note below [1]. The intended use for cmake
is to build in a different dir than the one containing the source
code. So, lets say you have the source in ./src and you compile in
./build. You can safely do a 'rm -fr build/*' to get rid of
everything.
So with cmake you get the standard cleanup of object files,
executables and libraries, but not of the generated files.

Best regards,
                   Juan

[1] CMake does not generate a "make distclean" target. Why?
Some build trees created with GNU autotools have a "make distclean"
target that cleans the build and also removes Makefiles and other
parts of the generated build system. CMake does not generate a "make
distclean" target because CMakeLists.txt files can run scripts and
arbitrary commands; CMake has no way of tracking exactly which files
are generated as part of running CMake. Providing a distclean target
would give users the false impression that it would work as expected.
(CMake does generate a "make clean" target to remove files generated
by the compiler and linker.)
A "make distclean" target is only necessary if the user performs an
in-source build. CMake supports in-source builds, but we strongly
encourage users to adopt the notion of an out-of-source build. Using a
build tree that is separate from the source tree will prevent CMake
from generating any files in the source tree. Because CMake does not
change the source tree, there is no need for a distclean target. One
can start a fresh build by deleting the build tree or creating a
separate build tree.
(If a CMakeLists.txt uses ADD_CUSTOM_COMMAND to generate source files
in the source tree, not the build tree, then in CMake 2.2 or higher
"make clean" will remove them. See next question.)


More information about the discuss mailing list