Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Forgot to update migrate signature in Process
[simgrid.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.8)
2 project(SimGrid-Java C)
3 set(UPDATE_TYPE svn)
4 set(CMAKE_C_FLAGS "" CACHE TYPE INTERNAL FORCE)
5 set(CMAKE_EXE_LINKER_FLAGS "" CACHE TYPE INTERNAL FORCE)
6 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_HOME_DIRECTORY}/lib")
7 set(soversion 1)
8
9 set(SIMGRID_JAVA_VERSION_MAJOR "1")
10 set(SIMGRID_JAVA_VERSION_MINOR "2")
11 set(SIMGRID_JAVA_VERSION_PATCH "0")
12 set(DIST_NAME ${PROJECT_NAME}-${SIMGRID_JAVA_VERSION_MAJOR}.${SIMGRID_JAVA_VERSION_MINOR})
13
14 ########
15 ## GCC #
16 ########
17 exec_program("${CMAKE_C_COMPILER} --version" OUTPUT_VARIABLE "COMPILER_C_VERSION")
18 string(REGEX MATCH "[0-9].[0-9].[0-9]" COMPILER_C_VERSION "${COMPILER_C_VERSION}")
19 string(REGEX MATCH "^[0-9].[0-9]" COMPILER_C_VERSION_MAJOR_MINOR "${COMPILER_C_VERSION}")
20 string(REPLACE "${COMPILER_C_VERSION_MAJOR_MINOR}." "" COMPILER_C_VERSION_PATCH "${COMPILER_C_VERSION}")
21
22 ########
23 ## GIT #
24 ########
25 if(EXISTS ${CMAKE_HOME_DIRECTORY}/.git/ AND NOT WIN32)
26 exec_program("git remote | head -n 1" OUTPUT_VARIABLE remote RETURN_VALUE ret)
27 exec_program("git config --get remote.${remote}.url" OUTPUT_VARIABLE url RETURN_VALUE ret)
28
29 if(url)
30         exec_program("git --git-dir=${CMAKE_HOME_DIRECTORY}/.git log --oneline -1" OUTPUT_VARIABLE "GIT_VERSION")
31         message(STATUS "Git version: ${GIT_VERSION}")
32         exec_program("git --git-dir=${CMAKE_HOME_DIRECTORY}/.git log -n 1 --format=%ai ." OUTPUT_VARIABLE "GIT_DATE")
33         message(STATUS "Git date: ${GIT_DATE}")
34         string(REGEX REPLACE " .*" "" GIT_VERSION "${GIT_VERSION}")
35         STRING(REPLACE " +0000" "" GIT_DATE ${GIT_DATE})
36         STRING(REPLACE " " "~" GIT_DATE ${GIT_DATE})
37         STRING(REPLACE ":" "-" GIT_DATE ${GIT_DATE})
38 endif(url)
39 endif(EXISTS ${CMAKE_HOME_DIRECTORY}/.git/ AND NOT WIN32)
40
41 #########
42 # CDASH #
43 #########
44 SET(DROP_METHOD "http")
45 SET(DROP_SITE "cdash.inria.fr/CDash")
46 SET(DROP_LOCATION "/submit.php?project=simgrid")
47 SET(DROP_SITE_CDASH TRUE)
48 SET(TRIGGER_SITE "http://cdash.inria.fr/CDash/cgi-bin/Submit-Random-TestingResults.cgi")
49 SET(BUILDNAME "SimGrid-Java" CACHE TYPE INTERNAL FORCE)
50 set(osname ${CMAKE_SYSTEM_NAME})
51 set(cpu ${CMAKE_SYSTEM_PROCESSOR})
52 set(DISTRIB2 ${CMAKE_SYSTEM_VERSION})
53 SET(SITE "${osname}_${DISTRIB2}_${cpu}")
54 SET(CTEST_SITE "${osname}_${DISTRIB2}_${cpu}")
55 SET(CTEST_PROJECT_NAME "${PROJECT_NAME}")
56 SET(CTEST_CUSTOM_MAXIMUM_FAILED_TEST_OUTPUT_SIZE "3000000")
57 SET(CTEST_CUSTOM_MAXIMUM_PASSED_TEST_OUTPUT_SIZE "3000000")
58 set(PIPOL_IMAGE $ENV{PIPOL_IMAGE})
59 if(NOT ${PIPOL_IMAGE} MATCHES "\n")
60 set(SITE ${PIPOL_IMAGE})
61 endif(NOT ${PIPOL_IMAGE} MATCHES "\n")
62 message(STATUS "SITE        : ${SITE}")
63 message(STATUS "BUILDNAME   : ${BUILDNAME}")
64
65 ###############################
66 # Test the build dependencies #
67 ###############################
68 include(FindSimGrid.cmake)
69 include(FindJavaSG.cmake)
70
71 ###############################
72 # Declare our package content #
73 ###############################
74 set(JMSG_C_SRC
75         src/smx_context_java.h
76         src/smx_context_java.c
77         src/jxbt_utilities.c
78         src/jxbt_utilities.h
79         src/jmsg.c 
80         src/jmsg.h
81         src/jmsg_comm.c
82         src/jmsg_comm.h
83         src/jmsg_host.c
84         src/jmsg_host.h
85         src/jmsg_process.c
86         src/jmsg_process.h
87         src/jmsg_task.c
88         src/jmsg_task.h
89         src/jmsg_synchro.c
90         src/jmsg_synchro.h
91         src/jmsg_application_handler.c
92         src/jmsg_application_handler.h
93 )
94
95 set(JMSG_JAVA_SRC
96         org/simgrid/msg/ApplicationHandler.java
97         org/simgrid/msg/Host.java
98         org/simgrid/msg/HostFailureException.java       
99         org/simgrid/msg/HostNotFoundException.java      
100         org/simgrid/msg/JniException.java
101         org/simgrid/msg/Msg.java
102         org/simgrid/msg/MsgException.java
103         org/simgrid/msg/NativeException.java
104         org/simgrid/msg/Process.java
105         org/simgrid/msg/ProcessKilled.java
106         org/simgrid/msg/ProcessNotFoundException.java
107         org/simgrid/msg/Task.java
108         org/simgrid/msg/TaskCancelledException.java
109         org/simgrid/msg/TimeoutException.java
110         org/simgrid/msg/TransferFailureException.java   
111         org/simgrid/msg/Mutex.java
112         org/simgrid/msg/Comm.java
113 )
114
115 set(JAVA_EXAMPLES
116         examples/mutualExclusion/centralized/MutexCentral.java
117         examples/mutualExclusion/centralized/GrantTask.java
118         examples/mutualExclusion/centralized/Coordinator.java
119         examples/mutualExclusion/centralized/ReleaseTask.java
120         examples/mutualExclusion/centralized/Node.java
121         examples/mutualExclusion/centralized/RequestTask.java
122         examples/basic/FinalizeTask.java
123         examples/basic/Forwarder.java
124         examples/basic/Master.java
125         examples/basic/BasicTest.java
126         examples/basic/Slave.java
127         examples/commTime/FinalizeTask.java
128         examples/commTime/Master.java
129         examples/commTime/Slave.java
130         examples/commTime/CommTimeTest.java
131         examples/pingPong/PingPongTask.java
132         examples/pingPong/Sender.java
133         examples/pingPong/Receiver.java
134         examples/pingPong/PingPongTest.java
135         examples/master_slave_bypass/Master.java
136         examples/master_slave_bypass/MsBypass.java
137         examples/master_slave_bypass/Slave.java
138         examples/master_slave_bypass/FinalizeTask.java
139         examples/master_slave_kill/Master.java
140         examples/master_slave_kill/MsKill.java
141         examples/master_slave_kill/Slave.java
142         examples/master_slave_kill/FinalizeTask.java
143         examples/async/AsyncTest.java
144         examples/async/FinalizeTask.java  
145         examples/async/Forwarder.java
146         examples/async/Master.java  
147         examples/async/Slave.java
148 )
149
150 set(CMAKE_SRC
151 ${CMAKE_HOME_DIRECTORY}/ChangeLog
152 ${CMAKE_HOME_DIRECTORY}/CMakeLists.txt
153 ${CMAKE_HOME_DIRECTORY}/FindJavaSG.cmake
154 ${CMAKE_HOME_DIRECTORY}/FindSimGrid.cmake
155 )
156
157 set(XML_FILES
158     examples/commTime/commTimeDeployment.xml
159     examples/mutualExclusion/ring3.xml
160     examples/mutualExclusion/centralized/mutex_centralized_deployment.xml
161     examples/platform.xml
162     examples/pingPong/pingPongDeployment.xml
163     examples/basic/basicDeployment.xml
164     examples/basic/deploy.xml
165     examples/master_slave_bypass/platform.xml
166     examples/master_slave_kill/platform.xml
167     examples/async/asyncDeployment.xml
168 )
169
170 set(source_to_pack
171 ${CMAKE_SRC}
172 ${JMSG_C_SRC}
173 ${JMSG_JAVA_SRC}
174 ${JAVA_EXAMPLES}
175 ${XML_FILES}
176 )
177
178 string(REPLACE "org/" "${CMAKE_HOME_DIRECTORY}/org/" JAVA_FILES "${JMSG_JAVA_SRC}") 
179 string(REPLACE "org/" "${CMAKE_HOME_DIRECTORY}/classes/org/" JMSG_JAVA_SRC_CLASS "${JMSG_JAVA_SRC}")
180 string(REPLACE ".java" ".class" JMSG_JAVA_SRC_CLASS "${JMSG_JAVA_SRC_CLASS}")
181 string(REPLACE "examples/" "${CMAKE_HOME_DIRECTORY}/examples/" JAVA_EXAMPLES_CLASS "${JAVA_EXAMPLES}") 
182 string(REPLACE ".java" ".class" JAVA_EXAMPLES_CLASS "${JAVA_EXAMPLES_CLASS}")
183
184 #########
185 # FLAGS #
186 #########
187 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g -Wall -Wunused -Wmissing-prototypes -Wmissing-declarations -Wpointer-arith -Wchar-subscripts -Wcomment -Wformat -Wwrite-strings -Wno-unused-function -Wno-unused-parameter -Wno-strict-aliasing -Wno-format-nonliteral -Werror ")
188 set(INCLUDE_PATH "-I${CMAKE_HOME_DIRECTORY}/src -I${SIMGRID_INCLUDES} ")
189 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${INCLUDE_PATH}")
190
191 if(COMPILER_C_VERSION_MAJOR_MINOR MATCHES "4.6")
192     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error=unused-but-set-variable")
193 endif(COMPILER_C_VERSION_MAJOR_MINOR MATCHES "4.6")
194
195 ###########
196 # TARGETS #
197 ###########
198 # SG_java
199 add_library(SG_java SHARED ${JMSG_C_SRC})
200 if(WIN32)
201     set_target_properties(SG_java PROPERTIES LINK_FLAGS "-Wl,--subsystem,windows,--kill-at ${SIMGRID_LIB}" PREFIX "")
202     find_path(PEXPORTS_PATH NAMES pexports.exe PATHS NO_DEFAULT_PATHS)
203     message(STATUS "pexports: ${PEXPORTS_PATH}")
204     if(PEXPORTS_PATH)
205     add_custom_command(TARGET SG_java POST_BUILD
206     COMMAND ${PEXPORTS_PATH}/pexports.exe ${CMAKE_BINARY_DIR}/SG_java.dll > ${CMAKE_BINARY_DIR}/SG_java.def)
207     endif(PEXPORTS_PATH)
208 else(WIN32)
209     target_link_libraries(SG_java pcre pthread simgrid)
210     set_target_properties(SG_java PROPERTIES LINK_FLAGS "-L${SIMGRID_LIB_PATH} -L$ENV{SIMGRID_PCRE_LIBRARY_PATH}/lib")
211 endif(WIN32)
212
213 # java_classes
214 add_custom_command(
215         OUTPUT  ${JMSG_JAVA_SRC_CLASS}
216         DEPENDS ${JMSG_JAVA_SRC}
217         COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_HOME_DIRECTORY}/classes/"
218         COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/classes/
219                                         -cp ${CMAKE_HOME_DIRECTORY}/classes/ ${JAVA_FILES}
220         COMMENT "Compiling java sources of core library..."                                     
221 )
222 add_custom_target(java_classes ALL
223   DEPENDS ${JMSG_JAVA_SRC_CLASS}
224 )
225
226 # simgrid_jar
227 add_custom_target(simgrid_jar ALL
228   COMMAND ${JAVA_ARCHIVE} -cvf ${CMAKE_HOME_DIRECTORY}/simgrid.jar .
229   COMMENT "Building simgrid.jar..."
230   WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/classes 
231 )
232
233 # simgrid_java_examples
234 add_custom_command(
235         COMMENT "Build examples for java"
236         OUTPUT  ${JAVA_EXAMPLES_CLASS}
237         DEPENDS ${JAVA_EXAMPLES}
238         COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/basic/*.java  
239         COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/async/*.java
240         COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/pingPong/*.java
241         COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/commTime/*.java
242         COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/mutualExclusion/centralized/*.java                                 
243         COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/master_slave_bypass/*.java
244         COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/master_slave_kill/*.java
245 )
246
247 add_custom_target(simgrid_java_examples ALL
248         DEPENDS ${JAVA_EXAMPLES_CLASS}
249 )
250
251 ########################
252 # Declare dependencies #
253 ########################
254 add_dependencies(simgrid_jar java_classes)
255 add_dependencies(simgrid_java_examples simgrid_jar SG_java)
256
257 SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES
258 ${CMAKE_HOME_DIRECTORY}/simgrid.jar
259 )
260
261 #####################
262 # Declare our tests #
263 #####################
264 INCLUDE(CTest)
265 ENABLE_TESTING()
266
267 ADD_TEST(basic           ${TESH_BIN_PATH} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/examples/basic/basic.tesh)
268 ADD_TEST(async           ${TESH_BIN_PATH} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/examples/async/async.tesh)
269 ADD_TEST(pingPong        ${TESH_BIN_PATH} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/examples/pingPong/pingpong.tesh)
270 ADD_TEST(CommTime        ${TESH_BIN_PATH} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/examples/commTime/commtime.tesh)
271 ADD_TEST(mutualExclusion ${TESH_BIN_PATH} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/examples/mutualExclusion/mutualexclusion.tesh)
272 ADD_TEST(bypass          ${TESH_BIN_PATH} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/examples/master_slave_bypass/bypass.tesh)
273 ADD_TEST(kill            ${TESH_BIN_PATH} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/examples/master_slave_kill/kill.tesh)
274 #Don't forget to put new test in this list!!!
275 set(test_list basic async pingPong CommTime mutualExclusion bypass kill)
276
277 ##########################################
278 # Set the  DYLD_LIBRARY_PATH for mac     #
279 ##########################################
280 if(APPLE)
281     if($ENV{DYLD_LIBRARY_PATH} STREQUAL "")
282         set_tests_properties(${test_list}
283         PROPERTIES ENVIRONMENT "DYLD_LIBRARY_PATH=${CMAKE_HOME_DIRECTORY}/lib:${SIMGRID_LIB_PATH}")
284     else($ENV{DYLD_LIBRARY_PATH} STREQUAL "")
285         set_tests_properties(${test_list}
286         PROPERTIES ENVIRONMENT "DYLD_LIBRARY_PATH=$ENV{DYLD_LIBRARY_PATH}:${CMAKE_HOME_DIRECTORY}/lib:${SIMGRID_LIB_PATH}")
287     endif($ENV{DYLD_LIBRARY_PATH} STREQUAL "")
288 endif(APPLE)
289
290 ##########################################
291 # Set the  LD_LIBRARY_PATH for our tests #
292 ##########################################
293 if(NOT WIN32)
294 if($ENV{LD_LIBRARY_PATH} STREQUAL "")
295     set_tests_properties(${test_list}
296     PROPERTIES ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_HOME_DIRECTORY}/lib:${SIMGRID_LIB_PATH}")
297 else($ENV{LD_LIBRARY_PATH} STREQUAL "")
298     set_tests_properties(${test_list}
299     PROPERTIES ENVIRONMENT "LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH}:${CMAKE_HOME_DIRECTORY}/lib:${SIMGRID_LIB_PATH}")
300 endif($ENV{LD_LIBRARY_PATH} STREQUAL "")
301 endif(NOT WIN32)
302
303 ###########
304 # Install #
305 ###########
306 install(TARGETS SG_java
307         DESTINATION $ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/java/)
308 install(FILES ${CMAKE_HOME_DIRECTORY}/simgrid.jar
309         DESTINATION $ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/java/)
310
311
312 #########
313 # Dist  #
314 #########
315
316 add_custom_target(dist-dir
317   COMMENT "Generating the distribution directory"
318   COMMAND test -e ${DIST_NAME}/ && chmod -R a+w ${DIST_NAME}/ || true
319   COMMAND ${CMAKE_COMMAND} -E remove_directory ${DIST_NAME}/
320   COMMAND ${CMAKE_COMMAND} -E make_directory ${DIST_NAME}
321 )
322
323 set(dirs_in_tarball "")
324 foreach(file ${source_to_pack})
325
326   # This damn prefix is still set somewhere (seems to be in subdirs)
327   string(REPLACE "${CMAKE_HOME_DIRECTORY}/" "" file "${file}")
328   
329   # Create the directory on need
330   get_filename_component(file_location ${file} PATH)
331   string(REGEX MATCH ";${file_location};" OPERATION "${dirs_in_tarball}")
332   if(NOT OPERATION)
333        set(dirs_in_tarball "${dirs_in_tarball};${file_location};")
334        add_custom_command(
335          TARGET dist-dir
336          COMMAND ${CMAKE_COMMAND} -E make_directory ${DIST_NAME}/${file_location}/
337        )       
338    endif(NOT OPERATION)
339    
340    # Actually copy the file
341    add_custom_command(
342      TARGET dist-dir
343      COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_HOME_DIRECTORY}/${file} ${DIST_NAME}/${file_location}/
344    )
345 endforeach(file ${source_to_pack})
346
347 add_custom_target(dist
348   DEPENDS ${CMAKE_BINARY_DIR}/${DIST_NAME}.tar.gz
349   COMMENT "Generated ${DIST_NAME}"
350 )
351 add_custom_command(
352         OUTPUT ${CMAKE_BINARY_DIR}/${DIST_NAME}.tar.gz  
353         COMMENT "Compressing the archive from the distribution directory"
354         COMMAND ${CMAKE_COMMAND} -E tar cf ${DIST_NAME}.tar ${DIST_NAME}/
355         COMMAND gzip -9v ${DIST_NAME}.tar
356         COMMAND ${CMAKE_COMMAND} -E remove_directory ${DIST_NAME}/
357 )
358 add_dependencies(dist dist-dir)
359
360 ########
361 # NOTE #
362 ########
363 file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/Testing/Notes/)
364 file(WRITE ${CMAKE_BINARY_DIR}/Testing/Notes/Build  "GIT version : ${GIT_VERSION}\n")
365 file(APPEND ${CMAKE_BINARY_DIR}/Testing/Notes/Build "Release     : ${DIST_NAME}\n")
366 file(APPEND ${CMAKE_BINARY_DIR}/Testing/Notes/Build "Pipol user  : $ENV{PIPOL_USER}\n")
367 file(APPEND ${CMAKE_BINARY_DIR}/Testing/Notes/Build "Pipol image : $ENV{PIPOL_IMAGE}\n")
368
369 #######
370 # DOC #
371 #######
372 set(WARNING "This file is generated, don't edit it!")
373 set(srcdir ${CMAKE_HOME_DIRECTORY})
374 include(GenerateDoc.cmake)