diff options
author | Brad King <brad.king@kitware.com> | 2014-01-29 18:47:51 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2014-01-29 19:12:54 (GMT) |
commit | fcd66a7f7b944f95372386332381a11c3b8b1508 (patch) | |
tree | a671843df379c3e68a384e6265dddf2ca9bb1a55 | |
parent | 4b3614b25a10bf558b3687cee5bac012779866e3 (diff) | |
download | CMake-fcd66a7f7b944f95372386332381a11c3b8b1508.zip CMake-fcd66a7f7b944f95372386332381a11c3b8b1508.tar.gz CMake-fcd66a7f7b944f95372386332381a11c3b8b1508.tar.bz2 |
Find{Java,JNI}: Consider JAVA_HOME before ENV{JAVA_HOME}
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.
-rw-r--r-- | Modules/CMakeFindJavaCommon.cmake | 30 | ||||
-rw-r--r-- | Modules/FindJNI.cmake | 7 | ||||
-rw-r--r-- | Modules/FindJava.cmake | 8 |
3 files changed, 40 insertions, 5 deletions
diff --git a/Modules/CMakeFindJavaCommon.cmake b/Modules/CMakeFindJavaCommon.cmake new file mode 100644 index 0000000..fd52689 --- /dev/null +++ b/Modules/CMakeFindJavaCommon.cmake @@ -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() diff --git a/Modules/FindJNI.cmake b/Modules/FindJNI.cmake index aef28d1..ccb5191 100644 --- a/Modules/FindJNI.cmake +++ b/Modules/FindJNI.cmake @@ -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: # # :: # @@ -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) diff --git a/Modules/FindJava.cmake b/Modules/FindJava.cmake index 36624a4..a488c46 100644 --- a/Modules/FindJava.cmake +++ b/Modules/FindJava.cmake @@ -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: # # :: # @@ -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) |