I am trying to convert my Android NDK cpp projects (ndk-build with Android.mk) to CMAKE in Android Studio. I have a project hierarchy like this:
.
├── 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
Module1 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})
I am seeing the following error when I build:
CMake Error at CMakeLists.txt (add_subdirectory):
How do I include MyModule1 into MyProject?
Suggested fix from:
Add a dependency not in a subdirectory using CMake
worked for me.
include_directories(../MyMModule1/include/)
add_subdirectory("../MyMModule1/" "${CMAKE_CURRENT_BINARY_DIR}/MyModule1_build")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.