Reputation: 11640
For incorporating other opensource libs via CMake, I've checked similar questions such as this one:
Android Studio: Adding a library outside of the project root
but those are about incorporating Android-Studio lib projects instead of external libs.
In my case, I have a folder structure like this:
In the project CMakeLists.txt, I then added this
target_link_libraries( # Specifies the target library.
native-lib
# Links the target library to the log library
# included in the NDK.
${log-lib} MyLib)
set (MyLib_DIR ../../../thirdparty/category/MyLib)
# output lib binary
add_subdirectory (${MyLib_DIR} ./MyLib)
include_directories (${OBOE_DIR}/include)
I learned from sample code and assume that the CMake source root is at src/MyAndroidStudioProject/app
, so MyLib
is located using relative path accordingly.
However, building the project gives me
CMake Error at /path/to/src/MyAndroidStudioProject/app/src/main/cpp/CMakeLists.txt:53 (add_subdirectory):
add_subdirectory given source "../../../thirdparty/category/MyLib"
which is not an existing directory.
How should I fix this? Should I configure other settings in the project?
Upvotes: 0
Views: 500
Reputation: 11640
OK, solved it myself.
The relative path should be relative to the CMakeLists.txt
file, located at
/path/to/src/MyAndroidStudioProject/app/src/main/cpp/CMakeLists.txt
So the correct relative path in my case should be
set (MyLib_DIR ../../../../../../thirdparty/category/MyLib)
i.e., CMakeLists.txt
is 3 levels down the app
folder.
Upvotes: 1