【问题标题】:android cmakelist add multi source file?android cmakelist 添加多源文件?
【发布时间】:2017-07-20 08:27:45
【问题描述】:

我使用 Android Studio 和 CMakelist 编写 NDK 项目。

但是当我想在 CMakelists.txt 中包含很多 cpp/c 文件时,我找不到一个简单的方法来轻轻地做到这一点。

我需要你的帮助。

这是我的代码的文件树示例:

Cmakelists.txt
src
|__main
     |__cpp
         |___a.cpp   // cpp file 
         |___a.h
         |___aa.c   //   c file
         |___...
         |___dirA    //  a dir
              |__b.c  // also has c file 
              |__b.h
              |__d.cpp  // and cpp file
              |__...
              |___dirB  // another dir
                   |__xxx.c
                   |__...

在我的 Cmakelist 中,我使用了

file(GLOB cpp_srcs "src/main/cpp/*.cpp")

这似乎只包含第一个目录层的cpp文件,不包含c文件和子目录的cpp/c文件

有什么办法吗?目录太深,不想手动添加cpp/c文件。

【问题讨论】:

    标签: android-ndk cmake


    【解决方案1】:

    你可以试试:

    file(GLOB_RECURSE cpp_srcs "src/main/cpp/*.c" "src/main/cpp/*.cpp")
    

    或者也许:

    file(GLOB_RECURSE cpp_srcs_c "src/main/cpp/*.c")
    file(GLOB_RECURSE cpp_srcs_cpp "src/main/cpp/*.cpp")
    set(cpp_srcs ${cpp_srcs_c} ${cpp_srcs_cpp})
    

    我不确定第一个模式是否有效,我现在无法测试,但第二个应该可以。

    【讨论】:

      猜你喜欢
      • 2016-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-14
      • 1970-01-01
      • 2011-09-26
      • 2013-09-27
      相关资源
      最近更新 更多