Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fatal error: jni_md.h: No such file or directory #246

Merged
merged 1 commit into from
Aug 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
61 changes: 31 additions & 30 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ endif()
# ------------------------------------------------------------------------------
# | INCLUDE DIRECTORIES |
# ------------------------------------------------------------------------------
# Temporary measure to test GitHub workflow on Ubuntu
include_directories(/usr/lib/jvm/java-11-openjdk-amd64/include/linux/)
# ZeroTier
include_directories(${ZTO_SRC_DIR})
include_directories(${ZTO_SRC_DIR}/include)
Expand Down Expand Up @@ -471,37 +469,40 @@ endif()

if(ZTS_ENABLE_JAVA OR (BUILD_ANDROID AND NOT ZTS_NDK_ONLY))
message(STATUS "Looking for JNI")

if(BUILD_WIN)
# We are only interested in finding jni.h: we do not care about extended JVM
# functionality or the AWT library. set(JAVA_AWT_LIBRARY NotNeeded)
# set(JAVA_JVM_LIBRARY NotNeeded) set(JAVA_INCLUDE_PATH2 NotNeeded)
# set(JAVA_AWT_INCLUDE_PATH NotNeeded)
set(JAVA_INCLUDE_PATH "C:\\Program Files\\Java\\jdk-10.0.2\\include")
endif()

message(STATUS "Ignore seeing \"Found JNI: NotNeeded\" below; check that JNI_INCLUDE_DIRS is valid")

#
# "trick" CMake into thinking that we have already found these
# https://stackoverflow.com/a/51764145
#
# These may be missing, but we do not need them
#
# There is no official way of telling CMake: "skip looking for AWT, etc."
#
set(JAVA_AWT_LIBRARY NotNeeded)
set(JAVA_JVM_LIBRARY NotNeeded)
set(JAVA_INCLUDE_PATH2 NotNeeded)
set(JAVA_AWT_INCLUDE_PATH NotNeeded)
find_package(JNI REQUIRED)

if(JNI_FOUND)
message(STATUS "JNI_INCLUDE_DIR=${JNI_INCLUDE_DIRS}")
message(STATUS "JNI_LIBRARIES=${JNI_LIBRARIES}")
list(GET JNI_INCLUDE_DIRS 0 JNI_INCLUDE_DIR)
message(STATUS "jni path=${JNI_INCLUDE_DIR}")
include_directories("${JNI_INCLUDE_DIR}")
# include_directories ("${JNI_INCLUDE_DIRS}")
if(BUILD_WIN)
include_directories("${JNI_INCLUDE_DIR}\\win32")
endif()
if(BUILD_MACOS)
include_directories("${JNI_INCLUDE_DIR}/darwin")
endif()
if(BUILD_LINUX)
include_directories("${JNI_INCLUDE_DIR}/linux")
endif()

#
# Do NOT make REQUIRED
# Until there is an official way of telling CMake to skip AWT, etc.,
# then JNI will be considered as "not found"
#
find_package(JNI)

list(FILTER JNI_INCLUDE_DIRS EXCLUDE REGEX NotNeeded)
list(FILTER JNI_LIBRARIES EXCLUDE REGEX NotNeeded)

#
# Do NOT check JNI_FOUND here, check JNI_INCLUDE_DIRS instead
# because of setting the above variables to NotNeeded,
# the variable JNI_FOUND is now set to NotNeeded, which is annoying
#
# We only care about JNI_INCLUDE_DIRS
#
if(JNI_INCLUDE_DIRS)
message(STATUS "JNI_INCLUDE_DIRS: ${JNI_INCLUDE_DIRS}")
include_directories("${JNI_INCLUDE_DIRS}")
else()
message(STATUS "JNI not found")
endif()
Expand Down