[CMake] Re: Using ADD_CUSTOM_COMMAND to generate sources...

Matthew Woehlke mw_triad at users.sourceforge.net
Thu May 17 14:39:34 EDT 2007


(Ick, top-posting...)

Ken Martin wrote:
> Matthew Woehlke wrote:
>> Ok... so I see that ADD_CUSTOM_COMMAND is silently ignored if no targets 
>> depend on the OUTPUT. What is strange is that the output is #include'd 
>> from one of my source files, and I can see from looking at the generated 
>> CMakeFiles/mytarget.dir/CXX.includecache that cmake /does/ know about 
>> the dependency. So why do I still have to explicitly tell CMake about 
>> the dependency? (This occurs even if the file is output to the source 
>> directory, i.e. the full path matches what is in the CXX.includecache.)
>> 
>> Also, what is the correct way to set up the dependency? I am using:
>> 
>> set_source_files_properties(main.cpp PROPERTIES OBJECT_DEPENDS 
>> ${objects_def})
>> 
>> ...but I seem to recall someone saying that this is deprecated?
>
> Well CMake does not /really/ know about the dependency :) Because the
> dependency is done through #include in the source code it is not known at
> CMake Configure/Generate time. Dependency analysis of source code is done at
> build time. For "make" based builds CMake does this during the build process
> (because someone has to) and stores the results. The reason this is delayed
> until build time is that the generated source code and possibly the
> executables that run to generate it have to be generated before we can
> inspect them for dependencies etc.

Hmm... ok, I guess that makes sense, but it's unfortunate. It would be 
nicer if CMake (additionally) did dependency analysis of existing 
sources at least to know that the ADD_CUSTOM_COMMAND is actually needed 
instead of silently stripping it.

> The typical way to setup dependencies on generated files is by adding them
> (the generated files) to the target, for example:
> 
> add_library(libname src1.cxx generated1.h generated1.cxx generated2.h
> generated3.h) 

Hmm... seems to work. Doesn't seem intuitive, but oh well. Thanks.

-- 
Matthew
/bin/sh -- still Bourne on Solaris (and still not POSIX compliant)



More information about the CMake mailing list