If I drop myprojJNI from the list of targets in the install(TARGETS, then error occurs (below ) indicating that dependendee target myprojlibShared needs its dependency myprojJNI because they are linked by
target_link_libraries(myprojlibShared
…myprojJNI …)
install(TARGETS myprojlibShared myprojJNI … #need myprojJNI bc it was linked
EXPORT myExportTargets …
)
ERROR: CMake Error: install(EXPORT “myExportTargets” …) includes target “myprojlibShared” which requires target “myprojJNI” that is not in any export set.
In regards to JNI not found (smaller problem), it got fixed after adding
set(CMAKE_FIND_ROOT_PATH "${JAVA_HOME}")
set(CMAKE_FIND_USE_CMAKE_SYSTEM_PATH "${JAVA_HOME}")
before find_package(JNI)
The problem was caused by find_package(JNI) search path considering only /opt/xxxx and /opt/toolchains while jni.h is located at /opt/jdk/jdk8/include/jni.h. Debugging was done with set(CMAKE_FIND_DEBUG_MODE TRUE) enabling printout of /opt/cmake/share/cmake-3.17/Modules/FindJNI.cmake:341 looking for jni.h find_path considered the following locations list