具有多个条目(空格?)的Cmake Generator表达式 [英] Cmake Generator expressions with multiple entries (spaces?)

查看:82
本文介绍了具有多个条目(空格?)的Cmake Generator表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(在编写此问题时,我找到了一个解决方案,所以只在记录下来,因为我确实真的需要它!)

(During writing this question I found a solution, so this just documents it, because I would really have needed it beforehand!)

我正在编写一个c ++项目,并使用cmake.

Im writing a c++ project and use cmake for it.

在我的cmake文件中,我有:

In my cmake file I have:

set(MY_DEBUG_WARNINGS "-Og -Wall"
)

# Add warnings:
add_compile_options("$<$<CONFIG:DEBUG>:${MY_DEBUG_WARNINGS}>"
"$<$<CXX_COMPILER_ID:Clang,AppleClang>:-fcolor-diagnostics>"
"$<$<CXX_COMPILER_ID:GNU>:-fdiagnostics-color>"
)

这不起作用,因为compile命令会获取多余的转义引号:

which doesn't work, because the compile command picks up extra escaped quotes:

  "/usr/bin/clang++ -I../src/Exception/include -g \"-Og -Wall\" -fcolor-diagnostics - 
  std=c++17 -o src/Exception/CMakeFiles/exception.dir/Exception.cpp.o -c 
  /home/bob/app/src/Exception/Exception.cpp",
  "file": "/home/bob/app/src/Exception/Exception.cpp"  

问题似乎出在警告中.

这个问题解决了"通过将每个值包装在自己的表达式中来解决问题,这似乎很奇怪,而且非常不切实际.有没有更简单的方法可以在生成器表达式中传递带有空格的字符串?

This question "solves" the issue by wrapping each value in its own expression, which seems weird and awfully impractical. Is there any easier way to pass a string with spaces in it in a generator expression?

如前所述,我本人找到了可以接受的解决方案,但尚未将其标记为我接受的答案,因为我不确定,这是一个很好的解决方案,而且如果我需要分号,也不会给我带来麻烦.自己选择.

As mentioned I found an acceptable solution myself but will not yet mark it as my accepted answer because I'm not sure, this is a good solution and not a hack that may bite me if I ever need semi-colons in the options themselves.

推荐答案

-Og -Wall" 是字符串,而-Og; -Wall" 是一个列表(因为列表是用分号分隔的字符串).

"-Og -Wall" is a string, whereas "-Og;-Wall" is a list (as lists are semicolon separated strings).

因此, set(my_list -Og -Wall)(无双引号)也会创建一个列表.在此处阅读所有内容.

So set(my_list -Og -Wall) (no double quotes) also creates a list. Read all about it here.

这篇关于具有多个条目(空格?)的Cmake Generator表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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