Imported Upstream version 2.8.10.2
[platform/upstream/cmake.git] / Modules / UseJavaClassFilelist.cmake
1 #
2 # This script create a list of compiled Java class files to be added to a
3 # jar file. This avoids including cmake files which get created in the
4 # binary directory.
5 #
6
7 #=============================================================================
8 # Copyright 2010-2011 Andreas schneider <asn@redhat.com>
9 #
10 # Distributed under the OSI-approved BSD License (the "License");
11 # see accompanying file Copyright.txt for details.
12 #
13 # This software is distributed WITHOUT ANY WARRANTY; without even the
14 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 # See the License for more information.
16 #=============================================================================
17 # (To distribute this file outside of CMake, substitute the full
18 #  License text for the above reference.)
19
20 if (CMAKE_JAVA_CLASS_OUTPUT_PATH)
21     if (EXISTS "${CMAKE_JAVA_CLASS_OUTPUT_PATH}")
22
23         set(_JAVA_GLOBBED_FILES)
24         if (CMAKE_JAR_CLASSES_PREFIX)
25             foreach(JAR_CLASS_PREFIX ${CMAKE_JAR_CLASSES_PREFIX})
26                 message(STATUS "JAR_CLASS_PREFIX: ${JAR_CLASS_PREFIX}")
27
28                 file(GLOB_RECURSE _JAVA_GLOBBED_TMP_FILES "${CMAKE_JAVA_CLASS_OUTPUT_PATH}/${JAR_CLASS_PREFIX}/*.class")
29                 if (_JAVA_GLOBBED_TMP_FILES)
30                     list(APPEND _JAVA_GLOBBED_FILES ${_JAVA_GLOBBED_TMP_FILES})
31                 endif ()
32             endforeach()
33         else()
34             file(GLOB_RECURSE _JAVA_GLOBBED_FILES "${CMAKE_JAVA_CLASS_OUTPUT_PATH}/*.class")
35         endif ()
36
37         set(_JAVA_CLASS_FILES)
38         # file(GLOB_RECURSE foo RELATIVE) is broken so we need this.
39         foreach(_JAVA_GLOBBED_FILE ${_JAVA_GLOBBED_FILES})
40             file(RELATIVE_PATH _JAVA_CLASS_FILE ${CMAKE_JAVA_CLASS_OUTPUT_PATH} ${_JAVA_GLOBBED_FILE})
41             set(_JAVA_CLASS_FILES ${_JAVA_CLASS_FILES}${_JAVA_CLASS_FILE}\n)
42         endforeach()
43
44         # write to file
45         file(WRITE ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist ${_JAVA_CLASS_FILES})
46
47     else ()
48         message(SEND_ERROR "FATAL: Java class output path doesn't exist")
49     endif ()
50 else ()
51     message(SEND_ERROR "FATAL: Can't find CMAKE_JAVA_CLASS_OUTPUT_PATH")
52 endif ()