Issue
I am trying to build an Android NDK project using CMake. My project has dependencies of some pre-built static libraries like libcurl. I was struggling to link those libraries with my own native library, then I followed this answer. It said to put absolute paths for the static libraries, and that's where I am facing a problem now.
I found a CMake variable named PROJECT_SOURCE_DIR
, which I suppose my project root directory as per the documentation. But when I tried to use that variable into my CMakeList.txt file, it gives the following error:
Build command failed.
Error while executing process /Users/sdsl/Library/Android/sdk/cmake/3.6.4111459/bin/cmake with arguments {--build /Users/sdsl/Documents/AfriGIS-SB/GitLab/AGMapKit3dDroid/agmapkit3d_droid/mapkit3dapp/.externalNativeBuild/cmake/debug/x86_64 --target mapkit-engine}
ninja: error: '../../../../mapkit3dapp/src/main/jni/CoreClasses/Libraries/droid/libcurl/x86_64/libcurl.a', needed by '../../../../build/intermediates/cmake/debug/obj/x86_64/libmapkit-engine.so', missing and no known rule to make it
Here is my CMakeLists.txt file:
cmake_minimum_required(VERSION 3.4.1)
add_library( # Sets the name of the library.
mapkit-engine
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
src/main/jni/MKMapJNI.cpp
src/main/jni/CoreClasses/IMKCPlatform.cpp)
# Specifies a path to native header files.
include_directories(src/main/jni/CoreClasses/)
include_directories(src/main/jni/CoreClasses/Libraries/droid/libcurl/include/)
find_library(log-lib log)
find_library(android-lib android)
target_link_libraries(mapkit-engine ${log-lib} ${android-lib})
target_link_libraries(mapkit-engine ${PROJECT_SOURCE_DIR}/mapkit3dapp/src/main/jni/CoreClasses/Libraries/droid/libcurl/${ANDROID_ABI}/libcurl.a)
I can assure that my static libraries are stored inside my project directory properly. And if I tried to navigate to my project root directory by clicking that PROJECT_SOURCE_DIR
variable, it takes me to the root directory into the IDE.
Solution
I have figured out that my understanding was not correct for the cmake variable PROJECT_SOURCE_DIR
, the official documentation is also not like crystal clear about it's actual outcome.
Top level source directory for the current project.
This is the source directory of the most recent project() command.
But in most Android NDK projects using cmake build, it's quite normal not to call the project()
command manually. And is that cases the PROJECT_SOURCE_DIR
variable points to the src directory where CMakeLists.txt is located.
In my case, my root src directory was: /Users/sdsl/Documents/AfriGIS-SB/GitLab/AGMapKit3dDroid/agmapkit3d_droid/
. And the PROJECT_SOURCE_DIR
is pointing to: /Users/sdsl/Documents/AfriGIS-SB/GitLab/AGMapKit3dDroid/agmapkit3d_droid/mapkit3dapp/
.
That is also the directory where I have put the CMakeLists.txt file. Thanks to Tsyvarev, for helping me to figure out what actually the PROJECT_SOURCE_DIR
results in execution.
Answered By - sourav.bh
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.