Logo AND Algorithmique Numérique Distribuée

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