We are including separate repositories into a common CMake superproject (which simply add_subdirectory() each repository folder, in the correct dependency order).
The different repositories all rely on export() to ouptut a XxxTargets.cmake file, such as:
# Assumes this repository provide the 'Alpha' target
install(TARGETS Alpha EXPORT AlphaTargets)
export(EXPORT $AlphaTargets
FILE $AlphaTargets.cmake
NAMESPACE myrepo::)
Yet, this superproject approach allowed us to observe that the export does not create the file directly. We could draw this conclusion because when the generated file is include() from another repository (added later, with a subsequent add_subdirectory()), the file does not exist yet.
export() delaying the file creation?add_subdirectory()?
- Why is
export()delaying the file creation?
Because you are asking it to generate code for a particular export set, which isn't fully defined until the configure step ends. If it generated it immediately, then the behavior of export() and install(EXPORT) would be vexing and inconsistent.
- And more importantly, is there a way to force it to actually create the file before the next
add_subdirectory()?
The export(TARGETS) signature runs immediately as far as I know. But I also can't think of a single reason why you would need the generated exports file when working with add_subdirectory. The targets already exist, so there's no need to import them! If the names are different, create ALIAS targets as needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With