Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
valgrind version checking rule did not match 3.10.0
[simgrid.git] / tools / cmake / Java.cmake
1 ##
2 ## The Cmake definitions for the use of Java (and Scala)
3 ##   This file is loaded only if the Java option is activated
4 ##
5
6 find_package(Java 1.7 COMPONENTS Runtime Development)
7 if (NOT ${Java_FOUND})
8   message(FATAL_ERROR "Java not found (need at least Java7). Please install the JDK or disable that option")
9 endif()
10 set(Java_FOUND 1)
11 include(UseJava)
12
13 find_package(JNI REQUIRED)
14 message("-- [Java] JNI found: ${JNI_FOUND}")
15 message("-- [Java] JNI include dirs: ${JNI_INCLUDE_DIRS}")
16
17 if(WIN32)
18   exec_program("java -d32 -version" OUTPUT_VARIABLE IS_32_BITS_JVM)
19   STRING( FIND ${IS_32_BITS_JVM} "Error" POSITION )
20   if(NOT ${POSITION} GREATER -1)
21     message(fatal_error "SimGrid can only use Java 64 bits")
22   endif()
23 endif()
24
25 # find_package(SWIG)
26 # if(${SWIG_FOUND})
27 #   include(UseSWIG)
28 #   message("-- [Java] Swig found: version ${SWIG_VERSION}")
29 # else()
30 #   message("-- [Java] Swig NOT FOUND. That's fine unless you work on this part yourself.")
31 # endif()
32 #mark_as_advanced(SWIG_EXECUTABLE)
33
34 # Rules to build libsimgrid-java
35 ################################
36
37 add_library(simgrid-java SHARED ${JMSG_C_SRC})
38 set_target_properties(simgrid-java PROPERTIES VERSION          ${libsimgrid-java_version})
39 set_target_properties(simgrid-java PROPERTIES SKIP_BUILD_RPATH ON)
40
41 target_link_libraries(simgrid-java simgrid)
42
43 get_target_property(COMMON_INCLUDES simgrid-java INCLUDE_DIRECTORIES)
44 if (COMMON_INCLUDES)
45   set_target_properties(simgrid-java PROPERTIES
46     INCLUDE_DIRECTORIES "${COMMON_INCLUDES};${JNI_INCLUDE_DIRS}")
47 else()
48   set_target_properties(simgrid-java PROPERTIES
49     INCLUDE_DIRECTORIES "${JNI_INCLUDE_DIRS}")
50 endif()
51
52 get_target_property(CHECK_INCLUDES simgrid-java INCLUDE_DIRECTORIES)
53 message("-- [Java] simgrid-java includes: ${CHECK_INCLUDES}")
54
55 # Rules to build simgrid.jar
56 ############################
57
58 ## Files to include in simgrid.jar
59 ##
60 set(SIMGRID_JAR "${CMAKE_BINARY_DIR}/simgrid.jar")
61 set(MANIFEST_IN_FILE "${CMAKE_HOME_DIRECTORY}/src/bindings/java/MANIFEST.MF.in")
62 set(MANIFEST_FILE "${CMAKE_BINARY_DIR}/src/bindings/java/MANIFEST.MF")
63
64 set(LIBSIMGRID_SO
65   libsimgrid${CMAKE_SHARED_LIBRARY_SUFFIX})
66 set(LIBSIMGRID_JAVA_SO
67   ${CMAKE_SHARED_LIBRARY_PREFIX}simgrid-java${CMAKE_SHARED_LIBRARY_SUFFIX})
68
69 ## Here is how to build simgrid.jar
70 ##
71 if(CMAKE_VERSION VERSION_LESS "2.8.12")
72   set(CMAKE_JAVA_TARGET_OUTPUT_NAME simgrid)
73   add_jar(simgrid-java_jar ${JMSG_JAVA_SRC})
74 else()
75   add_jar(simgrid-java_jar ${JMSG_JAVA_SRC} OUTPUT_NAME simgrid)
76 endif()
77
78 add_dependencies(simgrid-java_jar simgrid-java)
79 add_dependencies(simgrid-java_jar simgrid)
80
81 if (enable_documentation)
82   add_custom_command(
83     TARGET simgrid-java_jar POST_BUILD
84     COMMENT "Add the documentation into simgrid.jar..."
85     DEPENDS ${MANIFEST_IN_FILE}
86             ${CMAKE_HOME_DIRECTORY}/COPYING
87             ${CMAKE_HOME_DIRECTORY}/ChangeLog
88             ${CMAKE_HOME_DIRECTORY}/NEWS
89             ${CMAKE_HOME_DIRECTORY}/ChangeLog.SimGrid-java
90             ${CMAKE_HOME_DIRECTORY}/LICENSE-LGPL-2.1
91
92     COMMAND ${CMAKE_COMMAND} -E copy ${MANIFEST_IN_FILE} ${MANIFEST_FILE}
93     COMMAND ${CMAKE_COMMAND} -E echo "Specification-Version: \\\"${SIMGRID_VERSION_MAJOR}.${SIMGRID_VERSION_MINOR}.${SIMGRID_VERSION_PATCH}\\\"" >> ${MANIFEST_FILE}
94     COMMAND ${CMAKE_COMMAND} -E echo "Implementation-Version: \\\"${GIT_VERSION}\\\"" >> ${MANIFEST_FILE}
95
96     COMMAND ${Java_JAVADOC_EXECUTABLE} -quiet -d doc/javadoc -sourcepath ${CMAKE_HOME_DIRECTORY}/src/bindings/java/ org.simgrid.msg org.simgrid.trace
97
98     COMMAND ${JAVA_ARCHIVE} -uvmf ${MANIFEST_FILE} ${SIMGRID_JAR} doc/javadoc
99     COMMAND ${JAVA_ARCHIVE} -uvf  ${SIMGRID_JAR} -C ${CMAKE_HOME_DIRECTORY} COPYING -C ${CMAKE_HOME_DIRECTORY} ChangeLog -C ${CMAKE_HOME_DIRECTORY} LICENSE-LGPL-2.1 -C ${CMAKE_HOME_DIRECTORY} NEWS
100   )
101 endif()
102
103 ###
104 ### Pack the java libraries into the jarfile if asked to do so
105 ###
106
107 if(enable_lib_in_jar)
108
109   # Stripping disabled for the time being to make Java debuggable. We should introduce a proper option for that.
110   #find_program(STRIP_COMMAND strip)
111   #mark_as_advanced(STRIP_COMMAND)
112   #if(NOT STRIP_COMMAND)
113   #  set(STRIP_COMMAND "cmake -E echo (strip not found)")
114   #endif()
115   
116   set(SG_SYSTEM_NAME ${CMAKE_SYSTEM_NAME})
117   
118   if(${SG_SYSTEM_NAME} MATCHES "kFreeBSD")
119     set(SG_SYSTEM_NAME GNU/kFreeBSD)
120   endif()
121
122   set(JAVA_NATIVE_PATH NATIVE/${SG_SYSTEM_NAME}/${CMAKE_SYSTEM_PROCESSOR})
123   if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "^i[3-6]86$")
124     set(JAVA_NATIVE_PATH NATIVE/${SG_SYSTEM_NAME}/x86)
125   endif()
126   if(  (${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64") OR
127        (${CMAKE_SYSTEM_PROCESSOR} MATCHES "AMD64")     )
128     set(JAVA_NATIVE_PATH NATIVE/${SG_SYSTEM_NAME}/amd64)
129   endif()
130   if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "armv7l")
131     set(JAVA_NATIVE_PATH NATIVE/${SG_SYSTEM_NAME}/arm) # Default arm (soft-float ABI)
132   endif()
133
134   add_custom_command(
135     TARGET simgrid-java_jar POST_BUILD
136     COMMENT "Add the native libs into simgrid.jar..."
137     DEPENDS simgrid simgrid-java ${JAVALIBS}
138           
139     COMMAND ${CMAKE_COMMAND} -E remove_directory ${JAVA_NATIVE_PATH}
140     COMMAND ${CMAKE_COMMAND} -E make_directory   ${JAVA_NATIVE_PATH}
141     
142     ## strip seems to fail on Mac on binaries that are already stripped.
143     ## It then spits: "symbols referenced by indirect symbol table entries that can't be stripped"
144     #COMMAND ${STRIP_COMMAND} ${JAVA_NATIVE_PATH}/${LIBSIMGRID_SO}      || true
145     #COMMAND ${STRIP_COMMAND} ${JAVA_NATIVE_PATH}/${LIBSIMGRID_JAVA_SO} || true
146
147     COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/lib/${LIBSIMGRID_SO}      ${JAVA_NATIVE_PATH}
148     COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/lib/${LIBSIMGRID_JAVA_SO} ${JAVA_NATIVE_PATH} 
149     
150     COMMAND ${JAVA_ARCHIVE} -uvf ${SIMGRID_JAR}  ${JAVA_NATIVE_PATH}
151     COMMAND ${CMAKE_COMMAND} -E remove_directory ${JAVA_NATIVE_PATH}
152     
153     COMMAND ${CMAKE_COMMAND} -E echo "-- Cmake put the native code in ${JAVA_NATIVE_PATH}"
154     COMMAND "${Java_JAVA_EXECUTABLE}" -classpath "${SIMGRID_JAR}" org.simgrid.NativeLib
155     )
156     
157 endif(enable_lib_in_jar)
158
159 include_directories(${JNI_INCLUDE_DIRS} ${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PATH2})