1

I work with Visual Studio and have different paths to work for different configurations (Debug, Release):

if(WIN32 )
    set(static_release ${my_lib}_release/SomeLibrary.lib)
    set(static_debug ${my_lib}_debug/SomeLibrary.lib)
endif(WIN32)

Then I want to run different commands < <add_custom_command(TARGET ...> > for those different configurations as follows:

#A command which can be applied for Debug configuration:
add_custom_command(TARGET mylib
                   POST_BUILD
                   COMMAND lib /out:$<TARGET_FILE:mylib> $<TARGET_FILE:mylib> ${static_debug}
                   COMMENT "Concatenating static libs"
                   CONFIG Debug)
#A command which can be applied for Release configuration:
add_custom_command(TARGET mylib
                   POST_BUILD
                   COMMAND lib /out:$<TARGET_FILE:mylib> $<TARGET_FILE:mylib> ${static_release}
                   COMMENT "Concatenating static libs"
                   CONFIG Release)

Unfortunately, Visual Studio runs both of those custom commands for each configuration.

I also tried to use

add_custom_command(TARGET myLib
                   POST_BUILD
                   COMMAND lib /out:$<TARGET_FILE:myLib> $<TARGET_FILE:myLib> "$<IF:$<CONFIG:Debug>,${static_debug},$<CONFIG:Release>,${static_release}>"
                   COMMENT "Concatenating static libs"
                   CONFIG "$<IF:$<CONFIG:Debug>,Debug,$<CONFIG:Release>,Release")

but VS doesn't run this command and it doesn’t work at all.

Is it possible to run only needed custom command for each configuration?

  • What is the reason of `CONFIG "$,Debug,$,Release"`? Just remove it. BTW, [add_custom_command](https://cmake.org/cmake/help/latest/command/add_custom_command.html) doesn't support `CONFIG` option at all. – Tsyvarev Apr 11 '22 at 14:23

1 Answers1

0

I just have lost end ">". Thanks.

  • 1
    Your answer could be improved by providing an example of the solution and how it helps the OP. – Tyler2P Apr 19 '22 at 17:19