View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0011888CMakeCMakepublic2011-02-22 16:572011-06-06 18:25
Reporterlitghost 
Assigned ToJames Bigler 
PriorityhighSeveritymajorReproducibilityalways
StatusclosedResolutionno change required 
PlatformOSOS Version
Product VersionCMake 2.8.4 
Target VersionFixed in Version 
Summary0011888: Using external inputs to any build commands results in broken dependencies
DescriptionUsing 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.
Steps To ReproduceSee 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.
TagsNo tags attached.
Attached Filestar file icon test.tar [^] (10,240 bytes) 2011-02-22 16:57

 Relationships

  Notes
(0025554)
James Bigler (developer)
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 (reporter)
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 (developer)
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 (reporter)
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 (developer)
2011-02-23 12:25

litghost was able to get the functionality needed through existing APIs.
(0026728)
David Cole (manager)
2011-06-06 18:25

Closing resolved issues that have not been updated in more than 3 months.

 Issue History
Date Modified Username Field Change
2011-02-22 16:57 litghost New Issue
2011-02-22 16:57 litghost File Added: test.tar
2011-02-22 17:48 James Bigler Note Added: 0025554
2011-02-22 20:05 litghost Note Added: 0025556
2011-02-23 02:01 James Bigler Note Added: 0025557
2011-02-23 11:31 litghost Note Added: 0025563
2011-02-23 11:32 litghost Note Edited: 0025563
2011-02-23 12:25 James Bigler Note Added: 0025564
2011-02-23 12:25 James Bigler Status new => resolved
2011-02-23 12:25 James Bigler Resolution open => no change required
2011-02-23 12:25 James Bigler Assigned To => James Bigler
2011-06-06 18:25 David Cole Status resolved => closed
2011-06-06 18:25 David Cole Note Added: 0026728


Copyright © 2000 - 2018 MantisBT Team