summaryrefslogtreecommitdiff
path: root/Modules/CMakeFindJavaCommon.cmake
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2014-01-29 13:47:51 -0500
committerBrad King <brad.king@kitware.com>2014-01-29 14:12:54 -0500
commitfcd66a7f7b944f95372386332381a11c3b8b1508 (patch)
treea671843df379c3e68a384e6265dddf2ca9bb1a55 /Modules/CMakeFindJavaCommon.cmake
parent4b3614b25a10bf558b3687cee5bac012779866e3 (diff)
downloadcmake-fcd66a7f7b944f95372386332381a11c3b8b1508.tar.gz
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.
Diffstat (limited to 'Modules/CMakeFindJavaCommon.cmake')
-rw-r--r--Modules/CMakeFindJavaCommon.cmake30
1 files changed, 30 insertions, 0 deletions
diff --git a/Modules/CMakeFindJavaCommon.cmake b/Modules/CMakeFindJavaCommon.cmake
new file mode 100644
index 0000000000..fd5268905a
--- /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()