Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
f1c43dedbfc6129293b07d71330379e295bca41d
[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
33
34 if(WIN32)
35   exec_program("java -d32 -version"
36                 OUTPUT_VARIABLE IS_32_BITS_JVM)
37   STRING( FIND ${IS_32_BITS_JVM} "Error" POSITION )
38   if(${POSITION} GREATER -1) 
39     message(FATAL_ERROR "Java JVM needs to be 32 bits to be able to run with Simgrid on Windows for now")
40   endif()
41
42   set_target_properties(simgrid-java PROPERTIES
43     LINK_FLAGS "-Wl,--subsystem,windows,--kill-at"
44     PREFIX "")
45   find_path(PEXPORTS_PATH NAMES pexports.exe PATHS NO_DEFAULT_PATHS)
46   message(STATUS "pexports: ${PEXPORTS_PATH}")
47   if(PEXPORTS_PATH)
48     add_custom_command(TARGET simgrid-java POST_BUILD
49       COMMAND ${PEXPORTS_PATH}/pexports.exe ${CMAKE_BINARY_DIR}/lib/simgrid-java.dll > ${CMAKE_BINARY_DIR}/lib/simgrid-java.def)
50   endif(PEXPORTS_PATH)
51 endif()
52
53 # Rules to build simgrid.jar
54 #
55
56 ## Files to include in simgrid.jar
57 ##
58 set(SIMGRID_JAR "${CMAKE_BINARY_DIR}/simgrid.jar")
59 set(SIMGRID_FULL_JAR "${CMAKE_BINARY_DIR}/simgrid_full.jar")
60 set(MANIFEST_IN_FILE "${CMAKE_HOME_DIRECTORY}/src/bindings/java/MANIFEST.MF.in")
61 set(MANIFEST_FILE "${CMAKE_BINARY_DIR}/src/bindings/java/MANIFEST.MF")
62
63
64 set(LIBSIMGRID_SO
65   libsimgrid${CMAKE_SHARED_LIBRARY_SUFFIX})
66 set(LIBSIMGRID_JAVA_SO
67   ${CMAKE_SHARED_LIBRARY_PREFIX}simgrid-java${CMAKE_SHARED_LIBRARY_SUFFIX})
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   )
91 set(JAVA_BUNDLE_TXT_FILES
92   ${CMAKE_HOME_DIRECTORY}/COPYING
93   ${CMAKE_HOME_DIRECTORY}/ChangeLog
94   ${CMAKE_HOME_DIRECTORY}/ChangeLog.SimGrid-java
95   ${CMAKE_HOME_DIRECTORY}/LICENSE-LGPL-2.1
96   )
97 add_custom_command(
98   COMMENT "Finalize simgrid.jar..."
99   OUTPUT ${SIMGRID_JAR}_finalized
100   DEPENDS simgrid simgrid-java simgrid-java_pre_jar
101           ${SIMGRID_JAR} ${MANIFEST_IN_FILE}
102           ${JAVA_BUNDLE_SO_FILES} ${JAVA_BUNDLE_TXT_FILES}
103   COMMAND ${JAVA_BUNDLE} "${SIMGRID_JAR}" "${Java_JAVA_EXECUTABLE}" "${STRIP_COMMAND}" -so ${JAVA_BUNDLE_SO_FILES} -txt ${JAVA_BUNDLE_TXT_FILES}
104   COMMAND ${CMAKE_COMMAND} -E copy ${MANIFEST_IN_FILE} ${MANIFEST_FILE}
105   COMMAND ${CMAKE_COMMAND} -E echo "Specification-Version: \\\"${SIMGRID_VERSION_MAJOR}.${SIMGRID_VERSION_MINOR}.${SIMGRID_VERSION_PATCH}\\\"" >> ${MANIFEST_FILE}
106   COMMAND ${CMAKE_COMMAND} -E echo "Implementation-Version: \\\"${GIT_VERSION}\\\"" >> ${MANIFEST_FILE}
107   COMMAND ${JAVA_ARCHIVE} -uvmf ${MANIFEST_FILE} ${SIMGRID_JAR}
108   COMMAND ${CMAKE_COMMAND} -E copy ${SIMGRID_JAR} ${SIMGRID_FULL_JAR}
109   COMMAND ${JAVA_ARCHIVE} -uvf ${SIMGRID_FULL_JAR} "NATIVE"
110   COMMAND ${CMAKE_COMMAND} -E remove ${SIMGRID_JAR}_finalized
111   COMMAND ${CMAKE_COMMAND} -E touch ${SIMGRID_JAR}_finalized
112   )
113 add_custom_target(simgrid-java_jar ALL DEPENDS ${SIMGRID_JAR}_finalized)