[CMake] How to generate a source file with unpredictable dependency

jlh jlh at gmx.ch
Tue May 13 19:11:52 EDT 2008


jlh wrote:
> Alexander Neundorf wrote:
>> ADD_CUSTOM_TARGET(make_version_target ${CMAKE_CURRENT_SOURCE_DIR}/makeversion
>>     COMMENT "Checking version.cpp" VERBATIM)
>> SET_SOURCE_FILES_PROPERTIES(version.cpp PROPERTIES GENERATED TRUE)
>> ADD_EXECUTABLE(foo main.cpp version.cpp)
>> ADD_DEPENDENCIES(foo make_version_target)
> 
> This seems to work, thanks.

This is probably a good idea too:

SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES version.cpp)

In a maybe unrelated matter, the percents in the output are wrong
now.  Here's the output of a build from a clean state:

$ make
[  0%] Checking version.cpp
[  3%] Built target Version
[  7%] Generating qrc_file1.cxx
    ...6 other lines omited...
[ 32%] Generating moc_file2.cxx
Scanning dependencies of target project
[ 35%] Building CXX object CMakeFiles/project.dir/fileA.o
[ 39%] Building CXX object CMakeFiles/project.dir/fileB.o
    ...15 other lines omited...
[ 96%] Building CXX object CMakeFiles/project.dir/moc_fileY.o
[100%] Building CXX object CMakeFiles/project.dir/moc_fileZ.o
[103%] Building CXX object CMakeFiles/project.dir/qrc_file1.o
Linking CXX executable project
[103%] Built target project

This is for a nothing-changed rebuild:

$ make
[  0%] Checking version.cpp
[  3%] Built target Version
[103%] Built target project

Seems like something is off by one, probably version.cpp gets
counted in one place but not in another.  Is this rather something
still wrong with my CMakeList.txt or a bug in cmake?

jlh


More information about the CMake mailing list