简体   繁体   English

如何使用CMake generator-expression为Android构建生成clang编译器标志

[英]How to generate clang compiler flag using CMake generator-expression for android build

I am trying to use the clang PrecompiledHeader for CMake found here: https://gist.github.com/leeor/316168500765cf51ae97 我正在尝试使用CMake的clang PrecompiledHeader在这里找到: https : //gist.github.com/leeor/316168500765cf51ae97

which is a pull request from here: https://github.com/larsch/cmake-precompiled-header 这是来自此处的拉取请求: https : //github.com/larsch/cmake-precompiled-header

While doing so, I run into an error on line 22 of the export_all_flags function: 这样做时,我在export_all_flags函数的第22行遇到错误:

CMake Error at cmake/Modules/android/PrecompiledHeader.cmake:22 (file):
  Error evaluating generator expression:
    $<BOOL:-isystem /Users/XXXXX/Library/Android/sdk/ndk-bundle/sysroot/usr/include/arm-linux-androideabi -D__ANDROID_API__=24 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -fno-integrated-as -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11 -frtti -fexceptions -std=c++14 -pthread -DUSE_FILE32API=1 -DCC_ENABLE_CHIPMUNK_INTEGRATION=0 -DCC_ENABLE_SCRIPT_BINDING=0 -DCC_USE_PHYSICS=0 -DCC_LUA_ENGINE_DEBUG=0 -DCC_USE_3D_PHYSICS=0 -DCC_ENABLE_BULLET_INTEGRATION=0 -DCC_USE_NAVMESH=0 -DCC_USE_TIFF=0 -DCC_USE_WEBP=0 -DRAPIDJSON_HAS_STDSTRING=1 -std=c++11 -Wno-deprecated-declarations -Wno-reorder -Wno-invalid-offsetof -fPIC -stdlib=libc++ -fsigned-char -latomic>
  $<BOOL> expression requires exactly one parameter.

What would be the proper use of CMake generator-expression to generate the right list of compiler options to be passed afterwards to clang compiler? 如何正确使用CMake generator-expression生成正确的编译器选项列表,然后将其传递给clang编译器?

NOTE: 注意:

If I replace the 如果我更换

set(_cmake_cxx_flags "$<$<BOOL:${CMAKE_CXX_FLAGS}>:$<JOIN:${CMAKE_CXX_FLAGS},\n>\n>")

with

set(_cmake_cxx_flags "$<$<JOIN:${CMAKE_CXX_FLAGS},\n>\n>")

I get a different error: 我收到另一个错误:

Error evaluating generator expression:
    $<$<JOIN:-isystem /Users/XXXXX/Library/Android/sdk/ndk-bundle/sysroot/usr/include/arm-linux-androideabi -D__ANDROID_API__=24 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -fno-integrated-as -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11 -frtti -fexceptions -std=c++14 -pthread -DUSE_FILE32API=1 -DCC_ENABLE_CHIPMUNK_INTEGRATION=0 -DCC_ENABLE_SCRIPT_BINDING=0 -DCC_USE_PHYSICS=0 -DCC_LUA_ENGINE_DEBUG=0 -DCC_USE_3D_PHYSICS=0 -DCC_ENABLE_BULLET_INTEGRATION=0 -DCC_USE_NAVMESH=0 -DCC_USE_TIFF=0 -DCC_USE_WEBP=0 -DRAPIDJSON_HAS_STDSTRING=1 -std=c++11 -Wno-deprecated-declarations -Wno-reorder -Wno-invalid-offsetof -fPIC -stdlib=libc++ -fsigned-char -latomic,
  >
  >
  Expression did not evaluate to a known generator expression

Thanks to tsyvarev comment, I was able to solve the error by using 感谢tsyvarev评论,我能够通过使用解决错误

string(REPLACE " " "\\n" _cmake_cxx_flags ${CMAKE_CXX_FLAGS})

I still have issues because clang++ is complaining about a -o option being used while trying to output several files, but at least the compiler options are working. 我仍然遇到问题,因为clang ++抱怨在尝试输出多个文件时使用了-o选项,但是至少编译器选项有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM