[CMake] Generated source files and dependencies(+) (Wojciech Migda)

Clinton Stimpson clinton at elemtech.com
Wed Sep 9 10:55:58 EDT 2009


On 09/09/2009 01:15 AM, Wojciech Migda wrote:
> Użytkownik "Clinton Stimpson"  napisał(a):
>
>> From: "Clinton Stimpson"
>> Subject: Re: [CMake] Generated source files and dependencies(+) (Wojciech Migda)
>> To: cmake at cmake.org
>>
>> On Tuesday 08 September 2009 02:14:45 pm Wojciech Migda wrote:
>>
>>>> Why not include it in the foo target, instead of making a new
>>>>
>>> a_h_gen target and doing extra dependencies manually?
>>>
>>> Firstly, we have hundred of source files which may indirectly depend
>>> generated source files, so we want such information to be covered by
>>> cmake dependency scanner itself - the problem is that there is no link
>>> between the library target and the header target.
>>>
>> That's why I suggested
>> ADD_LIBRARY(foo STATIC a.c ${CMAKE_CURRENT_BINARY_DIR}/a.h)
>>
>> It creates the generated headers for foo, then does the dependency
>> scanning
>> for foo, then compiles files.
>>
>> Here's what I got:
>> $ make
>> [ 50%] Generating a.h
>> Scanning dependencies of target foo
>> [100%] Building C object CMakeFiles/foo.dir/a.o
>> Linking C static library libfoo.a
>>
>> If that doesn't work for your case, can you be more specific on why it
>> doesn't?
>>
>>
> hi, your proposal suggests implicit addition of dependency on a.h for the library. We have tens of libraries, some of which might need dependency on a.h, some might not.
Then use target_link_libraries() / add_dependency() between libraries, 
so foo gets built before.
>   If we add this dependency on those which do not need it then they will be rebuilt unnecesarilly if the a.txt changes.
>
Yeah, you should only add a.h to one library/target, and let the others 
depend on it.
> What I'd like to see is cmake take care of the dependencies in a way that when I type 'make foo' and a.txt is changed, then a.h would be regenerated/created and foo rebuilt with new a.h. I guess cmake has got all necessary information to convey such operation, since it does scanning of dependencies on a.c to know its dependency on a.h, it knows that there is a rule for a.h generation, so why not combine the two automaticaly and make it work together ?
>

And be sure your add_custom_command() has the DEPENDS option to depend 
on a.txt, so a.h will regenerate when a.txt changes.

The dependency scanning will pick up a.h for other targets/libraries, 
even if they are in different directories.

Clint



More information about the CMake mailing list