GENERATE_NATIVE_HEADERS target is not recognized as INTERFACE type

target_include_directories failed when target (myprojJNI below) is a target that was created by add_jar GENERATE_NATIVE_HEADERS option.
ERROR: CMake Error at …CMakeLists.txt:… (target_include_directories):
target_include_directories may only set INTERFACE properties on INTERFACE
targets"
This target was created with

 add_jar(myprojJava
        SOURCES ${JNI_SRC}
        INCLUDE_JARS ${JNI_CLASSPATH}
        GENERATE_NATIVE_HEADERS myprojJNI)

Here myprojJNI is a target and documenation said :
“using option GENERATE_NATIVE_HEADERS, native header files can be generated for methods declared as native. These files provide the connective glue that allow your Java and C code to interact. An INTERFACE target will be created for an easy usage of generated files. Sub-option DESTINATION can be used to specify the output directory for generated header files” So myprojJNI must be INTERFACE target and therefore allow target_include_directories setting like

target_include_directories(myprojJNI
        PUBLIC   #<-- Wrong, it must match myprojJNI target type which is INTERFACE
            $<INSTALL_INTERFACE:${ARCH}/include>
            $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
)

So why is this error occuring?
Note 1, there is also another error "Could NOT find JNI (missing: JNI_DIR)
" at the begging of CMakeLists in the
find_package(JNI PATHS /opt/jdk/jdk8)

but cmake documentation said JNI is recommended for using
GENERATE_NATIVE_HEADERS, but despite JNI package is not found, the JNI native_headers are generated ok under the build tree when target_include_directories and myprojJNI installation code is bypassed (UseJava.cmake : set (_add_jar_GENERATE_NATIVE_HEADERS_DESTINATION "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_TARGET_NAME}.dir/native_headers)
Note 2. The purpose of caling target_include_directories(myprojJNIis to fix an error occurring when install(TARGETWS myprojJNI … ) indicating that myprojJNIis property INTERFACE_INCLUDE_DIRECTORIES contains path to build tree and source tree which is because default value for the native_headers is under ${CMAKE_CURRENT_BINARY_DIR}.
So the bigger question is more general how to install and export target with dependency on GENERATE_NATIVE_HEADERS target like myprojJNI which seems blocked by the default INTERFACE_INCLUDE_DIRECTORIES pointing to CMAKE_CURRENT_BINARY_DIR.

target_link_libraries(myprojlibShared
        ...myprojJNI ...)
....

install(TARGETS myprojlibShared  myprojJNI .. 
          EXPORT myExportTargets ...
)
# had to add myprojJNI to avoid error indicating myprojlibShared dependency on myprojJNI

Your example after this uses PUBLIC instead of INTERFACE. I’m guessing that’s why you see the error message complaining that you may only set INTERFACE properties on INTERFACE targets.

For your other JNI-related questions, I will have to defer to others for follow-up (@marc.chevrier perhaps?).

For error on find_package(JNI ...): you don’t use correctly the command. As specified in FindJNI documentation, you have to set JAVA_HOME variable before calling find_package:

set(JAVA_HOME /opt/jdk/jdk8)
find_package(JNI)

And for the export, I don’t understand your problem. But, first, target_link_libraries does not have option EXPORT. And why do you want to install the JNI interface? It is just headers!! Use keyword PRIVATE to link the jNI interface to avoid problems…
The following snippet works as expected:

add_jar(myprojJava
        SOURCES ${JNI_SRC}
        INCLUDE_JARS ${JNI_CLASSPATH}
        GENERATE_NATIVE_HEADERS myprojJNI)
add_library(myprojlibShared SHARED ...)
target_link_libraries(myprojlibShared PRIVATE myprojJNI)
install(TARGETS myprojlibShared EXPORT libShared DESTINATION /to/install/path)
export (EXPORT libShared NAMESPACE proj::)
install(EXPORT libShared DESTINATION /to/install/path/EXPORT NAMESPACE proj::)

Thank you again! I changed to interface :

target_include_directories(myprojJNI
        INTERFACE    #must match myprojJNI target type which is INTERFACE
            $<INSTALL_INTERFACE:${ARCH}/include>
            $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
)

This passes Configure phase, However this still causes error
in install(TARGETS:

target_link_libraries(myprojlibShared
        ...myprojJNI ...)

install(TARGETS myprojlibShared  myprojJNI .. 
          EXPORT myExportTargets ...
)

ERROR

CMake Error in ... src/CMakeLists.txt:
Target "myprojJNI" INTERFACE_INCLUDE_DIRECTORIES property contains
  path:
    "..build/.../src/CMakeFiles/myprojJava.dir/native_headers"
  which is prefixed in the build directory <!--[Y] Of course it is in build directory bc UseJava.cmake sets it in ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_TARGET_NAME}.dir/native_headers -->
the followed by other error:
Target "myprojJNI" INTERFACE_INCLUDE_DIRECTORIES property contains
  path:
    "..build/.../src/CMakeFiles/myprojJava.dir/native_headers"
  which is prefixed in the source directory <!--[Y]This is wrong since this directory is under build and identified by the previous error as build tree path. -->
then next error 
Target "myprojJNI" INTERFACE_INCLUDE_DIRECTORIES property contains
  path:
    ..../src/JAVA_INCLUDE_PATH-NOTFOUND" <!-- [Y] Indeed is in the source tree, which again indicate previous error is incorrect as path starting from build is not in source dir.-->
  which is prefixed in the source directory
<!-- [Y] for this error note, that Java is found, only JNI is not found as per response to Marc-->

So adding target_include_directories(myprojJNI INTERFACE …) does not change the default path for native_headers which is set by GENERATE_NATIVE_HEADERS option. Could you please advise on these errors and in general how to install a target dependent on a target created by GENERATE_NATIVE_HEADERS option.

Thank you very much for you response Marc. I am sorry I swapped 2 lines in my original post, I fixed this typo so EXPORT is in the right place. In summary set(JAVA_HOME /opt/jdk/jdk8) does not help with finding JNI and making myprojJNI PRIVATE in target_link_libraries(myprojlibShared PRIVATE myprojJNI) does not resolve errors shown in my response to Craig below.
Before calling find_package(JNI), I call find_package(Java) and it reports success

Found Java: /opt/jdk/jdk8/bin/java (found version "1.8.0_161") 

despite JNI package is not found, cmake is able to create native_headers. So for this that I could trigger somehow INTERFACE_INCLUDE_DIRECTORIES settings without NOTFOUND JNI path instances this problem would be solved. I don’s think direct set(INTERFACE_INCLUDE_DIRECTORIES is agood idea, but do you know of better approach ?
So the main problem is to avoid errors shown in my response to Craig below

CMake Error in ... src/CMakeLists.txt:
Target "myprojJNI" INTERFACE_INCLUDE_DIRECTORIES property contains
  path:
    "..build/.../src/CMakeFiles/myprojJava.dir/native_headers"
  which is prefixed in the build directory <!--[Y] Of course it is in build directory bc UseJava.cmake sets it in ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_TARGET_NAME}.dir/native_headers -->

Here I tried your suggestion target_link_libraries(myprojlibShared PRIVATE myprojJNI)
and the same errors still there

If JNI is not found, may be there is some problem on the installation of Java jdk…

Again, why do you want to export the target generated by GENERATE_NATIVE_HEADERS? It is not required to export your library myprojlibShared.

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

The problem has been worked- around by adding DESTINATION path in the add_jar

add_jar(myprojJava
        SOURCES ${JNI_SRC}
        INCLUDE_JARS ${JNI_CLASSPATH}
        GENERATE_NATIVE_HEADERS myprojJNI 
               DESTINATION ${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}
}

This means cmake behavior is problematic because GENERATE_NATIVE_HEADERS default destination is inside the build tree set (_add_jar_GENERATE_NATIVE_HEADERS_DESTINATION "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_TARGET_NAME}.dir/native_headers) and this does not allow installation of the native_headers. The native_headers need to be installed for the upstream project to use library which is built with these headers.