View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0009840CMakeModulespublic2009-11-04 09:482010-05-11 16:53
ReporterMathieu Malaterre 
Assigned ToMathieu Malaterre 
PrioritynormalSeverityminorReproducibilityhave not tried
StatusclosedResolutionfixed 
PlatformOSOS Version
Product Version 
Target VersionFixed in VersionCMake-2-8 
Summary0009840: find_package(Java 1.6 COMPONENTS Runtime)
DescriptionPlease implement:

find_package(Java 1.6 COMPONENTS Runtime)

Right now the FindJava fails if javac or jar is not found, which is the case for JRE installation (instead of JDK).

It would be cool to handle both case, thanks to COMP interface.

Additional InformationIt works now, thanks.

The Java is c:/windows/system32/java.exe from 64-bit Vista.

I tried a test project like this:

 find_package(Java 1.7) # missing version
 foreach(v Java_VERSION Java_FOUND)
   message("${v}=[${${v}}]")
 endforeach()

and got this:

 -- Could NOT find Java (missing: Java_JAR_EXECUTABLE Java_JAVAC_EXECUTABLE _java_version_acceptable)
 Java_VERSION=[1.6.0]
 Java_FOUND=[]

Then I tried

 find_package(Java 1.6) # available version
 foreach(v Java_VERSION Java_FOUND)
   message("${v}=[${${v}}]")
 endforeach()

and go this:

 -- Java version 1.6.0 configured successfully!
 -- Could NOT find Java (missing: Java_JAR_EXECUTABLE Java_JAVAC_EXECUTABLE)
 Java_VERSION=[1.6.0]
 Java_FOUND=[]

If in the future you want to try to distinguish between the runtime
and development parts of java, perhaps you can use the find_package
COMPOENTS feature to allow something like

 find_package(Java 1.6 COMPONENTS Runtime)

or

 find_package(Java 1.6 COMPONENTS Compiler)

to look for different pieces.
TagsNo tags attached.
Attached Files

 Relationships

  Notes
(0020682)
Mathieu Malaterre (developer)
2010-05-09 05:29

diff --git a/Modules/FindJava.cmake b/Modules/FindJava.cmake
index 9e2a640..4cd4389 100644
--- a/Modules/FindJava.cmake
+++ b/Modules/FindJava.cmake
@@ -24,9 +24,18 @@
 # and
 # Java_VERSION = 1.6.0
 #
-# NOTE: At the moment this script will look for javac and jar component,
-# which means it will fail if javac or jar is not found.:w
-# See Bug 0009840
+# For these components the following variables are set:
+#
+# Java_FOUND - TRUE if all components are found.
+# Java_INCLUDE_DIRS - Full paths to all include dirs.
+# Java_LIBRARIES - Full paths to all libraries.
+# Java_<component>_FOUND - TRUE if <component> is found.
+#
+# Example Usages:
+# FIND_PACKAGE(Java)
+# FIND_PACKAGE(Java COMPONENTS Runtime)
+# FIND_PACKAGE(Java COMPONENTS Development)
+#
 
 #=============================================================================
 # Copyright 2002-2009 Kitware, Inc.
@@ -152,12 +161,36 @@ FIND_PROGRAM(Java_JAVAC_EXECUTABLE
 )
 
 include(FindPackageHandleStandardArgs)
-find_package_handle_standard_args(Java DEFAULT_MSG
- Java_JAVA_EXECUTABLE
- Java_JAR_EXECUTABLE
- Java_JAVAC_EXECUTABLE
- _java_version_acceptable
-)
+if(Java_FIND_COMPONENTS)
+ foreach(component ${Java_FIND_COMPONENTS})
+ # User just want to execute some Java byte-compiled
+ if(component STREQUAL "Runtime")
+ find_package_handle_standard_args(Java DEFAULT_MSG
+ Java_JAVA_EXECUTABLE
+ _java_version_acceptable
+ )
+ elseif(component STREQUAL "Development")
+ find_package_handle_standard_args(Java DEFAULT_MSG
+ Java_JAVA_EXECUTABLE
+ Java_JAR_EXECUTABLE
+ Java_JAVAC_EXECUTABLE
+ _java_version_acceptable
+ )
+ else()
+ message(FATAL_ERROR "Comp: ${component} is not handled")
+ endif()
+ set(Java_${component}_FOUND TRUE)
+ endforeach(component)
+else()
+ # Check for everything
+ find_package_handle_standard_args(Java DEFAULT_MSG
+ Java_JAVA_EXECUTABLE
+ Java_JAR_EXECUTABLE
+ Java_JAVAC_EXECUTABLE
+ _java_version_acceptable
+ )
+endif()
+
 
 MARK_AS_ADVANCED(
   Java_JAVA_EXECUTABLE
(0020683)
Mathieu Malaterre (developer)
2010-05-09 05:29

I need to read the doc on how to commit that to CMake but this should solve the bug now.
(0020716)
Mathieu Malaterre (developer)
2010-05-11 16:52

Apparently I got my first git push working:

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=0d88e19fefd44d3c243f010f5226f62c34b78b1f [^]

Closing bug

 Issue History
Date Modified Username Field Change
2009-11-04 09:48 Mathieu Malaterre New Issue
2009-11-04 09:50 Mathieu Malaterre Status new => assigned
2009-11-04 09:50 Mathieu Malaterre Assigned To => Mathieu Malaterre
2010-05-09 04:52 Alex Neundorf Category CMake => Modules
2010-05-09 05:29 Mathieu Malaterre Note Added: 0020682
2010-05-09 05:29 Mathieu Malaterre Note Added: 0020683
2010-05-11 16:52 Mathieu Malaterre Note Added: 0020716
2010-05-11 16:53 Mathieu Malaterre Status assigned => closed
2010-05-11 16:53 Mathieu Malaterre Resolution open => fixed
2010-05-11 16:53 Mathieu Malaterre Fixed in Version => CMake-2-8


Copyright © 2000 - 2018 MantisBT Team