File: UseJavaTest.cmake

package info (click to toggle)
gdcm 3.0.24-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 27,856 kB
  • sloc: cpp: 203,722; ansic: 76,471; xml: 48,131; python: 3,473; cs: 2,308; java: 1,629; lex: 1,290; sh: 334; php: 128; makefile: 97
file content (102 lines) | stat: -rw-r--r-- 3,244 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# Add a java test from a java file
#
# Usage:
# set_source_files_properties(test.py PROPERTIES PYTHONPATH
#   "${LIBRARY_OUTPUT_PATH}:${VTK_DIR}")
# ADD_PYTHON_TEST(PYTHON-TEST test.py)
#
#  Copyright (c) 2006-2011 Mathieu Malaterre <mathieu.malaterre@gmail.com>
#
#  Redistribution and use is allowed according to the terms of the New
#  BSD license.
#  For details see the accompanying COPYING-CMAKE-SCRIPTS file.
#

# Need python interpreter:
#find_package(PythonInterp REQUIRED)
#mark_as_advanced(PYTHON_EXECUTABLE)
# UseCSharp.cmake

macro(ADD_JAVA_TEST TESTNAME FILENAME)
  set(_sep ":")
  if(WIN32)
    set(_sep "\\;")
  endif()
  get_source_file_property(loc ${FILENAME}.class LOCATION)
  get_source_file_property(pyenv ${FILENAME}.class RUNTIMEPATH)
  get_source_file_property(theclasspath ${FILENAME}.class CLASSPATH)
  get_filename_component(loc2 ${loc} NAME_WE)


  if(CMAKE_CONFIGURATION_TYPES)
    # I cannot use CMAKE_CFG_INTDIR since it expand to "$(OutDir)"
    if(pyenv)
      set(pyenv "${pyenv};${LIBRARY_OUTPUT_PATH}/${CMAKE_BUILD_TYPE}")
    else()
      set(pyenv ${LIBRARY_OUTPUT_PATH}/${CMAKE_BUILD_TYPE})
      #set(pyenv ${LIBRARY_OUTPUT_PATH}/${CMAKE_CFG_INTDIR})
      #set(pyenv ${LIBRARY_OUTPUT_PATH}/${CMAKE_CONFIG_TYPE})
      #set(pyenv ${LIBRARY_OUTPUT_PATH}/\${CMAKE_CONFIG_TYPE})
    endif()
  else()
    if(pyenv)
      set(pyenv ${pyenv}${_sep}${LIBRARY_OUTPUT_PATH})
    else()
      set(pyenv ${LIBRARY_OUTPUT_PATH})
    endif()
   endif()
  string(REGEX REPLACE ";" " " wo_semicolumn "${ARGN}")

  set(classpath)
  if(theclasspath)
    set(classpath "${theclasspath}${_sep}.")
  else()
    set(classpath ".")
  endif()
  set(theld_library_path $ENV{LD_LIBRARY_PATH})
  set(ld_library_path)
  if(theld_library_path)
    set(ld_library_path ${theld_library_path})
  endif()
  if(pyenv)
    set(ld_library_path ${ld_library_path}${_sep}${pyenv})
  endif()

  file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${TESTNAME}.cmake
"
  if(UNIX)
  set(ENV{LD_LIBRARY_PATH} ${ld_library_path})
  set(ENV{DYLD_LIBRARY_PATH} ${ld_library_path})
  #set(ENV{CLASSPATH} ${pyenv}/gdcm.jar${_sep}.)
  #message(\"pyenv: ${pyenv}\")
  else()
  #set(the_path $ENV{PATH})
  set(ENV{PATH} ${ld_library_path})
  endif()
  message(\"ld_library_path: ${ld_library_path}\")
  message(\"loc: ${loc}\")
  message(\"loc2: ${loc2}\")
  message(\"JavaProp_PATH_SEPARATOR: \"${JavaProp_PATH_SEPARATOR}\"\")
  message(\"classpath: \"${classpath}\"\")
  message(\"java runtime: ${Java_JAVA_EXECUTABLE}\")
  #message( \"wo_semicolumn: ${wo_semicolumn}\" )
  execute_process(
    #COMMAND ${Java_JAVA_EXECUTABLE} -Djava.library.path=\"${GDCM_LIBRARY_DIR}\" -classpath \"${classpath}\" ${loc2} ${wo_semicolumn}
    COMMAND ${Java_JAVA_EXECUTABLE} -classpath \"${classpath}\" ${loc2} ${wo_semicolumn}
    WORKING_DIRECTORY \"${EXECUTABLE_OUTPUT_PATH}\"
    RESULT_VARIABLE import_res
    OUTPUT_VARIABLE import_output
    ERROR_VARIABLE  import_output
  )

  # Pass the output back to ctest
  if(import_output)
    message(STATUS \"\${import_output}\")
  endif()
  if(import_res)
    message(SEND_ERROR \"\${import_res}\")
  endif()
"
)
  add_test(NAME ${TESTNAME} COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/${TESTNAME}.cmake)
endmacro()