Skip to content

Commit ee5e253

Browse files
committed
Do not use custom FindJNI.cmake, do not require JDK_11 env variable
1 parent 6afaf41 commit ee5e253

File tree

4 files changed

+29
-23
lines changed

4 files changed

+29
-23
lines changed

CMakeLists.txt

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ if (WIN32 AND (NOT MINGW) AND (NOT CYGWIN))
1414
set(CMAKE_CXX_FLAGS_MINSIZEREL "/MT")
1515
endif ()
1616

17-
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
18-
find_package(JNI11)
17+
find_package(Java 11 REQUIRED COMPONENTS Development)
18+
include(${CMAKE_CURRENT_LIST_DIR}/SetJavaHomeFromJavaExecutable.cmake)
19+
find_package(JNI REQUIRED)
20+
1921
include_directories(${JNI_INCLUDE_DIRS})
2022

2123
add_library(memory_agent SHARED

CONTRIBUTING.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# Contributing guide for debugger memory agent
2+
3+
## Prerequisites
4+
To build the project you should have CMake 3.1 or higher installed, and JDK 11 or higher is installed.
5+
26
## Building
3-
To build the project you should have Cmake 3.1 or higher installed, and `JDK_11`
4-
environmental variable should be set to jdk 11 or higher. Once you've downloaded the project,
5-
you can build it using the following commands in the root project directory:
7+
Once you've downloaded the project, you can build it using the following commands in the root project directory:
68
```
79
cmake .
810
cmake --build .

FindJNI11.cmake

-18
This file was deleted.

SetJavaHomeFromJavaExecutable.cmake

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
if(NOT Java_JAVA_EXECUTABLE)
2+
message(FATAL_ERROR "java executable not found")
3+
endif()
4+
execute_process(COMMAND "${Java_JAVA_EXECUTABLE}" -XshowSettings:properties -version
5+
RESULT_VARIABLE res
6+
OUTPUT_VARIABLE var
7+
ERROR_VARIABLE var
8+
OUTPUT_STRIP_TRAILING_WHITESPACE
9+
ERROR_STRIP_TRAILING_WHITESPACE)
10+
if(res)
11+
message(FATAL_ERROR "Error executing java -version")
12+
else()
13+
set(_java_version_regex "java\\.home = ([^\n]+)")
14+
if(var MATCHES "${_java_version_regex}")
15+
set(JAVA_HOME "${CMAKE_MATCH_1}")
16+
else()
17+
string(REPLACE "\n" "\n " ver_msg "\n${var}")
18+
message(FATAL_ERROR "Java output not recognized:${ver_msg}\nPlease report.")
19+
endif()
20+
endif()

0 commit comments

Comments
 (0)