[CMake] Should I create IMPORTED targets for executables?

Alexander Neundorf a.neundorf-work at gmx.net
Wed Jul 25 16:10:39 EDT 2012


On Saturday 14 July 2012, Stephen Kelly wrote:
> Hi,
> 
> For Qt 5 I'm creating IMPORTED targets for all the libraries, which has
> several benefits.
> 
> I'm not sure if there are any benefits to creating IMPORTED targets for the
> executables too?

Yes, intended for crosscompiling.

add_custom_command() and add_custom_target() support using the target name of 
an executable created in the project as command (instead of using the path to 
an executable).

When crosscompiling a project, which contains code generators, you can do 
something like this:

# somewhere at the top level:
if(CMAKE_CROSSCOMPILING)
  # will find the exported executable targets exported and installed from a
  # native build of this project, which creates the imported target mycodegen
  find_package(MyProjectExecutables)
endif()

# then at the place where the code generator is built:
if(NOT CMAKE_CROSSCOMPILING)
  add_executable(mycodegen mcg.c)
endif()

...
add_custom_command(... COMMAND mycodegen arg1 arg2)


Alex
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20120725/11a2af26/attachment.htm>


More information about the CMake mailing list