AddTestsJava.cmake 5.41 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
INCLUDE(TestingSetup)

# Variables that are set externally
SET(java_binary_dir ${CMAKE_CURRENT_BINARY_DIR})
SET(java_source_dir ${CMAKE_CURRENT_SOURCE_DIR})

# Java Add Dependencies Macro
# Author: Brian Panneton
# Description: This macro adds the java test dependencies.
# Parameters:         
11
#              dependencies     = any target dependencies needed for java tests
12 13 14 15 16
MACRO(ADD_TEST_JAVA_DEPENDENCIES dependencies)
	IF(NOT ("${dependencies}" STREQUAL ""))
		SET_PROPERTY(GLOBAL APPEND PROPERTY JAVA_TEST_DEPENDENCIES 
        		"${dependencies}"
		)
17 18
	ENDIF()
ENDMACRO()
19

20 21 22 23 24 25 26 27 28 29 30
# Java Add File Dependencies Macro
# Author: Brian Panneton
# Description: This macro adds the java test file dependencies.
#        Note: The tests already depend on their own file
# Parameters:         
#              dependencies     = any dependencies needed for java tests
MACRO(ADD_TEST_JAVA_FILE_DEPENDENCIES dependencies)
	IF(NOT ("${dependencies}" STREQUAL ""))
		SET_PROPERTY(GLOBAL APPEND PROPERTY JAVA_TEST_FILE_DEPENDENCIES 
        		"${dependencies}"
		)
31 32
	ENDIF()
ENDMACRO()
33

34 35 36 37
# Java Add Classpath Macro
# Author: Brian Panneton
# Description: This macro adds the java test classpaths.
# Parameters:         
38
#              cp   = any classpaths needed for java tests
39 40 41 42
MACRO(ADD_TEST_JAVA_CLASSPATH cp)
        GET_PROPERTY(classpath GLOBAL PROPERTY JAVA_TEST_CLASSPATH)
        IF(NOT ("${cp}" STREQUAL ""))
                SET_PROPERTY(GLOBAL PROPERTY JAVA_TEST_CLASSPATH 
43
                        "${classpath}${sep}${cp}" 
44
                )
45 46
        ENDIF() 
ENDMACRO()
47 48 49 50 51

# Java Add LDPath  Macro
# Author: Brian Panneton
# Description: This macro adds the java test ldpaths.
# Parameters:         
52
#               ld  = any ldpaths needed for java tests
53 54 55 56
MACRO(ADD_TEST_JAVA_LDPATH ld)
	GET_PROPERTY(ldpath GLOBAL PROPERTY JAVA_TEST_LDPATH)
	IF("${ld}" STRGREATER "")
		SET_PROPERTY(GLOBAL PROPERTY JAVA_TEST_LDPATH 
57
        		"${ldpath}${sep}${ld}" 
58
		)
59 60
	ENDIF()  
ENDMACRO()
61

62 63 64 65 66 67 68 69 70 71 72
# Java Add Path Macro
# Author: Brian Panneton
# Description: This macro adds the java test paths.
# Parameters:         
#               p = any paths needed for java tests
MACRO(ADD_TEST_JAVA_PATH p)
    GET_PROPERTY(path GLOBAL PROPERTY JAVA_TEST_PATH)
    IF("${p}" STRGREATER "")
        SET_PROPERTY(GLOBAL PROPERTY JAVA_TEST_PATH 
                "${path}${sep}${p}" 
        )
73 74
    ENDIF()
ENDMACRO()
75

76 77 78 79 80 81 82 83 84 85 86 87 88
# Add Java Test Macro
# Author: Brian Panneton
# Description:	This macro builds and adds the java test in one shot. There is
#		no need to build a test separately, because there isn't a case 
#		that you don't want to run it.
# Parameters: 
#		executable 	= executable name 
#		${ARGN}		= any arguments for the executable
#
MACRO(ADD_TEST_JAVA executable)

	PARSE_TEST_ARGS("${ARGN}")	

89 90
	GET_PROPERTY(java_file_dependencies GLOBAL PROPERTY 
                    JAVA_TEST_FILE_DEPENDENCIES)
91 92
	GET_PROPERTY(java_classpath GLOBAL PROPERTY JAVA_TEST_CLASSPATH)
	GET_PROPERTY(java_ldpath GLOBAL PROPERTY JAVA_TEST_LDPATH)
93
    GET_PROPERTY(java_path GLOBAL PROPERTY JAVA_TEST_PATH)
94 95 96 97 98
	
	ADD_CUSTOM_COMMAND(
		OUTPUT ${java_binary_dir}/${executable}.class
		WORKING_DIRECTORY ${java_binary_dir}
		DEPENDS	${java_source_dir}/${executable}.java
99
			${java_file_dependencies}
100
		COMMAND ${JAVA_COMPILE}
101 102
		ARGS	-cp	"\"${java_classpath}\""
			-d	"\"${java_binary_dir}\""
103 104 105 106 107
			${java_source_dir}/${executable}.java
	)
	
	SET_PROPERTY(GLOBAL APPEND PROPERTY JAVA_TEST_TARGETS "${java_binary_dir}/${executable}.class")
	
108 109 110 111
    # Dlls need to be in the path dir for java
    IF(WIN32)
        IF("${java_path}" STREQUAL "")
            SET(java_path ${java_ldpath})
112 113
        ENDIF()
    ENDIF()    
114

115 116 117 118 119 120 121 122 123 124
	SET_CORE("${java_binary_dir}")
    ADD_TEST(Java${is_core}_${executable}${dup} ${CMAKE_COMMAND}
            -D "EXECUTABLE=${executable}"
            -D "ARGUMENTS=${arguments}"
            -D "CLASSPATH=${java_classpath}"
            -D "LDPATH=${java_ldpath}"
            -D "PATH=${java_path}"
            -D "SEPARATOR=${sep}"
            -P "${java_binary_dir}/TestDriverJava.cmake"
    )
125 126 127
    IF(NOT "${tdep}" STREQUAL "")
        SET_TESTS_PROPERTIES(Java${is_core}_${executable}${dup}
            PROPERTIES DEPENDS ${tdep})
128 129
    ENDIF()
ENDMACRO()
130 131 132 133 134 135 136 137 138 139 140

# Java Clean Macro
# Author: Brian Panneton
# Description: This macro sets up the java test for a make clean.
# Parameters:         
#              executable      = executable name
#              ${ARGN}         = files that the executable created
MACRO(CLEAN_TEST_JAVA executable)
       set_property(DIRECTORY APPEND PROPERTY 
                ADDITIONAL_MAKE_CLEAN_FILES ${ARGN}
       )
141
ENDMACRO()
142 143 144

# Java Create Target Macro
# Author: Brian Panneton
145
# Description: This macro sets up the java test target
146 147
# Parameters:   none
MACRO(CREATE_TARGET_TEST_JAVA)
148 149
    IF(EXISTS JavaCore_ALLTEST)
        SET(JavaCore_ALLTEST JavaCore_ALLTEST)
150
    ENDIF()
151 152

    GET_PROPERTY(java_dependencies GLOBAL PROPERTY JAVA_TEST_DEPENDENCIES)
153 154 155

	SET_CORE("${java_binary_dir}")
	GET_PROPERTY(targets GLOBAL PROPERTY JAVA_TEST_TARGETS)
156 157 158 159 160
    ADD_CUSTOM_TARGET(Java${is_core}_ALLTEST ALL DEPENDS 
            ${JavaCore_ALLTEST} ${targets})
   
    IF(NOT ("${java_dependencies}" STREQUAL ""))
        ADD_DEPENDENCIES(Java${is_core}_ALLTEST ${java_dependencies})
161
    ENDIF()
162 163

	IF(NOT ("${is_core}" STREQUAL ""))
164
        SET_PROPERTY(GLOBAL PROPERTY JAVA_TEST_TARGETS "")
165
    ENDIF()
166

167
ENDMACRO()
168 169 170 171


# Configure the java 'driver' file
CONFIGURE_FILE(${TESTING_SUITE_DIR}/TestingSuite/TestDriverJava.cmake.in ${java_binary_dir}/TestDriverJava.cmake @ONLY)