I want to import a prebuilt library using this CmakeLists.txt snippet:
add_library(openssl-crypto
SHARED
IMPORTED )
set_target_proper
You can use set_property
function with attribute TARGET
instead of set_target_properties
, and then you can set path relatively using macros ${PROJECT_SOURCE_DIR}
.
# import shared library libmylib.so
add_library( my-imported-lib
SHARED
IMPORTED)
# set the path to appropriate so files with appropriate architectures
set_property(TARGET
my-imported-lib
PROPERTY IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/<path_to_libs_directory>/${ANDROID_ABI}/libmy-imported-lib.so)
...
# link imported library to your developed library
target_link_libraries( my-developed-lib
my-imported-lib )
Maybe you can use macros ${PROJECT_SOURCE_DIR}
while set lib path with set_target_properties
but I didn't check this way.
Maybe file have wrong datetime.
Set current datetime for ${external_DIR}/libs/${ANDROID_ABI}/libcrypto.so
:
touch ${external_DIR}/libs/${ANDROID_ABI}/libcrypto.so
I found that the set_target_properties
function doesn't like relative paths.
From the CMake Documentation on IMPORTED_LOCATION
Full path to the main file on disk for an IMPORTED target.
To resolve this issue, I used the full path to the library instead.
Example:
set_target_properties ( curl-lib
PROPERTIES IMPORTED_LOCATION
libs/${ANDROID_ABI}/libcurl.a )
. . . becomes . . .
set_target_properties ( curl-lib
PROPERTIES IMPORTED_LOCATION
${PROJECT_SOURCE_DIR}/src/main/cpp/libs/${ANDROID_ABI}/libcurl.a )