Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
a861c109fc097a43d7d8d05936eb9c371fb79f97
[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 if(WIN32)
30   get_target_property(SIMGRID_LIB_NAME_NAME SG_java LIBRARY_OUTPUT_NAME)
31   set_target_properties(SG_java PROPERTIES
32     LINK_FLAGS "-Wl,--subsystem,windows,--kill-at ${SIMGRID_LIB_NAME}"
33     PREFIX "")
34   find_path(PEXPORTS_PATH NAMES pexports.exe PATHS NO_DEFAULT_PATHS)
35   message(STATUS "pexports: ${PEXPORTS_PATH}")
36   if(PEXPORTS_PATH)
37     add_custom_command(TARGET SG_java POST_BUILD
38       COMMAND ${PEXPORTS_PATH}/pexports.exe ${CMAKE_BINARY_DIR}/SG_java.dll > ${CMAKE_BINARY_DIR}/SG_java.def)
39   endif(PEXPORTS_PATH)
40 else()
41   target_link_libraries(SG_java simgrid)
42 endif()
43
44 # Rules to build simgrid.jar
45 #
46
47 ## Files to include in simgrid.jar
48 ##
49 set(SIMGRID_JAR "${CMAKE_BINARY_DIR}/simgrid.jar")
50 set(MANIFEST_FILE "${CMAKE_HOME_DIRECTORY}/src/bindings/java/MANIFEST.MF")
51 set(LIBSIMGRID_SO
52   ${CMAKE_SHARED_LIBRARY_PREFIX}simgrid${CMAKE_SHARED_LIBRARY_SUFFIX})
53 set(LIBSG_JAVA_SO
54   ${CMAKE_SHARED_LIBRARY_PREFIX}SG_java${CMAKE_SHARED_LIBRARY_SUFFIX})
55
56 ## Name of the "NATIVE" folder in simgrid.jar
57 ##
58 if(CMAKE_SYSTEM_PROCESSOR MATCHES ".86")
59   if(${ARCH_32_BITS})
60     set(JSG_BUNDLE "NATIVE/${CMAKE_SYSTEM_NAME}/i386/")
61   else()
62     set(JSG_BUNDLE "NATIVE/${CMAKE_SYSTEM_NAME}/amd64/")
63   endif()
64 else()
65   message(WARNING "Unknown system type. Processor: ${CMAKE_SYSTEM_PROCESSOR}; System: ${CMAKE_SYSTEM_NAME}")
66   set(JSG_BUNDLE "NATIVE/${CMAKE_SYSTEM_NAME}/${CMAKE_SYSTEM_PROCESSOR/")
67 endif()
68 message("-- [Java] Native libraries bundled into: ${JSG_BUNDLE}")
69
70 ## Don't strip libraries if not in release mode
71 ##
72 if(release)
73   set(STRIP_COMMAND "${CMAKE_STRIP}")
74 else()
75   set(STRIP_COMMAND "true")
76 endif()
77
78 ## Here is how to build simgrid.jar
79 ##
80 set(CMAKE_JAVA_TARGET_OUTPUT_NAME simgrid)
81 add_jar(SG_java_pre_jar ${JMSG_JAVA_SRC})
82
83 add_custom_command(
84   COMMENT "Finalize simgrid.jar..."
85   OUTPUT ${SIMGRID_JAR}_finalized
86   DEPENDS simgrid SG_java SG_java_pre_jar
87           ${SIMGRID_JAR} ${MANIFEST_FILE}
88           ${CMAKE_BINARY_DIR}/lib/${LIBSIMGRID_SO}
89           ${CMAKE_BINARY_DIR}/lib/${LIBSG_JAVA_SO}
90           ${CMAKE_HOME_DIRECTORY}/COPYING
91           ${CMAKE_HOME_DIRECTORY}/ChangeLog
92           ${CMAKE_HOME_DIRECTORY}/ChangeLog.SimGrid-java
93           ${CMAKE_HOME_DIRECTORY}/LICENSE-LGPL-2.1
94   COMMAND ${CMAKE_COMMAND} -E remove_directory "NATIVE"
95   COMMAND ${CMAKE_COMMAND} -E make_directory "${JSG_BUNDLE}"
96   COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_BINARY_DIR}/lib/${LIBSIMGRID_SO}" "${JSG_BUNDLE}"
97   COMMAND ${STRIP_COMMAND} -S "${JSG_BUNDLE}/${LIBSIMGRID_SO}"
98   COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_BINARY_DIR}/lib/${LIBSG_JAVA_SO}" "${JSG_BUNDLE}"
99   COMMAND ${STRIP_COMMAND} -S "${JSG_BUNDLE}/${LIBSG_JAVA_SO}"
100   COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_HOME_DIRECTORY}/COPYING" "${JSG_BUNDLE}"
101   COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_HOME_DIRECTORY}/ChangeLog" "${JSG_BUNDLE}"
102   COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_HOME_DIRECTORY}/ChangeLog.SimGrid-java" "${JSG_BUNDLE}"
103   COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_HOME_DIRECTORY}/LICENSE-LGPL-2.1" "${JSG_BUNDLE}"
104   COMMAND ${JAVA_ARCHIVE} -uvmf ${MANIFEST_FILE} ${SIMGRID_JAR} "NATIVE"
105   COMMAND ${CMAKE_COMMAND} -E remove ${SIMGRID_JAR}_finalized
106   COMMAND ${CMAKE_COMMAND} -E touch ${SIMGRID_JAR}_finalized
107   )
108 add_custom_target(SG_java_jar ALL DEPENDS ${SIMGRID_JAR}_finalized)