MantisBT - CMake
View Issue Details
0008164CMakeCMakepublic2008-11-25 08:392016-06-10 14:30
Hugo Heden 
Bill Hoffman 
normalminoralways
closedmoved 
CMake-2-6 
 
0008164: additional_clean_files not respected if no target present in directory
It seems that

  set_directory_properties( properties additional_clean_files ... )

is not respected if no target present in the directory -- that is
'make clean' will not remove the specified "additional clean file".

$ cmake --version
cmake version 2.6-patch 2

A little test case to illustrate the issue follows. We have two
CMakeLists.txt-files, one in the root directory and one in a sub
directory. The former (src/CMakeLists.txt) is not really important,
but included here for completeness. The latter,
src/subdir/CMakeLists.txt, is where the bug appears. There is also a
file that is being installed, src/subdir/hello.txt. Invoking 'make
clean' will not clean that file unless there is an actual target
specified in src/subdir/CMakeLists.txt.

File tree:.

|-- build
|-- install
`-- src
   |-- CMakeLists.txt
   `-- subdir
       |-- CMakeLists.txt
       `-- hello.txt

--------------------------------
------- src/CMakeLists.txt:

CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
SET( CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/../install )

ADD_SUBDIRECTORY( subdir )

ADD_CUSTOM_TARGET(
 some_target
 COMMAND ${CMAKE_COMMAND} -E echo HELLO
)


--------------------------------
------- src/subdir/CMakeLists.txt:

#ADD_CUSTOM_TARGET(
# some_subdir_target
# COMMAND ${CMAKE_COMMAND} -E echo WHOHOO
#)

INSTALL(
 FILES hello.txt
 DESTINATION ./
 )

SET_DIRECTORY_PROPERTIES(
 PROPERTIES
 ADDITIONAL_MAKE_CLEAN_FILES
 ${CMAKE_INSTALL_PREFIX}/hello.txt
 )

---------------------------
---------------------------

As written above, with the target "some_subdir_target" commented out,
the ADDITIONAL_MAKE_CLEAN_FILES will not be respected - - it seems to
be sort of optimized away:

$ cd build/
$ cmake ../src
...
...
$ make install
...
$ ls ../install
hello.txt
$ make clean
$ ls ../install/
hello.txt # <--- OUCH


--------------------------------
--------------------------------

However, if the target is not commented out it will all work nicely:

--------------------------------
------- src/subdir/CMakeLists.txt:

ADD_CUSTOM_TARGET(
 some_subdir_target
 COMMAND ${CMAKE_COMMAND} -E echo WHOHOO
)

INSTALL(
 FILES hello.txt
 DESTINATION ./
 )

SET_DIRECTORY_PROPERTIES(
 PROPERTIES
 ADDITIONAL_MAKE_CLEAN_FILES
 ${CMAKE_INSTALL_PREFIX}/hello.txt
 )

--------------------------------
--------------------------------


$ cd build/
$ cmake ../src
...
...
$ make install
...
$ ls ../install
hello.txt
$ make clean
$ ls ../install/
        # <no files> -- as expected

No tags attached.
Issue History
2008-11-25 08:39Hugo HedenNew Issue
2008-11-27 06:53Hugo HedenNote Added: 0014211
2009-01-30 06:32Hugo HedenNote Added: 0014733
2009-09-14 15:15Bill HoffmanStatusnew => assigned
2009-09-14 15:15Bill HoffmanAssigned To => Bill Hoffman
2016-06-10 14:27Kitware RobotNote Added: 0041472
2016-06-10 14:27Kitware RobotStatusassigned => resolved
2016-06-10 14:27Kitware RobotResolutionopen => moved
2016-06-10 14:30Kitware RobotStatusresolved => closed

Notes
(0014211)
Hugo Heden   
2008-11-27 06:53   
Ok, apparently this behaviour is to be expected. Bill Hoffman explains (on the mailing list, regarding a different matter) [1]:

"The concept of a directory property in CMake is not one to one with the
disk directories. A directory in CMake is a directory that has a list
of targets in it. You can have a target that uses files from all sorts
of different directories."

Still,

(1) It would be nice to be able to specify "additional-clean-files" in *any* CMakeLists.txt (whether it has a target in it or not should not matter)

(2) CMake should perhaps report an error when one is trying to set a directory-property for a directory that is not actually a directory in the CMake sense..



[1] http://www.cmake.org/pipermail/cmake/2008-November/025608.html [^]
(0014733)
Hugo Heden   
2009-01-30 06:32   
Another way to see this: "A directory in the cmake sense is a directory that has a list of targets in it".

Ok, but I would like this list to be instantiated wherever there is a CMakeLists.txt, even if there is zero targets there. So any directory containing a CMakeLists.txt would count as a directory, even if there would be zero targets in it.
(0041472)
Kitware Robot   
2016-06-10 14:27   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.