[CMake] Adding required source files to a custom target

Nils Gladitz nilsgladitz at gmail.com
Thu Dec 3 10:00:24 EST 2015


On 12/03/2015 03:47 PM, Attila Krasznahorkay wrote:
> Dear All,
>
> Is it possible to add additional source files to an already existing custom target?
>
> My project needs to generate a number of "different things", which it does by setting up many custom commands. In order to trigger the generation of everything, I currently need to set up an inconvenient number of custom targets as well. Would it be possible to attach multiple custom commands to an already existing custom target?

e.g. this nonsense example seems to work:

    cmake_minimum_required(VERSION 3.4)

    add_custom_target(foo ALL
         COMMAND ${CMAKE_COMMAND} -E echo $<TARGET_PROPERTY:foo,MY_INPUTS>
         DEPENDS "$<TARGET_PROPERTY:foo,MY_INPUTS>"
         VERBATIM
    )

    function(add_custom_input input)
         set(_output "${CMAKE_CURRENT_BINARY_DIR}/${input}.out")
         set(_input "${CMAKE_CURRENT_SOURCE_DIR}/${input}")

         add_custom_command(OUTPUT ${_output}
             COMMAND ${CMAKE_COMMAND} -E copy ${_input} ${_output}
             DEPENDS ${_input}
             VERBATIM
         )

         set_property(TARGET foo APPEND PROPERTY MY_INPUTS ${_output})
    endfunction()

    file(WRITE input1)
    add_custom_input(input1)

    file(WRITE input2)
    add_custom_input(input2)

Nils
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20151203/e09c924d/attachment.html>


More information about the CMake mailing list