简体   繁体   中英

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

which is a pull request from here: https://github.com/larsch/cmake-precompiled-header

While doing so, I run into an error on line 22 of the export_all_flags function:

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?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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