代码之家  ›  专栏  ›  技术社区  ›  ssk

在cmake中包含一个静态库,该库来自Android项目的不同文件夹

  •  1
  • ssk  · 技术社区  · 6 年前

    我正在尝试将我的android ndk cpp项目(android.mk的ndk构建)转换为android studio中的cmake。我有这样的项目层次结构:

    .
    ├── Module1
    │   ├── CMakeLists.txt
    │   ├── include
    │   │   └── Module1
    │   ├── libModule1
    │   │   ├── Module1File1.cpp
    │   │   └── Module1File2.cpp
    │   └── utModule1
    ├── MyProject
    │   ├── CMakeLists.txt
    │   ├── MyProject.iml
    │   ├── build
    │   │   ├── generated
    │   │   ├── intermediates
    │   │   └── outputs
    │   ├── build.gradle
    │   ├── proguard-rules.pro
    │   └── src
    │       │
    │       ├── MyProjectFile1.cpp
    │       └── MyProjectFile2.cpp
    |
    └── settings.gradle
    

    模块1 cmakelists.txt:

    cmake_minimum_required(VERSION 3.4.1)
    add_library( # Specifies the name of the library.
                 Module1
    
                 # Sets the library as a shared library.
                 STATIC
    
                 # Provides a relative path to your source file(s).
                 libModule1/Module1File1.cpp
                 libModule1/Module1File2.cpp )
    

    myproject cmakelists.txt文件:

    cmake_minimum_required(VERSION 3.4.1)
    
    add_subdirectory(../MyModule1)
    
    add_library( # Specifies the name of the library.
                 MyProject
                 # Sets the library as a shared library.
                 SHARED
                 # Provides a relative path to your source file(s).
                 src/MyProjectFile1.cpp
                 src/MyProjectFile2.cpp)
    
    target_link_libraries( # Specifies the target library.
            MyProject
            # Dependencies
            MyModule1
            # Links the target library to the log library
            # included in the NDK.
            ${log-lib})
    

    生成时出现以下错误:

    CMake Error at CMakeLists.txt (add_subdirectory):
    

    如何将mymodule1包含到我的项目中?

    1 回复  |  直到 6 年前
        1
  •  1
  •   ssk    6 年前

    建议修复来自:

    Add a dependency not in a subdirectory using CMake

    为我工作。

    include_directories(../MyMModule1/include/)
    add_subdirectory("../MyMModule1/" "${CMAKE_CURRENT_BINARY_DIR}/MyModule1_build")