Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
4f35374624e878085f050d1740dcb557300b5986
[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 "1")
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_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$ENV{SIMGRID_ROOT}/include")
178 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${INCLUDE_PATH}")
179
180 if(COMPILER_C_VERSION_MAJOR_MINOR MATCHES "4.6")
181     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error=unused-but-set-variable")
182 endif(COMPILER_C_VERSION_MAJOR_MINOR MATCHES "4.6")
183
184 ###########
185 # TARGETS #
186 ###########
187 # SG_java
188 add_library(SG_java SHARED ${JMSG_C_SRC})
189 target_link_libraries(SG_java pcre pthread)
190 set_target_properties(SG_java PROPERTIES LINK_FLAGS "${SIMGRID_LIB} -L$ENV{SIMGRID_PCRE_LIBRARY_PATH}/lib")
191 if(WIN32)
192     set_target_properties(SG_java PROPERTIES LINK_FLAGS "-Wl,--subsystem,windows,--kill-at" PREFIX "")
193     find_path(PEXPORTS_PATH NAMES pexports.exe PATHS NO_DEFAULT_PATHS)
194     message(STATUS "pexports: ${PEXPORTS_PATH}")
195     if(PEXPORTS_PATH)
196     add_custom_command(TARGET SG_java POST_BUILD
197     COMMAND ${PEXPORTS_PATH}/pexports.exe ${CMAKE_BINARY_DIR}/SG_java.dll > ${CMAKE_BINARY_DIR}/SG_java.def)
198     endif(PEXPORTS_PATH)
199 endif(WIN32)
200
201 # java_classes
202 add_custom_command(
203         OUTPUT  ${JMSG_JAVA_SRC_CLASS}
204         DEPENDS ${JMSG_JAVA_SRC}
205         COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_HOME_DIRECTORY}/classes/"
206         COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/classes/
207                                         -cp ${CMAKE_HOME_DIRECTORY}/classes/ ${JAVA_FILES}
208         COMMENT "Compiling java sources of core library..."                                     
209 )
210 add_custom_target(java_classes ALL
211   DEPENDS ${JMSG_JAVA_SRC_CLASS}                
212 )
213
214 # simgrid_jar
215 add_custom_target(simgrid_jar ALL
216   COMMAND ${JAVA_ARCHIVE} -cvf ${CMAKE_HOME_DIRECTORY}/simgrid.jar .
217   COMMENT "Building simgrid.jar..."
218   WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/classes 
219 )
220
221 # simgrid_java_examples
222 add_custom_command(
223         COMMENT "Build examples for java"
224         OUTPUT  ${JAVA_EXAMPLES_CLASS}
225         DEPENDS ${JAVA_EXAMPLES}
226         COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/basic/*.java  
227         COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/pingPong/*.java
228         COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/commTime/*.java
229         COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/mutualExclusion/centralized/*.java                                 
230         COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/master_slave_bypass/*.java
231         COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/master_slave_kill/*.java
232 )
233
234 add_custom_target(simgrid_java_examples ALL
235         DEPENDS ${JAVA_EXAMPLES_CLASS}
236 )
237
238 ########################
239 # Declare dependencies #
240 ########################
241 add_dependencies(simgrid_jar java_classes)
242 add_dependencies(simgrid_java_examples simgrid_jar SG_java)
243
244 SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES
245 ${CMAKE_HOME_DIRECTORY}/simgrid.jar
246 )
247
248 #####################
249 # Declare our tests #
250 #####################
251 INCLUDE(CTest)
252 ENABLE_TESTING()
253
254 ADD_TEST(basic
255 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
256 )
257 ADD_TEST(pingPong
258 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
259 )
260 ADD_TEST(CommTime
261 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
262 )
263 ADD_TEST(mutualExclusion
264 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
265 )
266 ADD_TEST(bypass
267 java -cp .:${CMAKE_HOME_DIRECTORY}/examples:${CMAKE_HOME_DIRECTORY}/simgrid.jar master_slave_bypass/MsBypass ${CMAKE_HOME_DIRECTORY}/examples/master_slave_bypass/platform.xml
268 )
269 ADD_TEST(kill
270 java -cp .:${CMAKE_HOME_DIRECTORY}/examples:${CMAKE_HOME_DIRECTORY}/simgrid.jar master_slave_kill/MsKill ${CMAKE_HOME_DIRECTORY}/examples/master_slave_kill/platform.xml
271 )
272 #Don't forget to put new test in this list!!!
273 set(test_list basic pingPong CommTime mutualExclusion bypass kill)
274
275 ##########################################
276 # Set the  DYLD_LIBRARY_PATH for mac     #
277 ##########################################
278 if(APPLE)
279     if($ENV{DYLD_LIBRARY_PATH} STREQUAL "")
280         set_tests_properties(${test_list}
281         PROPERTIES ENVIRONMENT "DYLD_LIBRARY_PATH=${CMAKE_HOME_DIRECTORY}/lib:${SIMGRID_LIB}")
282     else($ENV{DYLD_LIBRARY_PATH} STREQUAL "")
283         set_tests_properties(${test_list}
284         PROPERTIES ENVIRONMENT "DYLD_LIBRARY_PATH=$ENV{DYLD_LIBRARY_PATH}:${CMAKE_HOME_DIRECTORY}/lib:${SIMGRID_LIB}")
285     endif($ENV{DYLD_LIBRARY_PATH} STREQUAL "")
286 endif(APPLE)
287
288 ##########################################
289 # Set the  LD_LIBRARY_PATH for our tests #
290 ##########################################
291 if(NOT WIN32)
292 if($ENV{LD_LIBRARY_PATH} STREQUAL "")
293     set_tests_properties(${test_list}
294     PROPERTIES ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_HOME_DIRECTORY}/lib:${SIMGRID_LIB}")
295 else($ENV{LD_LIBRARY_PATH} STREQUAL "")
296     set_tests_properties(${test_list}
297     PROPERTIES ENVIRONMENT "LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH}:${CMAKE_HOME_DIRECTORY}/lib:${SIMGRID_LIB}")
298 endif($ENV{LD_LIBRARY_PATH} STREQUAL "")
299 endif(NOT WIN32)
300
301 ###########
302 # Install #
303 ###########
304 install(TARGETS SG_java
305         DESTINATION $ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/java/)
306 install(FILES ${CMAKE_HOME_DIRECTORY}/simgrid.jar
307         DESTINATION $ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/java/)
308
309
310 #########
311 # Dist  #
312 #########
313
314 add_custom_target(dist-dir
315   COMMENT "Generating the distribution directory"
316   COMMAND test -e ${DIST_NAME}/ && chmod -R a+w ${DIST_NAME}/ || true
317   COMMAND ${CMAKE_COMMAND} -E remove_directory ${DIST_NAME}/
318   COMMAND ${CMAKE_COMMAND} -E make_directory ${DIST_NAME}
319 )
320
321 set(dirs_in_tarball "")
322 foreach(file ${source_to_pack})
323
324   # This damn prefix is still set somewhere (seems to be in subdirs)
325   string(REPLACE "${CMAKE_HOME_DIRECTORY}/" "" file "${file}")
326   
327   # Create the directory on need
328   get_filename_component(file_location ${file} PATH)
329   string(REGEX MATCH ";${file_location};" OPERATION "${dirs_in_tarball}")
330   if(NOT OPERATION)
331        set(dirs_in_tarball "${dirs_in_tarball};${file_location};")
332        add_custom_command(
333          TARGET dist-dir
334          COMMAND ${CMAKE_COMMAND} -E make_directory ${DIST_NAME}/${file_location}/
335        )       
336    endif(NOT OPERATION)
337    
338    # Actually copy the file
339    add_custom_command(
340      TARGET dist-dir
341      COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_HOME_DIRECTORY}/${file} ${DIST_NAME}/${file_location}/
342    )
343 endforeach(file ${source_to_pack})
344
345 add_custom_target(dist
346   DEPENDS ${CMAKE_BINARY_DIR}/${DIST_NAME}.tar.gz
347   COMMENT "Generated ${DIST_NAME}"
348 )
349 add_custom_command(
350         OUTPUT ${CMAKE_BINARY_DIR}/${DIST_NAME}.tar.gz  
351         COMMENT "Compressing the archive from the distribution directory"
352         COMMAND ${CMAKE_COMMAND} -E tar cf ${DIST_NAME}.tar ${DIST_NAME}/
353         COMMAND gzip -9v ${DIST_NAME}.tar
354         COMMAND ${CMAKE_COMMAND} -E remove_directory ${DIST_NAME}/
355 )
356 add_dependencies(dist dist-dir)
357
358 ########
359 # NOTE #
360 ########
361 file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/Testing/Notes/)
362 file(WRITE ${CMAKE_BINARY_DIR}/Testing/Notes/Build  "GIT version : ${GIT_VERSION}\n")
363 file(APPEND ${CMAKE_BINARY_DIR}/Testing/Notes/Build "Release     : ${DIST_NAME}\n")
364 file(APPEND ${CMAKE_BINARY_DIR}/Testing/Notes/Build "Pipol user  : $ENV{PIPOL_USER}\n")
365 file(APPEND ${CMAKE_BINARY_DIR}/Testing/Notes/Build "Pipol image : $ENV{PIPOL_IMAGE}\n")
366
367 #######
368 # DOC #
369 #######
370 set(WARNING "This file is generated, don't edit it!")
371 set(srcdir ${CMAKE_HOME_DIRECTORY})
372 include(GenerateDoc.cmake)