如何在 CMake 中跨多行拆分字符串? [英] How to split strings across multiple lines in CMake?
问题描述
我通常在我的项目中有一个政策,永远不要在文本文件中创建超过 80 行的行,这样它们就可以在各种编辑器中轻松编辑(你知道的).但是对于 CMake,我遇到了一个问题,即我不知道如何将一个简单的字符串分成多行以避免出现一个巨大的行.考虑这个基本代码:
I usually have a policy in my project, to never create lines in text files that exceed a line length of 80, so they are easily editable in all kinds of editors (you know the deal). But with CMake I get the problem that I do not know how to split a simple string into multiple lines to avoid one huge line. Consider this basic code:
set(MYPROJ_VERSION_MAJOR "1")
set(MYPROJ_VERSION_MINOR "0")
set(MYPROJ_VERSION_PATCH "0")
set(MYPROJ_VERSION_EXTRA "rc1")
set(MYPROJ_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}-${VERSION_EXTRA}")
它已经超过了 80 列的限制.那么如何将 CMake 中的一行分成多行而不变得冗长(多个 list(APPEND ...)
或类似)?
It already exceeds the 80 column limit. So how do I break a line in CMake into multiple lines without getting to verbose (multiple list(APPEND ...)
or the like)?
推荐答案
CMake 3.0 及更新版本 的更新:
可以使用 继续行.见 cmake-3.0-doc
line continuation is possible with . see cmake-3.0-doc
message("
This is the first line of a quoted argument.
In fact it is the only line but since it is long
the source code uses line continuation.
")
CMake 版本的可用性:
Debian Wheezy (2013):2.8.9
Debian Wheezy 向后移植:2.8.11
Debian 杰西 (2015):3.0.2
Ubuntu 14.04 (LTS):2.8.12
Ubuntu 15.04:3.0.2
Mac OSX:cmake-3 可通过 Homebrew 获得,Macports 和 芬克
Windows:cmake-3 可通过 Chocolatey
这篇关于如何在 CMake 中跨多行拆分字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!