CMake从生成器表达式中删除转义字符 [英] CMake remove escape character from generator expresion
问题描述
我有一个生成器表达式 GEN_EXPR_INCLUDE_PATHS
,其中提供了要包含的目录列表.目标是通过 add_custom_command
将作为编译器选项直接传递给此列表:
I have the generator expression GEN_EXPR_INCLUDE_PATHS
that provides a list of the directories to include.
The goal is to pass this list directly as compiler option via add_custom_command
:
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/${HEADER_FILE_NAME}.gch
DEPENDS ${HEADER_FILE} IMPLICIT_DEPENDS CXX ${HEADER_FILE}
COMMAND ${CMAKE_CXX_COMPILER}
${FLAGS}
${HEADER_INCLUDE_PATHS}
${gccGarbageCollectorOpts}
-c ${HEADER_FILE} -o
${CMAKE_BINARY_DIR}/${HEADER_FILE_NAME}.gch
)
HEADER_INCLUDE_PATHS在生成器表达式之后:
Where HEADER_INCLUDE_PATHS is following generator expression:
$<1:-I$<JOIN:$<TARGET_PROPERTY:Some_Target,INTERFACE_INCLUDE_DIRECTORIES>, -I>>
仅仅是因为 Some_Target
的 INTERFACE_INCLUDE_DIRECTORIES
被接收为生成器表达式.
Just because the INTERFACE_INCLUDE_DIRECTORIES
of Some_Target
is received as generator expression.
但是cmake在空格之前添加了转义字符,由于这些额外的字符,gcc失败了.
But cmake adds escape chars before spaces, and gcc fails due to these extra chars.
有可能对此做些什么吗?我将为您提供任何支持.
Is it possible to do something with it? I'll be appriciate for any support.
推荐答案
add_custom_command
接受COMMAND参数作为列表.在CMake中,列表是一个字符串,其元素用分号分隔,因此应该使用分号而不是空格来连接.
add_custom_command
accepts COMMAND parameters as a list. In CMake a list is a string which elements are separated by semicolon, so it is semicolon which should be used for joining, not a space.
此外,对于正确分割的包含分号的字符串, add_custom_command
需要 COMMAND_EXPAND_LISTS
关键字.
Also, for correctly split semicolon-containing strings, add_custom_command
needs COMMAND_EXPAND_LISTS
keyword.
set(HEADER_INCLUDE_PATHS -I$<JOIN:$<TARGET_PROPERTY:mylib,INTERFACE_INCLUDE_DIRECTORIES>,;-I>)
add_custom_command(
...
COMMAND ${CMAKE_CXX_COMPILER}
...
"${HEADER_INCLUDE_PATHS}" # Double quotes are important!
...
COMMAND_EXPAND_LISTS # This option is important too
)
实际上,是一个包含空格的包含目录连接的示例
Actually, an example with a space-separated join of include directories
-I$<JOIN:$<TARGET_PROPERTY:INCLUDE_DIRECTORIES>, -I>
在 CMake文档本身.不确定他们对本示例的意图.
is provided in CMake documentation itself. Not sure about their intention for this example.
这篇关于CMake从生成器表达式中删除转义字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!