Logo AND Algorithmique Numérique Distribuée

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