Skip to content

Commit

Permalink
Find{Java,JNI}: Consider JAVA_HOME before ENV{JAVA_HOME}
Browse files Browse the repository at this point in the history
Add a helper module CMakeFindJavaCommon shared between FindJava
and FindJNI to select a JAVA_HOME value.  Prefer a CMake variable
or cache entry first, then an environment variable.
  • Loading branch information
bradking committed Jan 29, 2014
1 parent 4b3614b commit fcd66a7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
30 changes: 30 additions & 0 deletions Modules/CMakeFindJavaCommon.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

#=============================================================================
# Copyright 2013-2014 Kitware, Inc.
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)

# Do not include this module directly from code outside CMake!
set(_JAVA_HOME "")
if(JAVA_HOME AND IS_DIRECTORY "${JAVA_HOME}")
set(_JAVA_HOME "${JAVA_HOME}")
set(_JAVA_HOME_EXPLICIT 1)
else()
set(_ENV_JAVA_HOME "")
if(DEFINED ENV{JAVA_HOME})
file(TO_CMAKE_PATH "$ENV{JAVA_HOME}" _ENV_JAVA_HOME)
endif()
if(_ENV_JAVA_HOME AND IS_DIRECTORY "${_ENV_JAVA_HOME}")
set(_JAVA_HOME "${_ENV_JAVA_HOME}")
set(_JAVA_HOME_EXPLICIT 1)
endif()
unset(_ENV_JAVA_HOME)
endif()
7 changes: 5 additions & 2 deletions Modules/FindJNI.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
#
# This module finds if Java is installed and determines where the
# include files and libraries are. It also determines what the name of
# the library is. This code sets the following variables:
# the library is. The caller may set variable JAVA_HOME to specify a
# Java installation prefix explicitly.
#
# This module sets the following result variables:
#
# ::
#
Expand Down Expand Up @@ -91,7 +94,7 @@ macro(java_append_library_directories _var)
endforeach()
endmacro()

file(TO_CMAKE_PATH "$ENV{JAVA_HOME}" _JAVA_HOME)
include(${CMAKE_CURRENT_LIST_DIR}/CMakeFindJavaCommon.cmake)

set(JAVA_AWT_LIBRARY_DIRECTORIES)
if(_JAVA_HOME)
Expand Down
8 changes: 5 additions & 3 deletions Modules/FindJava.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
# Find Java
#
# This module finds if Java is installed and determines where the
# include files and libraries are. This code sets the following
# variables:
# include files and libraries are. The caller may set variable JAVA_HOME
# to specify a Java installation prefix explicitly.
#
# This module sets the following result variables:
#
# ::
#
Expand Down Expand Up @@ -67,7 +69,7 @@
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)

file(TO_CMAKE_PATH "$ENV{JAVA_HOME}" _JAVA_HOME)
include(${CMAKE_CURRENT_LIST_DIR}/CMakeFindJavaCommon.cmake)

# The HINTS option should only be used for values computed from the system.
set(_JAVA_HINTS)
Expand Down

0 comments on commit fcd66a7

Please sign in to comment.