如何在'CMakeLists.txt'中使用add_library将整个文件(.cpp,.h等)包含在目录中

时间:2017-10-24 09:19:00

标签: android c++ android-ndk android-studio-2.3

在我的项目中,我使用的是cpp和.h文件,它们都在不同的文件夹中

this.dataStorage.recipeSubscription.subscribe((res) => {
    // Do stuff.
});

this.dataStorage.getRecipes();

在当前版本中,我将每个文件添加到|-src |-main |-java |-cpp |-native-lib.cpp |-library-1 |-include |-lib11.h |-lib12.h |-... |-library-2 |-include |-lib21.h |-lib22.h |-...

'CMakeLists.txt'

我尝试添加如下

...

add_library(# Sets the name of the library.
            native-lib

            # Sets the library as a shared library.
            SHARED

            # Provides a relative path to your source file(s).



            src/main/cpp/native-lib.cpp
            src/main/cpp/library-1/include/lib10.h
            src/main/cpp/library-1/include/lib11.h
            src/main/cpp/library-1/include/lib12.h
            src/main/cpp/library-1/include/lib13.h
            ...

            src/main/cpp/library-2/include/lib21.h
            src/main/cpp/library-2/include/lib22.h
            src/main/cpp/library-2/include/lib23.h
            ...

)
...

使用... add_library(# Sets the name of the library. native-lib # Sets the library as a shared library. SHARED # Provides a relative path to your source file(s). src/main/cpp/native-lib.cpp src/main/cpp/library-1/include/*.h #expected result: it will include all '.h' files in directory, but gradle sync failed src/main/cpp/library-2/include/*.h#expected result: it will include all '.h' files in directory, but gradle sync failed ) ...

包含文件夹中所有文件的任何其他方式

来自Lucky的建议

add_library

1 个答案:

答案 0 :(得分:9)

您可以生成源文件列表:

file(GLOB SOURCES "src/*.h")

现在,SOURCES变量可以用作add_library中的参数。

add_library(native-lib SHARED ${SOURCES})