[CMake] Question about add_custom_command
Michael Wild
themiwi at gmail.com
Fri Sep 10 07:30:00 EDT 2010
On 10. Sep, 2010, at 12:38 , David Aldrich wrote:
> Hi Michael
>
> Thanks for your help. Please see question below.
>
>> CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
>> PROJECT(GENDEP C)
>> FILE(WRITE ${CMAKE_BINARY_DIR}/g.c "void g(void){}\n")
>> ADD_CUSTOM_COMMAND(
>> OUTPUT ${CMAKE_BINARY_DIR}/f.c
>> COMMAND echo "void f(void){}" > ${CMAKE_BINARY_DIR}/f.c
>> DEPENDS ${CMAKE_BINARY_DIR}/g.c
>> VERBATIM)
>> FILE(WRITE ${CMAKE_BINARY_DIR}/main.c "int main(void){f();return 0;}\n")
>> ADD_EXECUTABLE(main main.c f.c)
>>
>> "f.c" is regenerated and, thus, "main" rebuilt if "g.c" is touched
>> although it's not incorporated in "main".
>
> In my case, the dependencies of the f.c will be all the dependencies of main. i.e. if any source file contributing to the exe changes we must first regenerate f.c.
>
> Now our executable depends on many source files. I assume you are saying that I need to add the same list of dependencies to the ADD_CUSTOM_COMMAND. Can I specify a list of files further up in CMakeLists.txt so that I only need to enumerate the list once?
>
> Regards
>
> David
set(SRCS a.c b.c d.c e.c)
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/f.c
COMMAND ...
DEPENDS ${SRCS}
COMMENT "Generating f.c"
VERBATIM)
list(APPEND SRCS ${CMAKE_BINARY_DIR}/f.c)
add_executable(main ${SRCS})
HTH
Michael
--
There is always a well-known solution to every human problem -- neat, plausible, and wrong.
H. L. Mencken
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 195 bytes
Desc: This is a digitally signed message part
URL: <http://www.cmake.org/pipermail/cmake/attachments/20100910/c09bee8b/attachment.pgp>
More information about the CMake
mailing list