exporting target sources?

This is for custom build systems.

I have sources that I need to prepare from one build system to another for reuse. Unfortunately, products from builds are incompatible to each other, meaning that each needs to build its own from sources.

My thought is to copy the sources to an install location and create a custom export function which generates a library from the project replacing each source location from the project with its install location. The exported file could then be included by another project.

Sources can become complex, though. I still don’t know how many different types of sources there will be (at least two for now) and each file has a set of properties that need to be exported.

I am starting to think that I should instead simply generate a add_subdirectory() instruction to the source path and install it on a location I can include it using find_package().

The generated library is understood and handled by the importing project.

Thoughts?

I think you want an $<BUILD_INTERFACE> and $<INSTALL_INTERFACE> split. I would do something like this:

target_sources(mytgt
  INTERFACE
    "$<BUILD_INTERFACE:in/source/path/source.xyz>"
    "$<INSTALL_INTERFACE:${source_destination}/path/to/source.xyz>")
install(
  FILES in/source/path/source.xyz
  DESTINATION "${source_destination}/path/to/source")
1 Like

Hrm. This does make it more complicated. You’ll need some way to write such a file yourself then include it from your config.cmake.