Including resources with add_jar

Hi I’m trying to include some resources (jni library files) inside my jar but I’m facing issues to get exactly what I want.

I use add_jar(target SOURCES ${javasources} OUTPUT_DIR ${BUILD_ROOT}/jar) to generate the Jar and it works well).

But when I use,
file(GLOB_RECURSE jniResources ${STAGING_ROOT}/**.so)
add_jar(target SOURCES ${javasources} ${jniResources} OUTPUT_DIR ${BUILD_ROOT}/jar), it thinks the absolute paths are relative. When I point to the .so file directly in jniResources, it does copy it over but how it decides which folders are to be copied as well isn’t really clear to me and I’d like to copy over a specific folder and it’s contents starting from the specific folder.

By looking at implementation, resources are assumed to be specified as relative paths to the current source directory (CMAKE_CURRENT_SOURCE_DIR).

You can use command file(RELATIVE_PATH...) to compute relative paths from your initial absolute paths.