1# - try to find Java's IDLJ Interface Definition Language compiler. 2# 3# Ideally used with CMake 2.8.5 or newer for Java support using FindJava.cmake 4# and UseJava.cmake 5# 6# Variables: 7# Java_IDLJ_COMMAND, executable for idlj 8# IDLJ_FOUND, If false, do not try to use this 9# 10# Function: 11# java_idlj(varname idlfile [extra idlj args]) - Generates 12# the Java source files from the IDL file you indicate, and 13# appends filenames suitable to add to a add_jar() call to the 14# variable you specified. 15# 16# Because the files generated from an IDL file are not entirely predictable, 17# java_idlj runs idlj in the cmake step, rather than the build step, and triggers 18# a CMake re-run when an idl file is modified. Already up-to-date generated source 19# is not re-generated, however. 20# 21# Files are generated in a directory created specifically for 22# the particular IDL file and the particular call, in the build directory - 23# there should be no worries about overwriting files or picking up too much 24# with the wildcard. 25# 26# You may wish to add the IDL file to your list of sources if you want it 27# to appear in your IDE, but it is not necessary. 28# 29# Original Author: 30# 2012 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net> 31# http://academic.cleardefinition.com 32# Iowa State University HCI Graduate Program/VRAC 33# 34# Copyright Iowa State University 2012. 35# Distributed under the Boost Software License, Version 1.0. 36# (See accompanying file LICENSE_1_0.txt or copy at 37# http://www.boost.org/LICENSE_1_0.txt) 38 39if(NOT JAVA_FOUND) 40 find_package(Java QUIET) 41endif() 42 43if(JAVA_FOUND) 44 get_filename_component(JAVA_BIN_DIR "${Java_JAVAC_EXECUTABLE}" PATH) 45 find_program(Java_IDLJ_COMMAND 46 idlj 47 HINTS 48 ${JAVA_BIN_DIR} 49 ) 50endif() 51 52# handle the QUIETLY and REQUIRED arguments and set xxx_FOUND to TRUE if 53# all listed variables are TRUE 54include(FindPackageHandleStandardArgs) 55find_package_handle_standard_args(IDLJ 56 DEFAULT_MSG 57 Java_IDLJ_COMMAND 58 JAVA_FOUND) 59 60if(IDLJ_FOUND) 61 function(java_idlj _varname _idlfile) 62 # Get some unique value we can use in a directory name 63 # TODO would be better to somehow munge the full path relative to CMAKE_CURRENT_SOURCE_DIR 64 # in case somebody has multiple idl files with the same name 65 get_filename_component(_idl_name "${_idlfile}" NAME_WE) 66 get_filename_component(_idl_abs "${_idlfile}" ABSOLUTE) 67 68 # Compute directory name and stamp filename 69 set(outdir "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/idlj/${_idl_name}.dir") 70 set(stampfile "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/idlj/${_idl_name}.stamp") 71 72 # Force re-cmake if idl file changes 73 configure_file("${_idl_abs}" "${stampfile}" COPY_ONLY) 74 75 if((NOT EXISTS "${outdir}") OR ("${_idl_abs}" IS_NEWER_THAN "${outdir}")) 76 file(REMOVE_RECURSE "${outdir}") 77 message(STATUS "Processing ${_idlfile} with Java's idlj") 78 execute_process(COMMAND 79 "${Java_IDLJ_COMMAND}" -fclient -fallTIE -td "${outdir}" ${ARGN} "${_idlfile}" 80 WORKING_DIRECTORY 81 "${CMAKE_CURRENT_SOURCE_DIR}") 82 endif() 83 file(GLOB_RECURSE _idl_output "${outdir}/*") 84 85 set(${_varname} ${_idl_output} PARENT_SCOPE) 86 87 # Clean up after ourselves on make clean 88 set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${outdir}" "${stampfile}") 89 endfunction() 90endif() 91 92mark_as_advanced(Java_IDLJ_COMMAND) 93