[CMake] Remove a custom command added with add_custom_command(<target> POST_BUILD ...)

Kyle Edwards kyle.edwards at kitware.com
Tue Mar 5 12:58:34 EST 2019


On Tue, 2019-03-05 at 10:01 -0700, Olivier Gomez wrote:
> Hello,
> 
> I have been searching for a way to remove a custom command
> (POST_BUILD
> event) from a target in CMake but, so far, I've found nothing.
> 
> I tried to add another custom command to override the first one but
> it seems
> to append a second command. 
> I tough that could work because of the first signature of
> add_custom_command() that can take an optional argument named APPEND.
> https://cmake.org/cmake/help/v3.4/command/add_custom_command.html#gen
> erating-files
> Then, I looked for a target property that contains the POST_BUILD
> custom
> command (to erase it) but, again, I found nothing related (I listed
> every
> property using the "cmake --help-property-list" command).
> 
> 
> The context is that I configure a project using a "CMake SDK" from a
> third
> party library (custom functions that create and configure a shared
> library
> target basically).
> Until recently, I used to create those target by myself using
> standard CMake
> command.
> But now I switched to the "SDK" because it does a lot of specific
> thing
> depending on the platform (and between the current version of the SDK
> and
> all the legacy version) and I don't want to rewrite everything.
> 
> Specifically, this SDK add a custom command as a POST_BUILD event to
> run a
> tool that perform a signature on the produced library. As it is a
> proprietary tool that requires a valid licence to work, I want to
> remove
> that command in order to have a successful build even if i don't
> currently
> have a licence on my machine.
> 
> So ... is there some way to remove a custom command in CMake ? (or
> ignore
> failed command maybe)

CMake doesn't have a way to remove a custom command from a target. Your
best bet would be to either:

1) Fork the SDK for your project to remove the proprietary tool, or
2) Submit a patch upstream to add an option to disable the proprietary
tool.

Kyle


More information about the CMake mailing list