子 CMakeLists.txt
1 2 3 4 5 |
option(BUILD_FOR_ANDROID "Build For Android" OFF) if(SYSTEM.Android AND NOT BUILD_FOR_ANDROID) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${NATIVE_LIBRARY_OUTPUT}/${ANDROID_ABI}) endif() |
父 CMakeLists.txt
1 2 |
set(BUILD_FOR_ANDROID ON) add_subdirectory(${CHILD_ROOT_DIR}/ ${CMAKE_CURRENT_SOURCE_DIR}/build) |
执行如下命令的时候:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
/Users/xxxx/Library/Android/sdk/cmake/3.6.4111459/bin/cmake --trace-expand \ -H/Users/xxxx/Source/example/demo/android/app \ -B/Users/xxxx/Source/example/demo/android/app/.externalNativeBuild/cmake/debug/arm64-v8a \ -DANDROID_ABI=arm64-v8a \ -DANDROID_PLATFORM=android-21 \ -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/Users/xxxx/Source/example/demo/android/app/build/intermediates/cmake/debug/obj/arm64-v8a \ -DCMAKE_BUILD_TYPE=Debug \ -DANDROID_NDK=/Users/xxxx/Library/Android/android-ndk-r16b \ -DCMAKE_TOOLCHAIN_FILE=/Users/xxxx/Library/Android/android-ndk-r16b/build/cmake/android.toolchain.cmake \ -DCMAKE_MAKE_PROGRAM=/Users/xxxx/Library/Android/sdk/cmake/3.6.4111459/bin/ninja \ -G"Android Gradle - Ninja" \ -DANDROID_ARM_NEON=TRUE \ -DANDROID_TOOLCHAIN=gcc \ -DANDROID_PLATFORM=android-21 \ -DANDROID_STL=gnustl_shared |
会观察到生成的配置文件中 BUILD_FOR_ANDROID
不一定能生效。
需要如下配置才行:
父 CMakeLists.txt
1 2 |
set(BUILD_FOR_ANDROID ON CACHE BOOL "" FORCE) add_subdirectory(${CHILD_ROOT_DIR}/ ${CMAKE_CURRENT_SOURCE_DIR}/build) |