When using add_jar for generating JNI headers , the option GENERATE_NATIVE_HEADERS DESTINATION rejects path prefixed into build directory and if absolute path specified writes it into INTERFACE_INCLUDE_DIRECTORIES which leads to an error in consuming project during target importing (from xxxTargets.camke)
add_jar fails if relative path to the native_headers DESTINATION specified. If DESTINATION option is omitted or if relative path specified in the DESTINATION option, then add_jar writes an absolute path into INTERFACE_INCLUDE_DIRECTORIES and cmake fails with CMake Error indicating " Target “myProjJni” INTERFACE_INCLUDE_DIRECTORIES property contains
path: “/home/myspace/myproject/include” which is prefixed in the source directory."
If DESTINATION option is set with a path inside build directory ${CMAKE_CURRENT_BINARY_DIR}…, then cmake fails with similar error invalidating path bc it is inside build directory.
If the DESTINATION is set to be under ${CMAKE_INSTALL_PREFIX} then cmake completes with no error but it writes an absolute path into export Targets.cmake file which causes consuming project import to fail.
So could you please advise how to set cmake to prevent writing an absolute path into Targets.cmake . Note, another target that depends on the native_header target created by add_jar is being installed/exported with correct relative path and Targets.cmake has prefix "${_IMPORT_PREFIX} . If native_header is not installed, then cmake fails with an error that dependent target is missing
The cmake-generated export-name xxxTargets.cmake file has absolute path
add_library(mynms::myProjJni INTERFACE IMPORTED)
set_target_properties(framework::myProjJni PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "/home/myspace/myproject/include;${_IMPORT_PREFIX}/myproject/include"
)
CMakeLists.txt:
add_jar(myProjJava
SOURCES ${JNI_SRC}
INCLUDE_JARS ${JNI_CLASSPATH}
GENERATE_NATIVE_HEADERS myProjJni
DESTINATION ${CMAKE_INSTALL_PREFIX}/include #fails if ${CMAKE_INSTALL_PREFIX} removed
)