Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
63e64200e52cc1ffb69eda2936eab9f29e24d013
[simgrid.git] / buildtools / Cmake / MakeJava.cmake
1 cmake_minimum_required(VERSION 2.8.6)
2
3 include(UseJava)
4
5 # Rules to build libsimgrid-java
6 #
7 add_library(simgrid-java SHARED ${JMSG_C_SRC})
8 set_target_properties(simgrid-java PROPERTIES VERSION ${libsimgrid-java_version})
9 if (CMAKE_VERSION VERSION_LESS "2.8.8")
10   include_directories(${JNI_INCLUDE_DIRS})
11
12   message(WARNING "[Java] Try to workaround missing feature in older CMake.  You should better update CMake to version 2.8.8 or above.")
13   get_directory_property(CHECK_INCLUDES INCLUDE_DIRECTORIES)
14 else()
15   get_target_property(COMMON_INCLUDES simgrid-java INCLUDE_DIRECTORIES)
16   if (COMMON_INCLUDES)
17     set_target_properties(simgrid-java PROPERTIES
18       INCLUDE_DIRECTORIES "${COMMON_INCLUDES};${JNI_INCLUDE_DIRS}")
19   else()
20     set_target_properties(simgrid-java PROPERTIES
21       INCLUDE_DIRECTORIES "${JNI_INCLUDE_DIRS}")
22   endif()
23   add_dependencies(simgrid-java simgrid)
24
25   get_target_property(CHECK_INCLUDES simgrid-java INCLUDE_DIRECTORIES)
26 endif()
27 message("-- [Java] simgrid-java includes: ${CHECK_INCLUDES}")
28
29 target_link_libraries(simgrid-java simgrid)
30
31
32 if(WIN32)
33   exec_program("java -d32 -version"
34                 OUTPUT_VARIABLE IS_32_BITS_JVM)
35   STRING( FIND ${IS_32_BITS_JVM} "Error" POSITION )
36   if(${POSITION} GREATER -1) 
37     message(FATAL_ERROR "Java JVM needs to be 32 bits to be able to run with Simgrid on Windows for now")
38   endif()
39
40   set_target_properties(simgrid-java PROPERTIES
41     LINK_FLAGS "-Wl,--subsystem,windows,--kill-at"
42     PREFIX "")
43   find_path(PEXPORTS_PATH NAMES pexports.exe PATHS NO_DEFAULT_PATHS)
44   message(STATUS "pexports: ${PEXPORTS_PATH}")
45   if(PEXPORTS_PATH)
46     add_custom_command(TARGET simgrid-java POST_BUILD
47       COMMAND ${PEXPORTS_PATH}/pexports.exe ${CMAKE_BINARY_DIR}/lib/simgrid-java.dll > ${CMAKE_BINARY_DIR}/lib/simgrid-java.def)
48   endif(PEXPORTS_PATH)
49 endif()
50
51 # Rules to build simgrid.jar
52 #
53
54 ## Files to include in simgrid.jar
55 ##
56 set(SIMGRID_JAR "${CMAKE_BINARY_DIR}/simgrid.jar")
57 set(SIMGRID_FULL_JAR "${CMAKE_BINARY_DIR}/simgrid_full.jar")
58 set(MANIFEST_IN_FILE "${CMAKE_HOME_DIRECTORY}/src/bindings/java/MANIFEST.MF.in")
59 set(MANIFEST_FILE "${CMAKE_BINARY_DIR}/src/bindings/java/MANIFEST.MF")
60
61
62 set(LIBSIMGRID_SO
63   libsimgrid${CMAKE_SHARED_LIBRARY_SUFFIX})
64 set(LIBSIMGRID_JAVA_SO
65   ${CMAKE_SHARED_LIBRARY_PREFIX}simgrid-java${CMAKE_SHARED_LIBRARY_SUFFIX})
66 set(LIBSURF_JAVA_SO
67   ${CMAKE_SHARED_LIBRARY_PREFIX}surf-java.so)
68
69 ## Don't strip libraries if not in release mode
70 ##
71 if(release)
72   set(STRIP_COMMAND "${CMAKE_STRIP}")
73 else()
74   set(STRIP_COMMAND "true")
75 endif()
76
77 ## Here is how to build simgrid.jar
78 ##
79 if(CMAKE_VERSION VERSION_LESS "2.8.12")
80   set(CMAKE_JAVA_TARGET_OUTPUT_NAME simgrid)
81   add_jar(simgrid-java_pre_jar ${JMSG_JAVA_SRC})
82 else()
83   add_jar(simgrid-java_pre_jar ${JMSG_JAVA_SRC} OUTPUT_NAME simgrid)
84 endif()
85
86 set(JAVA_BUNDLE "${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Scripts/java_bundle.sh")
87 set(JAVA_BUNDLE_SO_FILES
88   ${CMAKE_BINARY_DIR}/lib/${LIBSIMGRID_SO}
89   ${CMAKE_BINARY_DIR}/lib/${LIBSIMGRID_JAVA_SO}
90   ${CMAKE_BINARY_DIR}/lib/${LIBSURF_JAVA_SO}
91   )
92 set(JAVA_BUNDLE_TXT_FILES
93   ${CMAKE_HOME_DIRECTORY}/COPYING
94   ${CMAKE_HOME_DIRECTORY}/ChangeLog
95   ${CMAKE_HOME_DIRECTORY}/ChangeLog.SimGrid-java
96   ${CMAKE_HOME_DIRECTORY}/LICENSE-LGPL-2.1
97   )
98 add_custom_command(
99   COMMENT "Finalize simgrid.jar..."
100   OUTPUT ${SIMGRID_JAR}_finalized
101   DEPENDS simgrid simgrid-java simgrid-java_pre_jar
102           ${SIMGRID_JAR} ${MANIFEST_IN_FILE}
103           ${JAVA_BUNDLE_SO_FILES} ${JAVA_BUNDLE_TXT_FILES}
104   COMMAND ${JAVA_BUNDLE} "${SIMGRID_JAR}" "${Java_JAVA_EXECUTABLE}" "${STRIP_COMMAND}" -so ${JAVA_BUNDLE_SO_FILES} -txt ${JAVA_BUNDLE_TXT_FILES}
105   COMMAND ${CMAKE_COMMAND} -E copy ${MANIFEST_IN_FILE} ${MANIFEST_FILE}
106   COMMAND ${CMAKE_COMMAND} -E echo "Specification-Version: \\\"${SIMGRID_VERSION_MAJOR}.${SIMGRID_VERSION_MINOR}.${SIMGRID_VERSION_PATCH}\\\"" >> ${MANIFEST_FILE}
107   COMMAND ${CMAKE_COMMAND} -E echo "Implementation-Version: \\\"${GIT_VERSION}\\\"" >> ${MANIFEST_FILE}
108   COMMAND ${JAVA_ARCHIVE} -uvmf ${MANIFEST_FILE} ${SIMGRID_JAR}
109   COMMAND ${CMAKE_COMMAND} -E copy ${SIMGRID_JAR} ${SIMGRID_FULL_JAR}
110   COMMAND ${JAVA_ARCHIVE} -uvf ${SIMGRID_FULL_JAR} "NATIVE"
111   COMMAND ${CMAKE_COMMAND} -E remove ${SIMGRID_JAR}_finalized
112   COMMAND ${CMAKE_COMMAND} -E touch ${SIMGRID_JAR}_finalized
113   )
114 add_custom_target(simgrid-java_jar ALL DEPENDS ${SIMGRID_JAR}_finalized)
115
116 set(CMAKE_SWIG_FLAGS "-package" "org.simgrid.surf")
117 set(CMAKE_SWIG_OUTDIR "${CMAKE_HOME_DIRECTORY}/src/bindings/java/org/simgrid/surf")
118
119 set(SURF_SWIG_FILE "${CMAKE_HOME_DIRECTORY}/src/bindings/java/surf.i")
120 set_source_files_properties(${SURF_SWIG_FILE} PROPERTIES CPLUSPLUS 1)
121 #set_source_files_properties(${SURF_SWIG_FILE} PROPERTIES SWIG_FLAGS "-includeall")
122 include_directories(${JNI_INCLUDE_DIRS})
123 swig_add_module(surf-java java ${SURF_SWIG_FILE} "${CMAKE_HOME_DIRECTORY}/src/surf/surf_interface.hpp" "${CMAKE_HOME_DIRECTORY}/src/bindings/java/surf_swig.hpp" "${CMAKE_HOME_DIRECTORY}/src/bindings/java/surf_swig.cpp")
124 swig_link_libraries(surf-java simgrid)
125
126 add_dependencies(simgrid-java surf-java)