Commit 6dfa3096 authored by Brian Panneton's avatar Brian Panneton Committed by Kenneth Leiter

Relocated and improved Java and Python SWIG Wrappers

This commit moves both Java and Python add_package to the Top Level.
It also contains macros to swig Java and Python. This is because
we end up doing the same thing inside core and outside core for both.
parent 10bb623c
......@@ -10,6 +10,75 @@ SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMake ${CMAKE_CURRENT_SOURCE_DIR}/core/CMake)
# Wrapper Setup
option(XDMF_WRAP_PYTHON OFF)
option(XDMF_WRAP_JAVA OFF)
# If we are wrapping either, we need swig
if(XDMF_WRAP_PYTHON OR XDMF_WRAP_JAVA)
find_package(SWIG REQUIRED)
include(${SWIG_USE_FILE})
endif(XDMF_WRAP_PYTHON OR XDMF_WRAP_JAVA)
# If we are wrapping python, let's include it in the top level
if(XDMF_WRAP_PYTHON)
find_package(PythonLibs REQUIRED)
include_directories(${PYTHON_INCLUDE_DIRS})
# A macro to swig and create the python files
# Since we essentually do the same thing inside and outside core, it
# would be easier as a macro
MACRO(XDMF_SWIG_PYTHON python_name)
set(CMAKE_SWIG_OUTDIR ${CMAKE_BINARY_DIR})
set_source_files_properties(${python_name}.i PROPERTIES CPLUSPLUS ON)
swig_add_module(${python_name} python ${python_name}.i)
swig_link_libraries(${python_name} ${python_name} ${PYTHON_LIBRARIES})
install(FILES ${CMAKE_BINARY_DIR}/Xdmf.py DESTINATION lib/python)
install(TARGETS ${SWIG_MODULE_Xdmf_REAL_NAME} DESTINATION lib/python)
ENDMACRO(XDMF_SWIG_PYTHON)
XDMF_SWIG_PYTHON(Xdmf)
endif(XDMF_WRAP_PYTHON)
# If we are wrapping java, let's include it in the top level
if(XDMF_WRAP_JAVA)
find_package(Java REQUIRED)
find_package(JNI REQUIRED)
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PATH2})
# A macro to swig and create the jar files
# Since we essentually do the same thing inside and outside core, it
# would be easier as a macro
MACRO(XDMF_SWIG_JAVA java_name java_classpath)
set(XDMF_JAVA_PACKAGE_DIR mil/army/arl/xdmf)
set(XDMF_JAVA_DIR ${CMAKE_CURRENT_BINARY_DIR}/${XDMF_JAVA_PACKAGE_DIR})
file(MAKE_DIRECTORY ${XDMF_JAVA_DIR})
set(CMAKE_SWIG_OUTDIR ${XDMF_JAVA_DIR})
set(CMAKE_SWIG_FLAGS -v -make_default -package mil.army.arl.xdmf)
set_source_files_properties(${java_name}.i PROPERTIES CPLUSPLUS ON)
swig_add_module(${java_name}Java java ${java_name}.i)
swig_link_libraries(${java_name}Java ${java_name})
if("${ARGN}" STRGREATER "")
add_dependencies(${java_name}Java "${ARGN}")
endif("${ARGN}" STRGREATER "")
add_custom_command(TARGET ${java_name}Java
POST_BUILD
COMMAND ${JAVA_COMPILE}
ARGS -cp "'${java_classpath}'"
"${XDMF_JAVA_DIR}/*.java"
COMMAND ${JAVA_ARCHIVE}
ARGS -cvf ${CMAKE_BINARY_DIR}/${java_name}.jar
"${XDMF_JAVA_PACKAGE_DIR}/*.class"
)
ENDMACRO(XDMF_SWIG_JAVA)
XDMF_SWIG_JAVA(Xdmf "core" XdmfCoreJava)
set(XDMF_JAVA_JAR ${CMAKE_BINARY_DIR}/Xdmf.jar CACHE INTERNAL "")
endif(XDMF_WRAP_JAVA)
add_subdirectory(core)
include_directories(${XdmfCore_INCLUDE_DIRS})
include_directories(tests/Cxx)
......@@ -42,43 +111,6 @@ if(XDMF_BUILD_DOCUMENTATION)
add_subdirectory(doc)
endif(XDMF_BUILD_DOCUMENTATION)
if(XDMF_WRAP_PYTHON)
find_package(SWIG REQUIRED)
include(${SWIG_USE_FILE})
find_package(PythonLibs REQUIRED)
include_directories(${PYTHON_INCLUDE_DIRS})
set(CMAKE_SWIG_OUTDIR ${CMAKE_BINARY_DIR})
set_source_files_properties(Xdmf.i PROPERTIES CPLUSPLUS ON)
swig_add_module(Xdmf python Xdmf.i)
swig_link_libraries(Xdmf Xdmf ${PYTHON_LIBRARIES})
install(FILES ${CMAKE_BINARY_DIR}/Xdmf.py DESTINATION lib/python)
install(TARGETS ${SWIG_MODULE_Xdmf_REAL_NAME} DESTINATION lib/python)
endif(XDMF_WRAP_PYTHON)
if(XDMF_WRAP_JAVA)
find_package(SWIG REQUIRED)
include(${SWIG_USE_FILE})
set(CMAKE_SWIG_OUTDIR ${CMAKE_BINARY_DIR})
set_source_files_properties(Xdmf.i PROPERTIES CPLUSPLUS ON)
find_package(Java REQUIRED)
find_package(JNI REQUIRED)
set(CMAKE_SWIG_FLAGS -v -make_default -package mil.army.arl.xdmf)
set(XDMF_JAVA_PACKAGE_DIR mil/army/arl/xdmf)
set(XDMF_JAVA_DIR ${CMAKE_CURRENT_BINARY_DIR}/${XDMF_JAVA_PACKAGE_DIR})
file(MAKE_DIRECTORY ${XDMF_JAVA_DIR})
set(CMAKE_SWIG_OUTDIR ${XDMF_JAVA_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PATH2})
swig_add_module(XdmfJava java Xdmf.i)
swig_link_libraries(XdmfJava Xdmf)
add_dependencies(XdmfJava XdmfCoreJava)
set(XDMF_JAVA_JAR ${CMAKE_BINARY_DIR}/Xdmf.jar CACHE INTERNAL "")
add_custom_command(TARGET XdmfJava
POST_BUILD
DEPENDS ${XDMF_CORE_JAVA_JAR}
COMMAND ${JAVA_COMPILE} ARGS -cp ${XDMF_CORE_JAVA_JAR} "${CMAKE_CURRENT_BINARY_DIR}/mil/army/arl/xdmf/*.java"
COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_CURRENT_BINARY_DIR} ${JAVA_ARCHIVE} -cvf ${XDMF_JAVA_JAR} "mil/army/arl/xdmf/*.class")
endif(XDMF_WRAP_JAVA)
option(XDMF_BUILD_UTILS OFF)
if(XDMF_BUILD_UTILS)
add_subdirectory(utils)
......
......@@ -49,40 +49,13 @@ if(XDMF_BUILD_TESTING)
add_subdirectory(tests)
endif(XDMF_BUILD_TESTING)
option(XDMF_WRAP_JAVA "Wrap Xdmf with Java" ON)
if(XDMF_WRAP_JAVA)
find_package(SWIG REQUIRED)
include(${SWIG_USE_FILE})
find_package(Java REQUIRED)
find_package(JNI REQUIRED)
set(CMAKE_SWIG_FLAGS -v -make_default -package mil.army.arl.xdmf)
set(XDMF_CORE_JAVA_PACKAGE_DIR mil/army/arl/xdmf)
set(XDMF_CORE_JAVA_DIR ${CMAKE_CURRENT_BINARY_DIR}/${XDMF_CORE_JAVA_PACKAGE_DIR})
file(MAKE_DIRECTORY ${XDMF_CORE_JAVA_DIR})
set(CMAKE_SWIG_OUTDIR ${XDMF_CORE_JAVA_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PATH2})
set_source_files_properties(XdmfCore.i PROPERTIES CPLUSPLUS ON)
swig_add_module(XdmfCoreJava java XdmfCore.i)
swig_link_libraries(XdmfCoreJava XdmfCore)
XDMF_SWIG_JAVA(XdmfCore "")
set(XDMF_CORE_JAVA_JAR ${CMAKE_BINARY_DIR}/XdmfCore.jar CACHE INTERNAL "")
add_custom_command(TARGET XdmfCoreJava
POST_BUILD
COMMAND ${JAVA_COMPILE} ARGS "${CMAKE_CURRENT_BINARY_DIR}/mil/army/arl/xdmf/*.java"
COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_CURRENT_BINARY_DIR} ${JAVA_ARCHIVE} -cvf ${XDMF_CORE_JAVA_JAR} "mil/army/arl/xdmf/*.class")
endif(XDMF_WRAP_JAVA)
option(XDMF_WRAP_PYTHON OFF)
if(XDMF_WRAP_PYTHON)
find_package(SWIG REQUIRED)
include(${SWIG_USE_FILE})
find_package(PythonLibs REQUIRED)
include_directories(${PYTHON_INCLUDE_DIRS})
set(CMAKE_SWIG_OUTDIR ${CMAKE_BINARY_DIR})
set_source_files_properties(XdmfCore.i PROPERTIES CPLUSPLUS ON)
swig_add_module(XdmfCore python XdmfCore.i)
swig_link_libraries(XdmfCore XdmfCore ${PYTHON_LIBRARIES})
install(FILES ${CMAKE_BINARY_DIR}/XdmfCore.py DESTINATION lib/python)
install(TARGETS ${SWIG_MODULE_XdmfCore_REAL_NAME} DESTINATION lib/python)
XDMF_SWIG_PYTHON(XdmfCore)
endif(XDMF_WRAP_PYTHON)
file(GLOB XdmfCoreHeaders *.hpp)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment