MantisBT - CMake
View Issue Details
0011888CMakeCMakepublic2011-02-22 16:572011-06-06 18:25
litghost 
James Bigler 
highmajoralways
closedno change required 
CMake 2.8.4 
 
0011888: Using external inputs to any build commands results in broken dependencies
Using FILE(READ or variants to read in inputs to any build commands (i.e. add_definitions) results does not result in build system dependencies. There does not appear to be a way to add a dependency on the build system to external files.
See attached example.

Imagine an external command writes the "defines.txt" which is a newline separated list of definitions. I want the CMake build system to see that defines.txt is newer than the last reconfiguration and regenerate the definition list.

Steps to reproduce with example:
1. Extract attached tar
2. Run "cmake ." in the directory with the extracted files
3. Run "make" command and observe the expected error "TEST_DEFINED not defined"
4. Append TEST_DEFINED to defines.txt (echo "TEST_DEFINED" >> defines.txt)
5. Run "make" command and observe that the error has not gone away, even though the definition is now listed in defines.txt because the CMake system has not re-read "defines.txt"
6. Touch CMakeLists.txt and run make. Observe that the error has gone away because the CMake system re-read "defines.txt" during the config pass.
No tags attached.
tar test.tar (10,240) 2011-02-22 16:57
https://public.kitware.com/Bug/file/3717/test.tar
Issue History
2011-02-22 16:57litghostNew Issue
2011-02-22 16:57litghostFile Added: test.tar
2011-02-22 17:48James BiglerNote Added: 0025554
2011-02-22 20:05litghostNote Added: 0025556
2011-02-23 02:01James BiglerNote Added: 0025557
2011-02-23 11:31litghostNote Added: 0025563
2011-02-23 11:32litghostNote Edited: 0025563bug_revision_view_page.php?bugnote_id=25563#r218
2011-02-23 12:25James BiglerNote Added: 0025564
2011-02-23 12:25James BiglerStatusnew => resolved
2011-02-23 12:25James BiglerResolutionopen => no change required
2011-02-23 12:25James BiglerAssigned To => James Bigler
2011-06-06 18:25David ColeStatusresolved => closed
2011-06-06 18:25David ColeNote Added: 0026728

Notes
(0025554)
James Bigler   
2011-02-22 17:48   
For FindCUDA, I use include(myfile) to put an implicit rule to configure when myfile changes, and then I add myfile to the list of dependencies if I use add_custom_command.
(0025556)
litghost   
2011-02-22 20:05   
I cannot seem to get that to work. Could you re-work the example I gave using your idea?
(0025557)
James Bigler   
2011-02-23 02:01   
OK, so there are two different ways to get CMake to regenerate when a file has changed.

1. include the file with include(), but the file needs to be in a CMake script readable format.
2. configure a file with configure_file.

Depending on what you need, you could make defines.txt be in CMake parlance:

set(IN_DEFINES -DTEST1 -DTEST_DEFINED)

or

set(IN_DEFINES
  TEST1
  TEST_DEFINED
  )

With a foreach in the host CMakeLists.txt file to add the -D to it.

With option 2, you can simply copy the file and use it like a time stamp:

  configure_file(defines.txt
    ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/defines.txt.generate.stamp.depends
    COPYONLY
    )

This is what I added to your test case, and then it worked just fine. The idea is that whenever defines.txt changes, CMake will reconfigure and then generate the stamp file. Note that it will only write the output file if the input file has changed.

$ make
-- Configuring done
-- Generating done
-- Build files have been written to: /code/bugs/cmake/test
[100%] Built target test

$ echo "TEST_DEFINED" >> defines.txt

$ make
-- Configuring done
-- Generating done
-- Build files have been written to: /code/bugs/cmake/test
Scanning dependencies of target test
[100%] Building C object CMakeFiles/test.dir/test.c.o
Linking C executable test
[100%] Built target test

$ make
[100%] Built target test

$ touch test.c

$ make
Scanning dependencies of target test
[100%] Building C object CMakeFiles/test.dir/test.c.o
Linking C executable test
[100%] Built target test
(0025563)
litghost   
2011-02-23 11:31   
(edited on: 2011-02-23 11:32)
Number 2 is basically exactly what I was looking for. It worked perfectly. Thanks. This issue can be closed.

(0025564)
James Bigler   
2011-02-23 12:25   
litghost was able to get the functionality needed through existing APIs.
(0026728)
David Cole   
2011-06-06 18:25   
Closing resolved issues that have not been updated in more than 3 months.