MantisBT - CMake
View Issue Details
0008778CMakeCMakepublic2009-03-22 18:532016-06-10 14:30
tron_thomas 
Bill Hoffman 
normalminoralways
closedmoved 
CMake-2-6 
 
0008778: Clean does not remove out of source generated files
I am using cxxtest for unit testing in a project that is configured with CMake. The configuration contains the following macro for generating the unit test target:

# Defines a macro that creates a cxxtest unit test application
# Name - the base name of the unit test
macro(AddCxxTest Name)
    # Specify the directory to place the generated, out of source cxxtest
    # runner file
    set(TestRunnerDirectory ${BuildPath}/${Name}Source)

    # Specify the fully qualified path the source code file for the cxxtest
    # runner
    set(TestRunner ${TestRunnerDirectory}/${Name}.cpp)
    
    # Add the command target that will generate the test runner source file
    add_custom_command(OUTPUT ${TestRunner}
        COMMAND ${CMAKE_COMMAND} -E make_directory ${TestRunnerDirectory}
        COMMAND ${PERL_EXECUTABLE} ${CxxTestGen} ${CxxTestGenFlags}
            -o ${TestRunner} ${ARGN}
        DEPENDS ${ARGN}
        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

    # Create the unit test application target
    add_executable(${Name} ${TestRunner} ${ARGN})

    set(CompileFlags "-I${CxxTestDirectory}")
    
    # Configure the test target to successfully find cxxtest header files
    set_target_properties(${Name} PROPERTIES COMPILE_FLAGS ${CompileFlags})

    # Make sure the unit test is built before all the tests are run
    add_dependencies(TestAll ${Name})
endmacro(AddCxxTest)

This macro creates the C++ file generated by the cxxtest test harness as an out of source file. When a new test is added, this file needs to be regenerated to pick up the test. When I attempt to clean the unit test target in Xcode on Mac OS X, the generated unit test C++ file does not get deleted. This is in conflict with what is stated in the CMake FAQ which states:

  Running "make clean" does not remove custom command outputs. Why?

In CMake 2.2 and higher custom command outputs should be removed by make clean. Make sure you are using at least this version. Prior to CMake 2.2 custom command outputs were not automatically added to the list of files to clean. In CMake 2.0 the developer can specify a list of files to be deleted. This can be done using SET_DIRECTORY_PROPERTIES setting property ADDITIONAL_MAKE_CLEAN_FILES to the list of files.

We however strongly recommend using an "out-of-source" build which never writes any files to the source tree. Using a separate source and build tree greatly reduces the need for "make clean" and "make distclean" targets to clean away files that differ between builds.


According to the FAQ, since the file was created with a custom command as an out of source file, the generated file should be deleted during a clean, yet the file doesn't get deleted.

No tags attached.
zip TestRunner.zip (72,459) 2009-03-23 23:39
https://public.kitware.com/Bug/file/2138/TestRunner.zip
Issue History
2009-03-22 18:53tron_thomasNew Issue
2009-03-22 21:50Bill HoffmanNote Added: 0015749
2009-03-22 21:51Bill HoffmanStatusnew => assigned
2009-03-22 21:51Bill HoffmanAssigned To => Bill Hoffman
2009-03-23 23:39tron_thomasFile Added: TestRunner.zip
2009-03-23 23:40tron_thomasNote Added: 0015780
2010-08-29 01:35Kovarththanan RajaratnamCategoryCCMake => CMake
2016-06-10 14:27Kitware RobotNote Added: 0041525
2016-06-10 14:27Kitware RobotStatusassigned => resolved
2016-06-10 14:27Kitware RobotResolutionopen => moved
2016-06-10 14:30Kitware RobotStatusresolved => closed

Notes
(0015749)
Bill Hoffman   
2009-03-22 21:50   
Should work, can you create a simple example that shows the problem.
(0015780)
tron_thomas   
2009-03-23 23:40   
I have attached a ZIP file to provide as simple of an example as I could make.

Use CMake to configure the project for Xcode
Build the project in Xcode
Clean the project in Xcode.

The out of source TestRunner.cpp generate by the cxxtest test harness will still exits after the clean operation.
(0041525)
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.