[CMake] Question about add_custom_command

Michael Wild themiwi at gmail.com
Fri Sep 10 10:55:35 EDT 2010


On 10. Sep, 2010, at 15:16 , Ingolf Steinbach wrote:

> 2010/9/10 Michael Wild <themiwi at gmail.com>:
>> 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)
> 
> Does this also create dependencies on the multitude of header files
> included by the .c files in SRCS (which would probably be desired in
> case of the OP)?
> 
> Ingolf

No, it will not. But usually you have anyways something like:

set(SRCS a.c b.c c.h d.c e.c)
set(HDRS a.h b.h c.h d.h e.h)

add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/f.c
 COMMAND ...
 DEPENDS ${SRCS} ${HDRS}
 COMMENT "Generating f.c"
 VERBATIM)

list(SRCS APPEND ${CMAKE_BINARY_DIR}/f.c)

add_executable(foo ${SRCS} ${HDRS})

You want an explicit list of header files because otherwise they won't show up in your IDE. Also, for libraries you often do:

add_library(foo ${SRCS} ${HDRS})

set_targets_properties(foo PROPERTIES
  FRAMEWORK TRUE
  PUBLIC_HEADER "${HDRS}")

install(TARGETS foo EXPORT Foo-exports
  RUNTIME DESTINATION bin
  LIBRARY DESTINATION lib
  ARCHIVE DESTINATION lib
  PUBLIC_HEADER DESTINATION include)

which has the added advantage of automatically installing the headers that belong to the target and also works automagically if you want to build foo as a framework on Mac OS X.

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/8e1ae3d2/attachment.pgp>


More information about the CMake mailing list