Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
msg.h lives in a subdir, actually
[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 "0")
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/)
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/)
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_host.c
82         src/jmsg_host.h
83         src/jmsg_process.c
84         src/jmsg_process.h
85         src/jmsg_task.c
86         src/jmsg_task.h
87         src/jmsg_application_handler.c
88         src/jmsg_application_handler.h
89 )
90
91 set(JMSG_JAVA_SRC
92         org/simgrid/msg/ApplicationHandler.java
93         org/simgrid/msg/Host.java
94         org/simgrid/msg/HostFailureException.java       
95         org/simgrid/msg/HostNotFoundException.java      
96         org/simgrid/msg/JniException.java
97         org/simgrid/msg/Msg.java
98         org/simgrid/msg/MsgException.java
99         org/simgrid/msg/MsgNative.java
100         org/simgrid/msg/NativeException.java
101         org/simgrid/msg/Process.java
102         org/simgrid/msg/ProcessNotFoundException.java
103         org/simgrid/msg/Sem.java
104         org/simgrid/msg/Task.java
105         org/simgrid/msg/TaskCancelledException.java
106         org/simgrid/msg/TimeoutException.java
107         org/simgrid/msg/TransferFailureException.java   
108 )
109
110 set(JAVA_EXAMPLES
111         examples/mutualExclusion/centralized/MutexCentral.java
112         examples/mutualExclusion/centralized/GrantTask.java
113         examples/mutualExclusion/centralized/Coordinator.java
114         examples/mutualExclusion/centralized/ReleaseTask.java
115         examples/mutualExclusion/centralized/Node.java
116         examples/mutualExclusion/centralized/RequestTask.java
117         examples/basic/FinalizeTask.java
118         examples/basic/Forwarder.java
119         examples/basic/Master.java
120         examples/basic/BasicTest.java
121         examples/basic/Slave.java
122         examples/commTime/FinalizeTask.java
123         examples/commTime/Master.java
124         examples/commTime/Slave.java
125         examples/commTime/CommTimeTest.java
126         examples/pingPong/PingPongTask.java
127         examples/pingPong/Sender.java
128         examples/pingPong/Receiver.java
129         examples/pingPong/PingPongTest.java
130         examples/master_slave_bypass/Master.java
131         examples/master_slave_bypass/MsBypass.java
132         examples/master_slave_bypass/Slave.java
133         examples/master_slave_bypass/FinalizeTask.java
134         examples/master_slave_kill/Master.java
135         examples/master_slave_kill/MsKill.java
136         examples/master_slave_kill/Slave.java
137         examples/master_slave_kill/FinalizeTask.java
138 )
139
140 set(CMAKE_SRC
141 ${CMAKE_HOME_DIRECTORY}/ChangeLog
142 ${CMAKE_HOME_DIRECTORY}/CMakeLists.txt
143 ${CMAKE_HOME_DIRECTORY}/FindJavaSG.cmake
144 ${CMAKE_HOME_DIRECTORY}/FindSimGrid.cmake
145 )
146
147 set(XML_FILES
148     examples/commTime/commTimeDeployment.xml
149     examples/mutualExclusion/ring3.xml
150     examples/mutualExclusion/centralized/mutex_centralized_deployment.xml
151     examples/platform.xml
152     examples/pingPong/pingPongDeployment.xml
153     examples/basic/basicDeployment.xml
154     examples/basic/deploy.xml
155     examples/master_slave_bypass/platform.xml
156     examples/master_slave_kill/platform.xml
157 )
158
159 set(source_to_pack
160 ${CMAKE_SRC}
161 ${JMSG_C_SRC}
162 ${JMSG_JAVA_SRC}
163 ${JAVA_EXAMPLES}
164 ${XML_FILES}
165 )
166
167 string(REPLACE "org/" "${CMAKE_HOME_DIRECTORY}/org/" JAVA_FILES "${JMSG_JAVA_SRC}") 
168 string(REPLACE "org/" "${CMAKE_HOME_DIRECTORY}/classes/org/" JMSG_JAVA_SRC_CLASS "${JMSG_JAVA_SRC}")
169 string(REPLACE ".java" ".class" JMSG_JAVA_SRC_CLASS "${JMSG_JAVA_SRC_CLASS}")
170 string(REPLACE "examples/" "${CMAKE_HOME_DIRECTORY}/examples/" JAVA_EXAMPLES_CLASS "${JAVA_EXAMPLES}") 
171 string(REPLACE ".java" ".class" JAVA_EXAMPLES_CLASS "${JAVA_EXAMPLES_CLASS}")
172
173 #########
174 # FLAGS #
175 #########
176 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 ")
177 set(INCLUDE_PATH "-I${CMAKE_HOME_DIRECTORY}/src -I${SIMGRID_INCLUDES}")
178 set(LIB_PATH "-L${SIMGRID_LIB}")
179 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${INCLUDE_PATH} ${LIB_PATH} -DMSG_USE_DEPRECATED")
180
181 if(COMPILER_C_VERSION_MAJOR_MINOR MATCHES "4.6")
182     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error=unused-but-set-variable ")
183 endif(COMPILER_C_VERSION_MAJOR_MINOR MATCHES "4.6")
184
185
186 ###########
187 # TARGETS #
188 ###########
189 # SG_java
190 add_library(SG_java SHARED ${JMSG_C_SRC})
191 target_link_libraries(SG_java -lsimgrid)
192 set_target_properties(SG_java PROPERTIES VERSION ${soversion})
193   
194 # java_classes
195 add_custom_command(
196         OUTPUT  ${JMSG_JAVA_SRC_CLASS}
197         DEPENDS ${JMSG_JAVA_SRC}
198         COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_HOME_DIRECTORY}/classes/"
199         COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/classes/
200                                         -cp ${CMAKE_HOME_DIRECTORY}/classes/ ${JAVA_FILES}
201         COMMENT "Compiling java sources of core library..."                                     
202 )
203 add_custom_target(java_classes ALL
204   DEPENDS ${JMSG_JAVA_SRC_CLASS}                
205 )
206
207 # simgrid_jar
208 add_custom_target(simgrid_jar ALL
209   COMMAND ${JAVA_ARCHIVE} -cvf ${CMAKE_HOME_DIRECTORY}/simgrid.jar .
210   COMMENT "Building simgrid.jar..."
211   WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/classes 
212 )
213
214 # simgrid_java_examples
215 add_custom_command(
216         COMMENT "Build examples for java"
217         OUTPUT  ${JAVA_EXAMPLES_CLASS}
218         DEPENDS ${JAVA_EXAMPLES}
219         COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/basic/*.java  
220         COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/pingPong/*.java
221         COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/commTime/*.java
222         COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/mutualExclusion/centralized/*.java                                 
223         COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/master_slave_bypass/*.java
224         COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/master_slave_kill/*.java
225 )
226
227 add_custom_target(simgrid_java_examples ALL
228         DEPENDS ${JAVA_EXAMPLES_CLASS}
229 )
230
231 ########################
232 # Declare dependencies #
233 ########################
234 add_dependencies(simgrid_jar java_classes)
235 add_dependencies(simgrid_java_examples simgrid_jar SG_java)
236
237 SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES
238 ${CMAKE_HOME_DIRECTORY}/simgrid.jar
239 )
240
241 #####################
242 # Declare our tests #
243 #####################
244 INCLUDE(CTest)
245 ENABLE_TESTING()
246
247 ADD_TEST(basic
248 java -cp .:${CMAKE_HOME_DIRECTORY}/examples:${CMAKE_HOME_DIRECTORY}/simgrid.jar basic/BasicTest ${CMAKE_HOME_DIRECTORY}/examples/platform.xml ${CMAKE_HOME_DIRECTORY}/examples/basic/basicDeployment.xml
249 )
250 ADD_TEST(pingPong
251 java -cp .:${CMAKE_HOME_DIRECTORY}/examples:${CMAKE_HOME_DIRECTORY}/simgrid.jar pingPong/PingPongTest ${CMAKE_HOME_DIRECTORY}/examples/platform.xml ${CMAKE_HOME_DIRECTORY}/examples/pingPong/pingPongDeployment.xml
252 )
253 ADD_TEST(CommTime
254 java -cp .:${CMAKE_HOME_DIRECTORY}/examples:${CMAKE_HOME_DIRECTORY}/simgrid.jar commTime/CommTimeTest ${CMAKE_HOME_DIRECTORY}/examples/platform.xml ${CMAKE_HOME_DIRECTORY}/examples/commTime/commTimeDeployment.xml
255 )
256 ADD_TEST(mutualExclusion
257 java -cp .:${CMAKE_HOME_DIRECTORY}/examples:${CMAKE_HOME_DIRECTORY}/simgrid.jar mutualExclusion/centralized/MutexCentral ${CMAKE_HOME_DIRECTORY}/examples/mutualExclusion/ring3.xml ${CMAKE_HOME_DIRECTORY}/examples/mutualExclusion/centralized/mutex_centralized_deployment.xml
258 )
259 ADD_TEST(bypass
260 java -cp .:${CMAKE_HOME_DIRECTORY}/examples:${CMAKE_HOME_DIRECTORY}/simgrid.jar master_slave_bypass/MsBypass ${CMAKE_HOME_DIRECTORY}/examples/master_slave_bypass/platform.xml
261 )
262 ADD_TEST(kill
263 java -cp .:${CMAKE_HOME_DIRECTORY}/examples:${CMAKE_HOME_DIRECTORY}/simgrid.jar master_slave_kill/MsKill ${CMAKE_HOME_DIRECTORY}/examples/master_slave_kill/platform.xml
264 )
265 #Don't forget to put new test in this list!!!
266 set(test_list basic pingPong CommTime mutualExclusion bypass kill)
267
268 ##########################################
269 # Set the  DYLD_LIBRARY_PATH for mac     #
270 ##########################################
271 if(APPLE)
272     if($ENV{DYLD_LIBRARY_PATH} STREQUAL "")
273         set_tests_properties(${test_list}
274         PROPERTIES ENVIRONMENT "DYLD_LIBRARY_PATH=${CMAKE_HOME_DIRECTORY}/lib:${SIMGRID_LIB}")
275     else($ENV{DYLD_LIBRARY_PATH} STREQUAL "")
276         set_tests_properties(${test_list}
277         PROPERTIES ENVIRONMENT "DYLD_LIBRARY_PATH=$ENV{DYLD_LIBRARY_PATH}:${CMAKE_HOME_DIRECTORY}/lib:${SIMGRID_LIB}")
278     endif($ENV{DYLD_LIBRARY_PATH} STREQUAL "")
279 endif(APPLE)
280
281 ##########################################
282 # Set the  LD_LIBRARY_PATH for our tests #
283 ##########################################
284 if($ENV{LD_LIBRARY_PATH} STREQUAL "")
285     set_tests_properties(${test_list}
286     PROPERTIES ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_HOME_DIRECTORY}/lib:${SIMGRID_LIB}")
287 else($ENV{LD_LIBRARY_PATH} STREQUAL "")
288     set_tests_properties(${test_list}
289     PROPERTIES ENVIRONMENT "LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH}:${CMAKE_HOME_DIRECTORY}/lib:${SIMGRID_LIB}")
290 endif($ENV{LD_LIBRARY_PATH} STREQUAL "")
291
292 ###########
293 # Install #
294 ###########
295 install(TARGETS SG_java
296         DESTINATION $ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/java/)
297 install(FILES ${CMAKE_HOME_DIRECTORY}/simgrid.jar
298         DESTINATION $ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/java/)
299
300
301 #########
302 # Dist  #
303 #########
304
305 add_custom_target(dist-dir
306   COMMENT "Generating the distribution directory"
307   COMMAND test -e ${DIST_NAME}/ && chmod -R a+w ${DIST_NAME}/ || true
308   COMMAND ${CMAKE_COMMAND} -E remove_directory ${DIST_NAME}/
309   COMMAND ${CMAKE_COMMAND} -E make_directory ${DIST_NAME}
310 )
311
312 set(dirs_in_tarball "")
313 foreach(file ${source_to_pack})
314
315   # This damn prefix is still set somewhere (seems to be in subdirs)
316   string(REPLACE "${CMAKE_HOME_DIRECTORY}/" "" file "${file}")
317   
318   # Create the directory on need
319   get_filename_component(file_location ${file} PATH)
320   string(REGEX MATCH ";${file_location};" OPERATION "${dirs_in_tarball}")
321   if(NOT OPERATION)
322        set(dirs_in_tarball "${dirs_in_tarball};${file_location};")
323        add_custom_command(
324          TARGET dist-dir
325          COMMAND ${CMAKE_COMMAND} -E make_directory ${DIST_NAME}/${file_location}/
326        )       
327    endif(NOT OPERATION)
328    
329    # Actually copy the file
330    add_custom_command(
331      TARGET dist-dir
332      COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_HOME_DIRECTORY}/${file} ${DIST_NAME}/${file_location}/
333    )
334 endforeach(file ${source_to_pack})
335
336 add_custom_target(dist
337   DEPENDS ${CMAKE_BINARY_DIR}/${DIST_NAME}.tar.gz
338   COMMENT "Generated ${DIST_NAME}"
339 )
340 add_custom_command(
341         OUTPUT ${CMAKE_BINARY_DIR}/${DIST_NAME}.tar.gz  
342         COMMENT "Compressing the archive from the distribution directory"
343         COMMAND ${CMAKE_COMMAND} -E tar cf ${DIST_NAME}.tar ${DIST_NAME}/
344         COMMAND gzip -9v ${DIST_NAME}.tar
345         COMMAND ${CMAKE_COMMAND} -E remove_directory ${DIST_NAME}/
346 )
347 add_dependencies(dist dist-dir)
348
349 ########
350 # NOTE #
351 ########
352 file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/Testing/Notes/)
353 file(WRITE ${CMAKE_BINARY_DIR}/Testing/Notes/Build  "GIT version : ${GIT_VERSION}\n")
354 file(APPEND ${CMAKE_BINARY_DIR}/Testing/Notes/Build "Release     : ${DIST_NAME}\n")
355 file(APPEND ${CMAKE_BINARY_DIR}/Testing/Notes/Build "Pipol user  : $ENV{PIPOL_USER}\n")
356 file(APPEND ${CMAKE_BINARY_DIR}/Testing/Notes/Build "Pipol image : $ENV{PIPOL_IMAGE}\n")
357
358 #######
359 # DOC #
360 #######
361 set(WARNING "This file is generated, don't edit it!")
362 set(srcdir ${CMAKE_HOME_DIRECTORY})
363 include(GenerateDoc.cmake)