How to run different add_custom_command for each specific target?

215 views Asked by At

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?

1

There are 1 answers

1
Leo Abalckin On

I just have lost end ">". Thanks.