Logo AND Algorithmique Numérique Distribuée

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