我的CMakeLists.txt
文件的相关片段:
add_executable(hello main.cpp)
set(helloCompileOptions -Wall -Wextra -O3 -Wno-narrowing -ffast-math -march=native)
target_compile_options(hello PRIVATE ${helloCompileOptions})
target_compile_features(hello PUBLIC cxx_std_23)
add_compile_definitions(COMPILE_OPTIONS="${helloCompileOptions}")
字符串
会产生这些编译错误:
[build] <command line>:1:9: error: macro name must be an identifier
[build] 1 | #define -O3 1
[build] | ^
[build] <command line>:2:9: error: macro name must be an identifier
[build] 2 | #define -Wextra 1
[build] | ^
...
型
我应该如何处理helloCompileOptions
列表,使它能够编译并作为字符串提供给我的C++代码?
1条答案
按热度按时间pb3skfrl1#
使用CMake字符串处理:
字符串
使这条线:
型
生产:
型