Cmake(Clion / Android Studio)子构建失败了

发布于 2025-01-23 02:09:53 字数 2013 浏览 0 评论 0原文

我有多个软件的依赖关系。为了使一切变得更容易,我们为这些依赖项制造了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,则该编译罚款。这是Android Studio中的一个例子。

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使其发挥作用?

I have multiple dependencies for a piece of software. To make everything easier, we made CMake build files for these dependencies. For example, we have lo libfoo, so we make a folder called "make", and in there put the file "buildLibFoo.cmake", which looks like this:

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)

In my primary CMakeFiles.cmake I add the following:

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})

While the compiles fine if I run cmake CMakeLists.txt and make, it fails to do so if I use Android Studio (with native code) or CLion. Here is an example in Android Studio.

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 $)

Any ideas how to make it work through the IDE?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

帅哥哥的热头脑 2025-01-30 02:09:54

我遇到了一个相同的错误,对于一个现有的项目,我试图加载clion,该项目也使用命令行使用cmake进行了良好的构建。

在我的情况下,解决方案是覆盖发电机工具(ninja)的默认设置,并将其设置为“让cmake决定”

“ build> build> cmake> cmake -set Generator down down to cmake cmake decak decake'>

I ran into this same error for an existing project I was trying to load with CLion that also built fine using cmake from the command line.

In my case the solution was to override the default setting CLion uses for the generator tool (ninja) and set it to the "Let CMake decide"

Screen shot of CLion preferences > Build > CMake - set generator drop down to Let CMake decide

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文