cmake:使用多个输出配置 [英] cmake: Working with multiple output configurations

查看:216
本文介绍了cmake:使用多个输出配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我忙于将我的构建过程从msbuild移植到cmake,以便更好地处理gcc工具链(对于我正在做的一些数字东西,它会生成更快的代码)。



现在,我想cmake生成输出的几个版本,像一个版本sse2,另一个x64,等等。然而,如果你只是有一堆标志(比如说,sse2_enable和platform),然后根据这些平台生成一个输出,cmake似乎工作最自然。



使用这种多输出配置的最佳方式是什么?直觉上,我想迭代大量的标志组合,并为每个组合重新运行相同的CMakeLists.txt文件 - 但当然,你不能在 CMakeLists.txt文件中表达 (AFAIK)。

解决方案

这里没有太多的活动,所以我自己提出了一个可行的解决方案。这可能不太理想,所以如果你有一个更好的主意,请添加它!



现在,很难重复的构建配置在cmake,因为cmake的关键变量,因此,例如,这意味着如果你做 include_directories(X),X目录将保留在包含列表中,即使函数退出后。 p>

目录有范围 - 虽然通常每个输入目录对应一个输出目录,您可以有多个输出目录。



所以,我的解决方案如下所示:

  project(FooAllConfigs)

set(FooVar 2)
set(FooAnotherVar b)
add_subdirectory(project_dirout-2b)
set(FooVar 5)
set(FooAnotherVar c)
add_subdirectory(project_dirout-5c)
set(FooVar 3)
set(FooAnotherVar b)
add_subdirectory(project_dirout-3b)
set(FooVar 3)
set(FooAnotherVar c)
add_subdirectory(project_dirout-3c)

然后,正常的项目dir包含一个 CMakeLists.txt 文件,该代码用于设置相应的包含和编译器选项,给定全局变量在 FooAllConfigs 项目中,它还确定附加到所有构建输出的构建后缀 - 任何间接包括的输出(例如由 add_executable 生成)必须具有唯一的名称。



这对我很好。


I'm busy porting my build process from msbuild to cmake, to better be able to deal with the gcc toolchain (which generates much faster code for some of the numeric stuff I'm doing).

Now, I'd like cmake to generate several versions of the output, stuff like one version with sse2, another with x64, and so on. However, cmake seems to work most naturally if you simply have a bunch of flags (say, "sse2_enable", and "platform") and then generate one output based on those platforms.

What's the best way to work with multiple output configurations like this? Intuitively, I'd like to iterate over a large number of flag combinations and rerun the same CMakeLists.txt files for each combination - but of course, you can't express that within the CMakeLists.txt files (AFAIK).

解决方案

There hasn't been much activity here, so I've come up with a workable solution myself. It's probably not ideal, so if you have a better idea, please do add it!

Now, it's hard to iterate over build configs in cmake because cmake's crucial variables don't live in function scope - so, for instance, that means if you do include_directories(X) the X directory will remain in the include list even after the function exits.

Directories do have scope - and while normally each input directory corresponds to one output directory, you can have multiple output directories.

So, my solution looks like this:

project(FooAllConfigs)

set(FooVar 2)
set(FooAnotherVar b)
add_subdirectory("project_dir" "out-2b")
set(FooVar 5)
set(FooAnotherVar c)
add_subdirectory("project_dir" "out-5c")
set(FooVar 3)
set(FooAnotherVar b)
add_subdirectory("project_dir" "out-3b")
set(FooVar 3)
set(FooAnotherVar c)
add_subdirectory("project_dir" "out-3c")

The normal project dir then contains a CMakeLists.txt file with code to set up the appropriate includes and compiler options given the global variables set in the FooAllConfigs project, and it also determines a build suffix that's appended to all build outputs - any even indirectly included output (e.g. as generated by add_executable) must have a unique name.

This works fine for me.

这篇关于cmake:使用多个输出配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆