Logo AND Algorithmique Numérique Distribuée

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