如何为每个特定目标运行不同的add_custom_command?

发布于 2025-01-20 12:08:46 字数 1466 浏览 5 评论 0原文

我与Visual Studio合作,并有不同的途径用于不同的配置(调试,发行):

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

然后我想运行不同的命令< < add_custom_command(target ...>>对于那些不同的配置,如下所示:

#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)

不幸的是,Visual Studio为每种配置运行两个自定义命令。

我也尝试使用

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")

,但VS不运行此命令,并且它不使用它' T根本工作

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:
lt;TARGET_FILE:mylib> 
lt;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:
lt;TARGET_FILE:mylib> 
lt;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:
lt;TARGET_FILE:myLib> 
lt;TARGET_FILE:myLib> "
lt;IF:
lt;CONFIG:Debug>,${static_debug},
lt;CONFIG:Release>,${static_release}>"
                   COMMENT "Concatenating static libs"
                   CONFIG "
lt;IF:
lt;CONFIG:Debug>,Debug,
lt;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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

十年不长 2025-01-27 12:08:46

我只是失去了终点”。
谢谢。

I just have lost end ">".
Thanks.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文