CMake在构建之前使用外部项目库

时间:2017-10-03 14:39:08

标签: android c++ c

我正在构建音频播放器,我需要在构建音频目标之前构建/提取FMOD。这是CMakeLists.txt

cmake_minimum_required(VERSION 3.4.1)

# Setup GNU/Unix make
set(PREBUILT_ARCH "windows-x86_64")
set(UNIX_MAKE_PROGRAM ${ANDROID_NDK}/prebuilt/${PREBUILT_ARCH}/bin/make)
set(MAKEFILE_FORMAT "Unix Makefiles")

# taglib configuration
set(TAGLIB_VERSION 1.11.1)
set(TAGLIB_CHECKSUM "cee7be0ccfc892fa433d6c837df9522a")

# fmod configuration
set(FMOD_VERSION 11000)
set(FMOD_CHECKSUM "154308800ea4e21649b70120d999fe7a")

include(ExternalProject)

ExternalProject_Add(
    taglib
    URL ${CMAKE_CURRENT_SOURCE_DIR}/external/taglib-${TAGLIB_VERSION}.tar.gz
    URL_MD5 ${TAGLIB_CHECKSUM}
    CONFIGURE_COMMAND ${CMAKE_COMMAND}
                      ${CMAKE_CURRENT_BINARY_DIR}/taglib/src/taglib
                      -DCMAKE_SYSTEM_NAME=Android
                      -DCMAKE_ANDROID_API=${ANDROID_NATIVE_API_LEVEL}
                      -DCMAKE_ANDROID_ARCH_ABI=${ANDROID_ABI}
                      -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK}/build/cmake/android.toolchain.cmake
                      -GUnix\ Makefiles
                      -DCMAKE_MAKE_PROGRAM=${UNIX_MAKE_PROGRAM}
                      -DBUILD_SHARED_LIBS=ON
                      -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_SOURCE_DIR}/build/taglib/${ANDROID_ABI}

    PREFIX taglib
    INSTALL_COMMAND ${UNIX_MAKE_PROGRAM} install
)

ExternalProject_Add(
    libfmod
    URL ${CMAKE_CURRENT_SOURCE_DIR}/external/fmodstudioapi${FMOD_VERSION}android.tar.gz
    URL_MD5 ${FMOD_CHECKSUM}
    CONFIGURE_COMMAND ""
    BUILD_COMMAND ""
    INSTALL_COMMAND ${CMAKE_COMMAND} -E copy
                    ${CMAKE_CURRENT_BINARY_DIR}/libfmod/src/libfmod/api/lowlevel/lib/${ANDROID_ABI}/libfmod.so
                    ${CMAKE_CURRENT_SOURCE_DIR}/build/libfmod/${ANDROID_ABI}/libfmod.so
                    &&
                    ${CMAKE_COMMAND} -E copy
                    ${CMAKE_CURRENT_BINARY_DIR}/libfmod/src/libfmod/api/lowlevel/lib/fmod.jar
                    ${CMAKE_CURRENT_SOURCE_DIR}/build/libfmod/fmod.jar
    PREFIX libfmod
)

add_library(fmod SHARED IMPORTED)
set_target_properties(fmod PROPERTIES IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/build/libfmod/${ANDROID_ABI}/libfmod.so")

add_library(tag SHARED IMPORTED)
set_target_properties(tag PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/build/taglib/${ANDROID_ABI}/lib/libtag.so)

add_library(jni_abstract SHARED src/main/jni/jni_abstract.cpp)
add_library(audio SHARED src/main/jni/audio.c)

add_dependencies(audio fmod libfmod)

target_link_libraries(jni_abstract android log audio)
target_link_libraries(audio android log fmod)

然而,这不起作用。我怀疑CMakeLists.txt文件中的命令顺序不正确,或者我在这里遗漏了什么?

FMOD和taglib都是从互联网上下载的外部压缩tarball构建的。编译器是LLVM,目标系统是Android。

这是错误:Error:error: '../../../../build/libfmod/armeabi/libfmod.so', needed by '../../../../build/intermediates/cmake/debug/obj/armeabi/libaudio.so', missing and no known rule to make it

0 个答案:

没有答案