CMake:根据 CMake 生成的项目中的配置更改 Visual Studio 和 Xcode 可执行文件的名称 [英] CMake : Changing name of Visual Studio and Xcode exectuables depending on configuration in a project generated by CMake
问题描述
我需要做的是将我的可执行名称设置为
What I need to do is to setup my excecutable name to be
program-debug for debug builds and
program-release(or whatever) for other builds
我想以真正的跨平台方式来做这件事,这也是非常重要的——我想以 XCode 和 VS2008 为目标——所以当我在一种下拉列表中更改配置时,它也必须有正确的名称为了输出!我不想用其他 -D 选项重新生成 .vcproj 或 .xcodeproj(但如果找不到解决方案,我将不得不这样做)
I want to do it in a true cross-platform way and what is also very important - I want to target XCode and VS2008 - so when I change configuration in a kind of drop-down list, it must also have correct names for output! I do no want to regenerate .vcproj or .xcodeproj with other -D option (but I will have to if will not found a solution)
AFAIK cmake 变量 CMAKE_BUILD_TYPE 应该适用于基于 make 的生成器 - 在制作时间(如果我错了,请纠正我)
AFAIK cmake variable CMAKE_BUILD_TYPE should work for make-based generators - in is evaluated at make time (Correct me if I am wrong)
基本上是如何根据某些 IDE/构建系统中的配置设置目标选项(不是必要的名称).它对于整体 cmake 目标来说可能过于具体,但也许您可以提供帮助.
Basically it is how to setup target options (not nessesary name) depending on configuration in some IDEs/build system. It can be too specific for overall cmake goals, but maybe you can help.
非常感谢!
推荐答案
查看目标属性:其中之一是 OUTPUT_NAME 和 OUTPUT_NAME_<配置>.可以为每个配置类型(Debug、Release、MinSizeRel 等)设置最后一个.您可以使用 set_target_properties,例如:
Take a look at the list of target properties: One of those is the OUTPUT_NAME and OUTPUT_NAME_<CONFIG>. The last one can be set for each config-type (Debug, Release, MinSizeRel, etc.) You can set them on your program with set_target_properties, e.g.:
project( YourProject )
add_executable( myprogram ${YourSources} )
set_target_properties( myprogram PROPERTIES OUTPUT_NAME_DEBUG program-debug )
set_target_properties( myprogram PROPERTIES OUTPUT_NAME_RELEASE program-release )
注意你需要设置RUNTIME_OUTPUT_NAME_
Take care that you need to set RUNTIME_OUTPUT_NAME_<CONFIG> and/or LIBRARY_OUTPUT_NAME_<CONFIG> as well in some cases.
这篇关于CMake:根据 CMake 生成的项目中的配置更改 Visual Studio 和 Xcode 可执行文件的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!