Skip to content

Commit

Permalink
- do not force java 1.6 compatibility by default
Browse files Browse the repository at this point in the history
  • Loading branch information
fbergmann committed Mar 7, 2022
1 parent a7a3819 commit d5b2e96
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 47 deletions.
65 changes: 34 additions & 31 deletions examples/java/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,40 +35,43 @@
find_package(Java COMPONENTS Development REQUIRED)


if (JAVA_COMPATIBILITY)
SET(COMPAT_ARGS "-source ${JAVA_COMPATIBILITY} -target ${JAVA_COMPATIBILITY}")
endif()

foreach( example
create_sedml
echo_sedml
print_sedml
create_sedml
echo_sedml
print_sedml
)

file(TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR} CURRENT_BIN)
file(TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR}/../../src/bindings/java/libsedmlj.jar CURRENT_JAR )
file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/${example}.java CURRENT_FILE)
file(TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR} CURRENT_BIN)
file(TO_NATIVE_PATH ${CMAKE_CURRENT_BINARY_DIR}/../../src/bindings/java/libsedmlj.jar CURRENT_JAR )
file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/${example}.java CURRENT_FILE)

add_custom_command(
OUTPUT ${example}.class
COMMAND "${Java_JAVAC_EXECUTABLE}"
ARGS -cp ".${FILE_SEP}\"${CURRENT_JAR}\"${FILE_SEP}${CMAKE_CURRENT_SOURCE_DIR}"
${CURRENT_FILE}
-source 1.6
-target 1.6
-d ${CMAKE_CURRENT_BINARY_DIR}
MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/../../src/bindings/java/local.i"
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${example}.java
COMMENT "Build java example ${example}"
)

add_custom_target(example_java_${example} ALL
DEPENDS
${CMAKE_CURRENT_BINARY_DIR}/${example}.class
SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/${example}.java
)

add_dependencies(example_java_${example} binding_java_jar)
add_custom_command(
OUTPUT ${example}.class
COMMAND "${Java_JAVAC_EXECUTABLE}"
ARGS -cp ".${FILE_SEP}\"${CURRENT_JAR}\"${FILE_SEP}${CMAKE_CURRENT_SOURCE_DIR}"
${CURRENT_FILE}
${COMPAT_ARGS}
-d ${CMAKE_CURRENT_BINARY_DIR}
MAIN_DEPENDENCY "${CMAKE_CURRENT_SOURCE_DIR}/../../src/bindings/java/local.i"
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${example}.java
COMMENT "Build java example ${example}"
)

add_custom_target(example_java_${example} ALL
DEPENDS
${CMAKE_CURRENT_BINARY_DIR}/${example}.class
SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/${example}.java
)

add_dependencies(example_java_${example} binding_java_jar)

endforeach()
5 changes: 5 additions & 0 deletions src/bindings/java/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ install(TARGETS binding_java_lib DESTINATION ${JAVA_PACKAGE_BIN_INSTALL_DIR} )

target_link_libraries(binding_java_lib ${LIBSEDML_LIBRARY}-static )

set(JAVA_COMPATIBILITY "" CACHE STRING
"Specify the source and target compatibility for the libsbml Java bindings (for example 1.7). Leave empty to remove the parameter altogether.")


ADD_CUSTOM_COMMAND(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/libsedmlj.jar
COMMAND "${CMAKE_COMMAND}"
Expand All @@ -167,6 +171,7 @@ ADD_CUSTOM_COMMAND(
-DSRC_DIRECTORY=\"${CMAKE_CURRENT_SOURCE_DIR}\"
-DFILE_SEP=\"${FILE_SEP}\"
-DPATH_SEP=${PATH_SEP}
-DCOMPATIBILIY=${JAVA_COMPATIBILITY}
-P "${CMAKE_CURRENT_SOURCE_DIR}/compile-native-files.cmake"

WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
Expand Down
37 changes: 21 additions & 16 deletions src/bindings/java/compile-native-files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,40 +41,45 @@ file(GLOB_RECURSE SOURCE_FILES RELATIVE ${BIN_DIRECTORY} ${BIN_DIRECTORY}/java-f
# convert paths
set(NATIVE_FILES)
foreach(javaFile ${SOURCE_FILES})
file(TO_NATIVE_PATH ${javaFile} temp)
set(NATIVE_FILES ${NATIVE_FILES} ${temp})
file(TO_NATIVE_PATH ${javaFile} temp)
set(NATIVE_FILES ${NATIVE_FILES} ${temp})
endforeach()

# delete file if it exists
if (EXISTS ${BIN_DIRECTORY}/libsedml.jar)
file(REMOVE ${BIN_DIRECTORY}/libsedml.jar)
file(REMOVE ${BIN_DIRECTORY}/libsedml.jar)
endif()

SET (COMPATIBILITY_ARGS)
if (COMPATIBILIY)
SET (COMPATIBILITY_ARGS ${COMPATIBILITY_ARGS} -source ${COMPATIBILIY} -target ${COMPATIBILIY})
endif()


# compile files
execute_process(
COMMAND "${Java_JAVAC_EXECUTABLE}"
-source 1.6
-target 1.6
-d java-files
${NATIVE_FILES}
WORKING_DIRECTORY "${BIN_DIRECTORY}"
COMMAND "${Java_JAVAC_EXECUTABLE}"
${COMPATIBILITY_ARGS}
-d java-files
${NATIVE_FILES}
WORKING_DIRECTORY "${BIN_DIRECTORY}"
)

# enumerate class files
file(GLOB_RECURSE CLASS_FILES RELATIVE ${BIN_DIRECTORY}/java-files ${BIN_DIRECTORY}/java-files/org/sedml/libsedml/*.class)
set(NATIVE_CLASS_FILES)
foreach(classFile ${CLASS_FILES})
file(TO_NATIVE_PATH ${classFile} temp)
set(NATIVE_CLASS_FILES ${NATIVE_CLASS_FILES} ${temp})
file(TO_NATIVE_PATH ${classFile} temp)
set(NATIVE_CLASS_FILES ${NATIVE_CLASS_FILES} ${temp})
endforeach()

# create jar
execute_process(
COMMAND "${Java_JAR_EXECUTABLE}"
-cvfm ..${PATH_SEP}libsedmlj.jar
../Manifest.txt
${NATIVE_CLASS_FILES}
WORKING_DIRECTORY "${BIN_DIRECTORY}/java-files"
COMMAND "${Java_JAR_EXECUTABLE}"
-cvfm ..${PATH_SEP}libsedmlj.jar
../Manifest.txt
${NATIVE_CLASS_FILES}
WORKING_DIRECTORY "${BIN_DIRECTORY}/java-files"
)

# # print variables for debug purposes
Expand Down

0 comments on commit d5b2e96

Please sign in to comment.