Force addition of a Target specific generated source file / win32 manifests

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 to produce manifest-${TARGET}.xml with some target-specific tweaks, e.g. the"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?


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

I’m not sure CMake provides such specific functionality out of the box. What I’d do is create a helper function in a CMake module. Something like this:

    # link library
    # run custom command

Here are the docs on making a function.