CMake(CLion / Android Studio)子构建失败,出现忍者

crcmnpdw  于 2022-11-11  发布在  Android
关注(0)|答案(1)|浏览(638)

我有一个软件的多个依赖项。为了使一切更容易,我们为这些依赖项创建了CMake编译文件。例如,我们有lo libfoo,所以我们创建了一个名为“make”的文件夹,并在其中放置文件“buildLibFoo.cmake”,它看起来像这样:

include(ExternalProject)

externalproject_add(LIBFOO
        URL https://github.com/lib/foo/archive/refs/tags/v1.6.0.tar.gz
        URL_MD5 58e4e09322f2d1e417469eb0987f0531b
        BUILD_IN_SOURCE 0
        PREFIX ${CMAKE_BINARY_DIR}/deps/libfoo
        SOURCE_DIR ${CMAKE_BINARY_DIR}/deps/libfoo/src/libfoo
        CONFIGURE_COMMAND
        cd <SOURCE_DIR> &&
        autoreconf -i &&
        ./configure 
        BUILD_COMMAND
        cd <SOURCE_DIR> &&
        make -j$(nproc)
        INSTALL_COMMAND ""
        )

set(LIBFOO_INCLUDE_PATH ${CMAKE_BINARY_DIR}/deps/libfoo/src/libfoo/utils)
set(LIBFOO_LIB_PATH ${CMAKE_BINARY_DIR}/deps/libfoo/src/libfoo/utils/.libs)

在我的主CMakeFiles.cmake中,我添加了以下内容:

cmake_minimum_required(VERSION 3.18.1)

project("testproject")

set (COMPILE_FLAGS "-O2")

## Need LIBFOO

if(NOT (${LIBFOO_INCLUDE_PATH} AND ${LIBFOO_LIB_PATH}))
    include(buildTSS.cmake)
    include_directories(${LIBFOO_INCLUDE_PATH})
    link_directories(${LIBFOO_LIB_PATH})
    list(APPEND DEPENDENCY_LIST "LIBFOO")
endif()

add_library( 
        testproject
        SHARED
        testproject.cpp)

target_link_libraries(testproject libfoo)    
add_dependencies(testproject ${DEPENDENCY_LIST})

如果我运行cmake CMakeLists.txtmake,编译会很好,但如果我使用Android Studio(带原生代码)或CLion,编译就失败了。

Build command failed.
Error while executing process /home/derp/Android/Sdk/cmake/3.18.1/bin/ninja with arguments {-C /home/derp/AndroidStudioProjects/testproject/app/.cxx/Debug/565m494g/arm64-v8a testproject}
ninja: Entering directory `/home/derp/AndroidStudioProjects/testproject/app/.cxx/Debug/565m494g/arm64-v8a'

ninja: error: build.ninja:178: bad $-escape (literal $ must be written as $$)

有什么想法如何使它通过IDE工作?

h79rfbju

h79rfbju1#

我在尝试使用CLion加载的现有项目中也遇到了同样的错误,该项目也是从命令行使用cmake构建的。
在我的例子中,解决方案是覆盖CLion用于生成器工具(ninja)的默认设置,并将其设置为“让CMake决定”

相关问题