Cmake 3.16+
Most of our executables ultimately depend on a target, Base
, and for Windows long-path support I’ve introduced a manifest file to the Base
sources, but this limits what I can put in that manifest.
- executable1
/ - Base
/ - Library 1
/ / - Library 2
/ / / - Base
- executable 2
/ - Library 2
/ / - Base
...
What I’d like to do is - for every target that depends on Base - automatically cause linking to executable to run a custom command on manifest.xml.in
to produce manifest-${TARGET}.xml
with some target-specific tweaks, e.g. the assemblyIdentity.name="SuperEvilMegaCorp.Engine.${TARGET}
", (* actual name).
I’ve done something like this before by crawling target trees and finding connections, but my ask is whether this is innately and explicitly possible with modern CMake?
Conceptually:
add_custom_command(
TARGET $<EXECUTABLE_TARGET>-manifest.xml
...
)
add_library(Base base.cpp $<EXECUTABLE_TARGET>-manifest.xml)
add_library(Intermediate im.cpp)
target_link_libraries(Intermediate PUBLIC Base)
add_executable(Exe main.cpp)
target_link_libraries(Exe Base Intermediate) # ends up gaining one Exe-manifest.xml generated from customizing manifest.xml.in