[CMake] Adding required source files to a custom target
Attila Krasznahorkay
attila.krasznahorkay at gmail.com
Thu Dec 3 10:13:32 EST 2015
Hi Nils,
Clever. I didn't even consider specifying the SOURCES argument of the custom target with a generator expression. But it seems to work perfectly.
Thanks!
Attila
> On 03 Dec 2015, at 16:00, Nils Gladitz <nilsgladitz at gmail.com> wrote:
>
> 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
More information about the CMake
mailing list