117 cedaAddJavaTest
It has been found that setting java.library.path to the location of the .so files
(i.e. ${Ceda_LIB}) works on Linux, but setting java.library.path to the location
of the .dll files (i.e. ${Ceda_BIN}) doesn't work on Windows.
Instead, on Windows it is necessary to set the PATH environment variable
function(cedaAddJavaTest)
cmake_parse_arguments(
PARSED_ARGS # prefix of output variables
"" # list of names of the boolean arguments (only defined ones will be true)
"NAME;MAINCLASS" # list of names of mono-valued arguments
"INCLUDE_JARS" # list of names of multi-valued arguments (output variables are lists)
${ARGN} # arguments of the function to parse, here we take the all original ones
)
if(NOT PARSED_ARGS_NAME)
message(FATAL_ERROR "NAME parameter required in call to cedaAddJavaTest")
endif()
if(NOT PARSED_ARGS_MAINCLASS)
message(FATAL_ERROR "MAINCLASS parameter required in call to cedaAddJavaTest")
endif()
set(testName ${PARSED_ARGS_NAME})
set(mainClass ${PARSED_ARGS_MAINCLASS})
set(includeJars ${PARSED_ARGS_INCLUDE_JARS})
if (BUILD_SHARED_LIBS)
set(jarFilesList "") # create empty list
foreach(j ${includeJars})
if (TARGET ${j})
get_target_property(jarFile ${j} JAR_FILE)
list(APPEND jarFilesList ${jarFile})
else()
list(APPEND jarFilesList ${j})
endif()
endforeach(j)
if (TARGET CedaJni)
get_target_property(jarFile CedaJni JAR_FILE)
list(APPEND jarFilesList ${jarFile})
else()
list(APPEND jarFilesList "${Ceda_BIN}/CedaJni.jar")
endif()
if(CMAKE_HOST_WIN32)
# On Windows all the .dll files created in this project live in ${Ceda_BIN}
# It has been found that setting java.library.path to this location doesn't work
# because, for example when loading cxJava.dll we get the error:
# Can't find dependent libraries
# Instead it is necessary to set the PATH environment variable so it includes
# ${Ceda_BIN}
message("Adding test: ${Java_JAVA_EXECUTABLE} -cp ${jarFilesList} ${mainClass} with PATH=${Ceda_BIN}")
add_test(
NAME ${testName}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMAND ${Java_JAVA_EXECUTABLE} -ea -cp "${jarFilesList}" ${mainClass})
SET_TESTS_PROPERTIES(${testName} PROPERTIES ENVIRONMENT "PATH=${Ceda_BIN}")
else()
# On Linux the .so files created in this project live in ${Ceda_LIB}
# so we set java.library.path to this location
# On Linux the separator is : not ;
string(REPLACE ";" ":" jarFilesList "${jarFilesList}")
message("Adding test: ${Java_JAVA_EXECUTABLE} -Djava.library.path=${Ceda_LIB} -cp ${jarFilesList} ${mainClass}")
add_test(
NAME ${testName}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMAND ${Java_JAVA_EXECUTABLE} -Djava.library.path=${Ceda_LIB} -cp "${jarFilesList}" ${mainClass})
endif()
endif()
endfunction()