Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
c6a77b79bb804b2919c1cc6ef035889f5844cd95
[simgrid.git] / buildtools / Cmake / MakeJava.cmake
1 cmake_minimum_required(VERSION 2.8.6)
2
3 include(UseJava)
4
5 # Rules to build libSG_java
6 #
7 add_library(SG_java SHARED ${JMSG_C_SRC})
8 set_target_properties(SG_java PROPERTIES VERSION ${libSG_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 SG_java INCLUDE_DIRECTORIES)
16   if (COMMON_INCLUDES)
17     set_target_properties(SG_java PROPERTIES
18       INCLUDE_DIRECTORIES "${COMMON_INCLUDES};${JNI_INCLUDE_DIRS}")
19   else()
20     set_target_properties(SG_java PROPERTIES
21       INCLUDE_DIRECTORIES "${JNI_INCLUDE_DIRS}")
22   endif()
23   add_dependencies(SG_java simgrid)
24
25   get_target_property(CHECK_INCLUDES SG_java INCLUDE_DIRECTORIES)
26 endif()
27 message("-- [Java] SG_java includes: ${CHECK_INCLUDES}")
28
29 target_link_libraries(SG_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(SG_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 SG_java POST_BUILD
49       COMMAND ${PEXPORTS_PATH}/pexports.exe ${CMAKE_BINARY_DIR}/lib/SG_java.dll > ${CMAKE_BINARY_DIR}/lib/SG_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(MANIFEST_FILE "${CMAKE_HOME_DIRECTORY}/src/bindings/java/MANIFEST.MF")
60 set(LIBSIMGRID_SO
61   libsimgrid${CMAKE_SHARED_LIBRARY_SUFFIX})
62 set(LIBSG_JAVA_SO
63   ${CMAKE_SHARED_LIBRARY_PREFIX}SG_java${CMAKE_SHARED_LIBRARY_SUFFIX})
64
65 ## Name of the "NATIVE" folder in simgrid.jar
66 ##
67 if(CMAKE_SYSTEM_PROCESSOR MATCHES ".86")
68   if(${ARCH_32_BITS})
69     set(JSG_BUNDLE "NATIVE/${CMAKE_SYSTEM_NAME}/i386/")
70   else()
71     set(JSG_BUNDLE "NATIVE/${CMAKE_SYSTEM_NAME}/amd64/")
72   endif()
73 else()
74   message(WARNING "Unknown system type. Processor: ${CMAKE_SYSTEM_PROCESSOR}; System: ${CMAKE_SYSTEM_NAME}")
75   set(JSG_BUNDLE "NATIVE/${CMAKE_SYSTEM_NAME}/${CMAKE_SYSTEM_PROCESSOR}/")
76 endif()
77 message("-- [Java] Native libraries bundled into: ${JSG_BUNDLE}")
78
79 ## Don't strip libraries if not in release mode
80 ##
81 if(release)
82   set(STRIP_COMMAND "${CMAKE_STRIP}")
83 else()
84   set(STRIP_COMMAND "true")
85 endif()
86
87 ## Here is how to build simgrid.jar
88 ##
89 set(CMAKE_JAVA_TARGET_OUTPUT_NAME simgrid)
90 add_jar(SG_java_pre_jar ${JMSG_JAVA_SRC})
91
92 add_custom_command(
93   COMMENT "Finalize simgrid.jar..."
94   OUTPUT ${SIMGRID_JAR}_finalized
95   DEPENDS simgrid SG_java SG_java_pre_jar
96           ${SIMGRID_JAR} ${MANIFEST_FILE}
97           ${CMAKE_BINARY_DIR}/lib/${LIBSIMGRID_SO}
98           ${CMAKE_BINARY_DIR}/lib/${LIBSG_JAVA_SO}
99           ${CMAKE_HOME_DIRECTORY}/COPYING
100           ${CMAKE_HOME_DIRECTORY}/ChangeLog
101           ${CMAKE_HOME_DIRECTORY}/ChangeLog.SimGrid-java
102           ${CMAKE_HOME_DIRECTORY}/LICENSE-LGPL-2.1
103   COMMAND ${CMAKE_COMMAND} -E remove_directory "NATIVE"
104   COMMAND ${CMAKE_COMMAND} -E make_directory "${JSG_BUNDLE}"
105   COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_BINARY_DIR}/lib/${LIBSIMGRID_SO}" "${JSG_BUNDLE}"
106   COMMAND ${STRIP_COMMAND} -S "${JSG_BUNDLE}/${LIBSIMGRID_SO}"
107   COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_BINARY_DIR}/lib/${LIBSG_JAVA_SO}" "${JSG_BUNDLE}"
108   COMMAND ${STRIP_COMMAND} -S "${JSG_BUNDLE}/${LIBSG_JAVA_SO}"
109   COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_HOME_DIRECTORY}/COPYING" "${JSG_BUNDLE}"
110   COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_HOME_DIRECTORY}/ChangeLog" "${JSG_BUNDLE}"
111   COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_HOME_DIRECTORY}/ChangeLog.SimGrid-java" "${JSG_BUNDLE}"
112   COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_HOME_DIRECTORY}/LICENSE-LGPL-2.1" "${JSG_BUNDLE}"
113   COMMAND ${JAVA_ARCHIVE} -uvmf ${MANIFEST_FILE} ${SIMGRID_JAR} "NATIVE"
114   COMMAND ${CMAKE_COMMAND} -E remove ${SIMGRID_JAR}_finalized
115   COMMAND ${CMAKE_COMMAND} -E touch ${SIMGRID_JAR}_finalized
116   )
117 add_custom_target(SG_java_jar ALL DEPENDS ${SIMGRID_JAR}_finalized)