Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Completely remove ruby and java from simgrid project.
[simgrid.git] / buildtools / Cmake / CompleteInFiles.cmake
1 set(CMAKE_MODULE_PATH 
2 ${CMAKE_MODULE_PATH}
3 ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Modules
4 )
5
6 message(STATUS "Cmake version ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}")
7
8 include(CheckFunctionExists)
9 include(CheckTypeSize)
10 include(CheckIncludeFile)
11 include(CheckIncludeFiles)
12 include(CheckLibraryExists)
13 include(TestBigEndian)
14 TEST_BIG_ENDIAN(BIGENDIAN)
15
16 include(FindGraphviz)
17 if(enable_pcre)
18 include(FindPCRE)
19 endif(enable_pcre)
20 if(enable_gtnets)       
21         include(FindGTnets)
22 endif(enable_gtnets)
23 if(enable_smpi)
24         include(FindF2c)
25 endif(enable_smpi)
26 if(enable_lua)
27         include(FindLua51Simgrid)
28 endif(enable_lua)
29
30 # Checks for header libraries functions.
31 CHECK_LIBRARY_EXISTS(pthread    pthread_create                  "" pthread)
32 CHECK_LIBRARY_EXISTS(pthread    sem_init                                "" HAVE_SEM_INIT_LIB)
33 CHECK_LIBRARY_EXISTS(pthread    sem_timedwait                   "" HAVE_SEM_TIMEDWAIT_LIB)
34 CHECK_LIBRARY_EXISTS(pthread    pthread_mutex_timedlock "" HAVE_MUTEX_TIMEDLOCK_LIB)
35 CHECK_LIBRARY_EXISTS(rt                 clock_gettime                   "" HAVE_POSIX_GETTIME)
36
37 CHECK_INCLUDE_FILES("time.h;sys/time.h" TIME_WITH_SYS_TIME)
38 CHECK_INCLUDE_FILES("stdlib.h;stdarg.h;string.h;float.h" STDC_HEADERS)
39 CHECK_INCLUDE_FILE("pthread.h" HAVE_PTHREAD_H)
40 CHECK_INCLUDE_FILE("valgrind/valgrind.h" HAVE_VALGRIND_VALGRIND_H)
41 CHECK_INCLUDE_FILE("socket.h" HAVE_SOCKET_H)
42 CHECK_INCLUDE_FILE("sys/socket.h" HAVE_SYS_SOCKET_H)
43 CHECK_INCLUDE_FILE("stat.h" HAVE_STAT_H)
44 CHECK_INCLUDE_FILE("sys/stat.h" HAVE_SYS_STAT_H)
45 CHECK_INCLUDE_FILE("windows.h" HAVE_WINDOWS_H)
46 CHECK_INCLUDE_FILE("winsock.h" HAVE_WINSOCK_H)
47 CHECK_INCLUDE_FILE("winsock2.h" HAVE_WINSOCK2_H)
48 CHECK_INCLUDE_FILE("errno.h" HAVE_ERRNO_H)
49 CHECK_INCLUDE_FILE("unistd.h" HAVE_UNISTD_H)
50 CHECK_INCLUDE_FILE("execinfo.h" HAVE_EXECINFO_H)
51 CHECK_INCLUDE_FILE("signal.h" HAVE_SIGNAL_H)
52 CHECK_INCLUDE_FILE("sys/time.h" HAVE_SYS_TIME_H)
53 CHECK_INCLUDE_FILE("time.h" HAVE_TIME_H)
54 CHECK_INCLUDE_FILE("dlfcn.h" HAVE_DLFCN_H)
55 CHECK_INCLUDE_FILE("inttypes.h" HAVE_INTTYPES_H)
56 CHECK_INCLUDE_FILE("memory.h" HAVE_MEMORY_H)
57 CHECK_INCLUDE_FILE("stdlib.h" HAVE_STDLIB_H)
58 CHECK_INCLUDE_FILE("strings.h" HAVE_STRINGS_H)
59 CHECK_INCLUDE_FILE("string.h" HAVE_STRING_H)
60 CHECK_INCLUDE_FILE("ucontext.h" HAVE_UCONTEXT_H)
61 CHECK_INCLUDE_FILE("stdio.h" HAVE_STDIO_H)
62 CHECK_INCLUDE_FILE("linux/futex.h" HAVE_FUTEX_H)
63
64
65 CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
66 CHECK_FUNCTION_EXISTS(usleep HAVE_USLEEP)
67 CHECK_FUNCTION_EXISTS(getdtablesize HAVE_GETDTABLESIZE)
68 CHECK_FUNCTION_EXISTS(sysconf HAVE_SYSCONF)
69 CHECK_FUNCTION_EXISTS(readv HAVE_READV)
70 CHECK_FUNCTION_EXISTS(popen HAVE_POPEN)
71 CHECK_FUNCTION_EXISTS(signal HAVE_SIGNAL)
72 CHECK_FUNCTION_EXISTS(snprintf HAVE_SNPRINTF)
73 CHECK_FUNCTION_EXISTS(vsnprintf HAVE_VSNPRINTF)
74 CHECK_FUNCTION_EXISTS(asprintf HAVE_ASPRINTF)
75 CHECK_FUNCTION_EXISTS(vasprintf HAVE_VASPRINTF)
76 CHECK_FUNCTION_EXISTS(makecontext HAVE_MAKECONTEXT)
77 CHECK_FUNCTION_EXISTS(mmap HAVE_MMAP)
78
79 if(WIN32) #THOSE FILES ARE FUNCTIONS ARE NOT DETECTED BUT THEY SHOULD...
80     set(HAVE_UCONTEXT_H 1)
81     set(HAVE_MAKECONTEXT 1)
82     set(HAVE_SNPRINTF 1)
83     set(HAVE_VSNPRINTF 1)
84 endif(WIN32)
85
86 set(CONTEXT_UCONTEXT 0)
87 SET(CONTEXT_THREADS 0)
88 SET(HAVE_TRACING 0)
89
90 if(enable_tracing)
91         SET(HAVE_TRACING 1)
92 endif(enable_tracing)
93
94 if(enable_jedule)
95         SET(HAVE_JEDULE 1)
96 endif(enable_jedule)
97
98 if(enable_latency_bound_tracking)
99         SET(HAVE_LATENCY_BOUND_TRACKING 1)
100 else(enable_latency_bound_tracking)
101   if(enable_gtnets)
102     message(STATUS "Warning : Turning latency_bound_tracking to ON because GTNeTs is ON")
103     SET(enable_latency_bound_tracking ON)
104     SET(HAVE_LATENCY_BOUND_TRACKING 1)
105   else(enable_gtnets)
106     SET(HAVE_LATENCY_BOUND_TRACKING 0)
107   endif(enable_gtnets)
108 endif(enable_latency_bound_tracking)
109
110 if(enable_model-checking AND HAVE_MMAP)
111         SET(HAVE_MC 1)
112         SET(MMALLOC_WANT_OVERIDE_LEGACY 1)
113 else(enable_model-checking AND HAVE_MMAP)
114         SET(HAVE_MC 0)
115         SET(MMALLOC_WANT_OVERIDE_LEGACY 0)
116 endif(enable_model-checking AND HAVE_MMAP)
117
118 #--------------------------------------------------------------------------------------------------
119 ### Check for some architecture dependent values
120 CHECK_TYPE_SIZE(int SIZEOF_INT)
121 CHECK_TYPE_SIZE(void* SIZEOF_VOIDP)
122
123
124 #--------------------------------------------------------------------------------------------------
125 ### Initialize of CONTEXT THREADS
126
127 if(pthread)
128         set(pthread 1)
129 elseif(pthread)
130         set(pthread 0)
131 endif(pthread)
132
133 if(pthread)
134         ### HAVE_SEM_INIT
135         
136         if(HAVE_SEM_INIT_LIB)
137                 exec_program("${CMAKE_C_COMPILER} -lpthread ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_sem_init.c" OUTPUT_VARIABLE HAVE_SEM_INIT_run)
138                 if(HAVE_SEM_INIT_run)
139                         set(HAVE_SEM_INIT 0)
140                 else(HAVE_SEM_INIT_run)
141                         set(HAVE_SEM_INIT 1)
142                 endif(HAVE_SEM_INIT_run)
143         endif(HAVE_SEM_INIT_LIB)
144
145         ### HAVE_SEM_TIMEDWAIT
146
147         if(HAVE_SEM_TIMEDWAIT_LIB)
148                 exec_program("${CMAKE_C_COMPILER} -lpthread ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_sem_timedwait.c" OUTPUT_VARIABLE HAVE_SEM_TIMEDWAIT_run)
149                 if(HAVE_SEM_TIMEDWAIT_run)
150                         set(HAVE_SEM_TIMEDWAIT 0)
151                 else(HAVE_SEM_TIMEDWAIT_run)
152                         set(HAVE_SEM_TIMEDWAIT 1)
153                 endif(HAVE_SEM_TIMEDWAIT_run)
154         endif(HAVE_SEM_TIMEDWAIT_LIB)
155
156         ### HAVE_MUTEX_TIMEDLOCK
157
158         if(HAVE_MUTEX_TIMEDLOCK_LIB)
159                 exec_program("${CMAKE_C_COMPILER} -lpthread ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_mutex_timedlock.c" OUTPUT_VARIABLE HAVE_SEM_TIMEDWAIT_run)
160                 if(HAVE_MUTEX_TIMEDLOCK_run)
161                         set(HAVE_MUTEX_TIMEDLOCK 0)
162                 else(HAVE_MUTEX_TIMEDLOCK_run)
163                         set(HAVE_MUTEX_TIMEDLOCK 1)
164                 endif(HAVE_MUTEX_TIMEDLOCK_run)
165         endif(HAVE_MUTEX_TIMEDLOCK_LIB)
166 endif(pthread)
167
168 # AC_CHECK_MCSC(mcsc=yes, mcsc=no) 
169 set(mcsc_flags "")
170 if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
171         set(mcsc_flags "-D_XOPEN_SOURCE")
172 endif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
173
174 if(WIN32)
175     if(__VISUALC__)
176         set(mcsc_flags "/D_XBT_WIN32 /I${CMAKE_HOME_DIRECTORY}/include/xbt /I${CMAKE_HOME_DIRECTORY}/src/xbt")
177         endif(__VISUALC__)
178         if(__GNUC__)
179                 set(mcsc_flags "-D_XBT_WIN32 -I${CMAKE_HOME_DIRECTORY}/include/xbt -I${CMAKE_HOME_DIRECTORY}/src/xbt")
180         endif(__GNUC__)
181 endif(WIN32)
182
183 IF(CMAKE_CROSSCOMPILING)
184         IF(WIN32)
185                 set(windows_context "yes")
186                 set(IS_WINDOWS 1)       
187         ENDIF(WIN32)
188 ELSE(CMAKE_CROSSCOMPILING)
189         try_run(RUN_mcsc_VAR COMPILE_mcsc_VAR
190                 ${simgrid_BINARY_DIR}
191                 ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_AC_CHECK_MCSC.c
192                 COMPILE_DEFINITIONS "${mcsc_flags}"
193                 OUTPUT_VARIABLE var_compil
194                 )
195                 
196                 if(EXISTS "${simgrid_BINARY_DIR}/conftestval" AND COMPILE_mcsc_VAR)
197                         file(READ "${simgrid_BINARY_DIR}/conftestval" mcsc)
198                         STRING(REPLACE "\n" "" mcsc "${mcsc}")
199                         if(mcsc)
200                                 set(mcsc "yes")
201                         elseif(mcsc)
202                                 set(mcsc "no")
203                         endif(mcsc)
204                 else(EXISTS "${simgrid_BINARY_DIR}/conftestval" AND COMPILE_mcsc_VAR)
205                         set(mcsc "no")
206                 endif(EXISTS "${simgrid_BINARY_DIR}/conftestval" AND COMPILE_mcsc_VAR)
207 ENDIF(CMAKE_CROSSCOMPILING)
208
209 if(mcsc MATCHES "no" AND pthread)
210         if(HAVE_WINDOWS_H)
211                 set(windows_context "yes")
212                 set(IS_WINDOWS 1)
213         elseif(HAVE_WINDOWS_H)
214                 message(FATAL_ERROR "no appropriate backend found")
215         endif(HAVE_WINDOWS_H)
216 endif(mcsc MATCHES "no" AND pthread)
217
218 #Only windows
219
220 if(WIN32)
221         if(NOT HAVE_WINDOWS_H)
222                 message(FATAL_ERROR "no appropriate backend found windows")
223         endif(NOT HAVE_WINDOWS_H)
224 endif(WIN32)
225
226 if(windows_context MATCHES "yes")
227         message(STATUS "Context change to windows")
228 endif(windows_context MATCHES "yes")
229
230 #If can have both context
231
232 if(mcsc)
233         set(CONTEXT_UCONTEXT 1)
234 endif(mcsc)
235
236 if(pthread)
237         set(CONTEXT_THREADS 1)
238 endif(pthread)
239
240
241 ###############
242 ## SVN version check
243 ##
244 if(IS_DIRECTORY ${CMAKE_HOME_DIRECTORY}/.svn)
245         find_file(SVN ".svn" ${CMAKE_HOME_DIRECTORY})
246         exec_program("svnversion ${CMAKE_HOME_DIRECTORY}" OUTPUT_VARIABLE "SVN_VERSION")
247         message(STATUS "svn version ${SVN_VERSION}")
248 endif(IS_DIRECTORY ${CMAKE_HOME_DIRECTORY}/.svn)
249
250 if(IS_DIRECTORY ${CMAKE_HOME_DIRECTORY}/.git)
251
252         exec_program("git --git-dir=${CMAKE_HOME_DIRECTORY}/.git log --oneline -1" OUTPUT_VARIABLE "GIT_VERSION")
253         exec_program("git --git-dir=${CMAKE_HOME_DIRECTORY}/.git log -n 1 --format=%ai ." OUTPUT_VARIABLE "GIT_DATE")
254         
255         string(REGEX REPLACE " .*" "" GIT_VERSION "${GIT_VERSION}")
256         STRING(REPLACE " +0000" "" GIT_DATE ${GIT_DATE})
257         STRING(REPLACE " " "~" GIT_DATE ${GIT_DATE})
258         STRING(REPLACE ":" "-" GIT_DATE ${GIT_DATE})
259
260         exec_program("git config --get svn-remote.svn.url"
261                 OUTPUT_VARIABLE url
262                 RETURN_VALUE ret)
263         if(ret EQUAL 0)
264                 exec_program("git svn info" ${CMAKE_HOME_DIRECTORY}
265                         OUTPUT_VARIABLE "GIT_SVN_VERSION")
266                 string(REPLACE "\n" ";" GIT_SVN_VERSION ${GIT_SVN_VERSION})
267                 foreach(line ${GIT_SVN_VERSION})
268                         string(REGEX MATCH "^Revision:.*" line_good ${line})
269                         if(line_good)
270                                 string(REPLACE "Revision: " ""
271                                         line_good ${line_good})
272                                 set(SVN_VERSION ${line_good})
273                         endif(line_good)
274                 endforeach(line ${GIT_SVN_VERSION})
275         endif(ret EQUAL 0)
276 endif(IS_DIRECTORY ${CMAKE_HOME_DIRECTORY}/.git)
277
278 ###################################
279 ## SimGrid and GRAS specific checks
280 ##
281
282 IF(NOT CMAKE_CROSSCOMPILING)
283 # Check architecture signature begin
284 try_run(RUN_GRAS_VAR COMPILE_GRAS_VAR
285         ${simgrid_BINARY_DIR}
286         ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_GRAS_ARCH.c
287         RUN_OUTPUT_VARIABLE var1
288         )
289 if(BIGENDIAN)
290   set(val_big "B${var1}")
291   set(GRAS_BIGENDIAN 1)
292 else(BIGENDIAN)
293   set(val_big "l${var1}")
294   set(GRAS_BIGENDIAN 0)
295 endif(BIGENDIAN)
296
297 if(val_big MATCHES "l_C:1/1:_I:2/1:4/1:4/1:8/1:_P:4/1:4/1:_D:4/1:8/1:")
298         #gras_arch=0; gras_size=32; gras_arch_name=little32_1;
299         SET(GRAS_ARCH_32_BITS 1)
300         SET(GRAS_THISARCH 0)
301 endif(val_big MATCHES "l_C:1/1:_I:2/1:4/1:4/1:8/1:_P:4/1:4/1:_D:4/1:8/1:")
302 if(val_big MATCHES "l_C:1/1:_I:2/2:4/2:4/2:8/2:_P:4/2:4/2:_D:4/2:8/2:")
303         #gras_arch=1; gras_size=32; gras_arch_name=little32_2;
304         SET(GRAS_ARCH_32_BITS 1)
305         SET(GRAS_THISARCH 1)
306 endif(val_big MATCHES "l_C:1/1:_I:2/2:4/2:4/2:8/2:_P:4/2:4/2:_D:4/2:8/2:")
307 if(val_big MATCHES "l_C:1/1:_I:2/2:4/4:4/4:8/4:_P:4/4:4/4:_D:4/4:8/4:") 
308         #gras_arch=2; gras_size=32; gras_arch_name=little32_4;
309         SET(GRAS_ARCH_32_BITS 1)
310         SET(GRAS_THISARCH 2)
311 endif(val_big MATCHES "l_C:1/1:_I:2/2:4/4:4/4:8/4:_P:4/4:4/4:_D:4/4:8/4:")
312 if(val_big MATCHES "l_C:1/1:_I:2/2:4/4:4/4:8/8:_P:4/4:4/4:_D:4/4:8/8:") 
313         #gras_arch=3; gras_size=32; gras_arch_name=little32_8;
314         SET(GRAS_ARCH_32_BITS 1)
315         SET(GRAS_THISARCH 3)
316 endif(val_big MATCHES "l_C:1/1:_I:2/2:4/4:4/4:8/8:_P:4/4:4/4:_D:4/4:8/8:") 
317 if(val_big MATCHES "l_C:1/1:_I:2/2:4/4:8/8:8/8:_P:8/8:8/8:_D:4/4:8/8:") 
318         #gras_arch=4; gras_size=64; gras_arch_name=little64;
319         SET(GRAS_ARCH_32_BITS 0)
320         SET(GRAS_THISARCH 4)
321 endif(val_big MATCHES "l_C:1/1:_I:2/2:4/4:8/8:8/8:_P:8/8:8/8:_D:4/4:8/8:")
322
323 if(val_big MATCHES "B_C:1/1:_I:2/2:4/4:4/4:8/8:_P:4/4:4/4:_D:4/4:8/8:") 
324         #gras_arch=5; gras_size=32; gras_arch_name=big32;
325         SET(GRAS_ARCH_32_BITS 1)
326         SET(GRAS_THISARCH 5)
327 endif(val_big MATCHES "B_C:1/1:_I:2/2:4/4:4/4:8/8:_P:4/4:4/4:_D:4/4:8/8:")
328 if(val_big MATCHES "B_C:1/1:_I:2/2:4/4:4/4:8/8:_P:4/4:4/4:_D:4/4:8/4:") 
329         #gras_arch=6; gras_size=32; gras_arch_name=big32_8_4;
330         SET(GRAS_ARCH_32_BITS 1)
331         SET(GRAS_THISARCH 6)
332 endif(val_big MATCHES "B_C:1/1:_I:2/2:4/4:4/4:8/8:_P:4/4:4/4:_D:4/4:8/4:")
333 if(val_big MATCHES "B_C:1/1:_I:2/2:4/4:4/4:8/4:_P:4/4:4/4:_D:4/4:8/4:") 
334         #gras_arch=7; gras_size=32; gras_arch_name=big32_4;
335         SET(GRAS_ARCH_32_BITS 1)
336         SET(GRAS_THISARCH 7)
337 endif(val_big MATCHES "B_C:1/1:_I:2/2:4/4:4/4:8/4:_P:4/4:4/4:_D:4/4:8/4:")
338 if(val_big MATCHES "B_C:1/1:_I:2/2:4/2:4/2:8/2:_P:4/2:4/2:_D:4/2:8/2:") 
339         #gras_arch=8; gras_size=32; gras_arch_name=big32_2;
340         SET(GRAS_ARCH_32_BITS 1)
341         SET(GRAS_THISARCH 8)
342 endif(val_big MATCHES "B_C:1/1:_I:2/2:4/2:4/2:8/2:_P:4/2:4/2:_D:4/2:8/2:") 
343 if(val_big MATCHES "B_C:1/1:_I:2/2:4/4:8/8:8/8:_P:8/8:8/8:_D:4/4:8/8:") 
344         #gras_arch=9; gras_size=64; gras_arch_name=big64;
345         SET(GRAS_ARCH_32_BITS 0)
346         SET(GRAS_THISARCH 9)
347 endif(val_big MATCHES "B_C:1/1:_I:2/2:4/4:8/8:8/8:_P:8/8:8/8:_D:4/4:8/8:")
348 if(val_big MATCHES "B_C:1/1:_I:2/2:4/4:8/8:8/8:_P:8/8:8/8:_D:4/4:8/4:") 
349         #gras_arch=10;gras_size=64; gras_arch_name=big64_8_4;
350         SET(GRAS_ARCH_32_BITS 0)
351         SET(GRAS_THISARCH 10)
352 endif(val_big MATCHES "B_C:1/1:_I:2/2:4/4:8/8:8/8:_P:8/8:8/8:_D:4/4:8/4:") 
353
354
355 # Check architecture signature end
356 try_run(RUN_GRAS_VAR COMPILE_GRAS_VAR
357         ${simgrid_BINARY_DIR}
358         ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_GRAS_CHECK_STRUCT_COMPACTION.c
359         RUN_OUTPUT_VARIABLE var2
360         )
361 separate_arguments(var2)
362 foreach(var_tmp ${var2})
363         set(${var_tmp} 1)
364 endforeach(var_tmp ${var2})
365
366 # Check for [SIZEOF_MAX]
367 try_run(RUN_SM_VAR COMPILE_SM_VAR
368         ${simgrid_BINARY_DIR}
369         ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_max_size.c
370         RUN_OUTPUT_VARIABLE var3
371         )
372 SET(SIZEOF_MAX ${var3})
373 ENDIF(NOT CMAKE_CROSSCOMPILING)
374
375 #--------------------------------------------------------------------------------------------------
376
377 set(makecontext_CPPFLAGS_2 "")
378 if(HAVE_MAKECONTEXT OR WIN32)
379         set(makecontext_CPPFLAGS "-DTEST_makecontext")
380         if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
381                 set(makecontext_CPPFLAGS_2 "-DOSX")
382         endif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
383         
384     if(WIN32 AND __VISUALC__)
385         set(makecontext_CPPFLAGS "/DTEST_makecontext")
386             set(makecontext_CPPFLAGS_2 "/D_XBT_WIN32 /I${CMAKE_HOME_DIRECTORY}/include/xbt /I${CMAKE_HOME_DIRECTORY}/src/xbt")
387         endif(WIN32 AND __VISUALC__)
388         if(WIN32 AND __GNUC__)
389             set(makecontext_CPPFLAGS "-DTEST_makecontext")
390             set(makecontext_CPPFLAGS_2 "-D_XBT_WIN32 -I${CMAKE_HOME_DIRECTORY}/include/xbt -I${CMAKE_HOME_DIRECTORY}/src/xbt")
391         endif(WIN32 AND __GNUC__)
392         
393         try_run(RUN_makecontext_VAR COMPILE_makecontext_VAR
394                 ${simgrid_BINARY_DIR}
395                 ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_stacksetup.c
396                 COMPILE_DEFINITIONS "${makecontext_CPPFLAGS} ${makecontext_CPPFLAGS_2}"
397                 )
398         file(READ ${simgrid_BINARY_DIR}/conftestval MAKECONTEXT_ADDR_SIZE)
399         string(REPLACE "\n" "" MAKECONTEXT_ADDR_SIZE "${MAKECONTEXT_ADDR_SIZE}")
400         string(REGEX MATCH ;^.*,;MAKECONTEXT_ADDR "${MAKECONTEXT_ADDR_SIZE}")
401         string(REGEX MATCH ;,.*$; MAKECONTEXT_SIZE "${MAKECONTEXT_ADDR_SIZE}")
402         string(REPLACE "," "" makecontext_addr "${MAKECONTEXT_ADDR}")
403         string(REPLACE "," "" makecontext_size "${MAKECONTEXT_SIZE}")   
404         set(pth_skaddr_makecontext "#define pth_skaddr_makecontext(skaddr,sksize) (${makecontext_addr})")
405         set(pth_sksize_makecontext "#define pth_sksize_makecontext(skaddr,sksize) (${makecontext_size})")
406         
407 endif(HAVE_MAKECONTEXT OR WIN32)
408
409 #--------------------------------------------------------------------------------------------------
410
411 ### check for stackgrowth
412 if (NOT CMAKE_CROSSCOMPILING)
413         try_run(RUN_makecontext_VAR COMPILE_makecontext_VAR
414                 ${simgrid_BINARY_DIR}
415                 ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_stackgrowth.c
416                 )
417 file(READ "${simgrid_BINARY_DIR}/conftestval" stack)
418 if(stack MATCHES "down")
419         set(PTH_STACKGROWTH "-1")
420 endif(stack MATCHES "down")
421 if(stack MATCHES "up")
422         set(PTH_STACKGROWTH "1")
423 endif(stack MATCHES "up")
424
425 endif(NOT CMAKE_CROSSCOMPILING)
426 ###############
427 ## System checks
428 ##
429
430 #SG_CONFIGURE_PART([System checks...])
431 #AC_PROG_CC(xlC gcc cc) -auto
432 #AM_SANITY_CHECK -auto
433
434 #AC_PROG_MAKE_SET
435
436
437 #AC_PRINTF_NULL
438 try_run(RUN_PRINTF_NULL_VAR COMPILE_PRINTF_NULL_VAR
439         ${simgrid_BINARY_DIR}
440         ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_printf_null.c
441         )
442
443 if(RUN_PRINTF_NULL_VAR MATCHES "FAILED_TO_RUN")
444 SET(PRINTF_NULL_WORKING "0")
445 else(RUN_PRINTF_NULL_VAR MATCHES "FAILED_TO_RUN")
446 SET(PRINTF_NULL_WORKING "1")
447 endif(RUN_PRINTF_NULL_VAR MATCHES "FAILED_TO_RUN")
448
449 #AC_CHECK_VA_COPY
450
451 set(diff_va "va_copy((d),(s))"
452 "VA_COPY((d),(s))"
453 "__va_copy((d),(s))"
454 "__builtin_va_copy((d),(s))"
455 "do { (d) = (s)\; } while (0)"
456 "do { *(d) = *(s)\; } while (0)"
457 "memcpy((void *)&(d), (void *)&(s), sizeof(s))"
458 "memcpy((void *)(d), (void *)(s), sizeof(*(s)))"
459 )
460
461 foreach(fct ${diff_va})
462         write_file("${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_va_copy.c" "#include <stdlib.h>
463         #include <stdarg.h>
464         #include <string.h>
465         #define DO_VA_COPY(d,s) ${fct}
466         void test(char *str, ...)
467         {
468             va_list ap, ap2;
469             int i;
470             va_start(ap, str);
471             DO_VA_COPY(ap2, ap);
472             for (i = 1; i <= 9; i++) {
473                 int k = (int)va_arg(ap, int);
474                 if (k != i)
475                     abort();
476             }
477             DO_VA_COPY(ap, ap2);
478             for (i = 1; i <= 9; i++) {
479                 int k = (int)va_arg(ap, int);
480                 if (k != i)
481                     abort();
482             }
483             va_end(ap);
484         }
485         int main(int argc, char *argv[])
486         {
487             test("test", 1, 2, 3, 4, 5, 6, 7, 8, 9);
488             exit(0);
489         }"
490         )
491         try_compile(COMPILE_VA_NULL_VAR
492         ${simgrid_BINARY_DIR}
493         ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_va_copy.c
494         )
495         if(COMPILE_VA_NULL_VAR)
496                 string(REGEX REPLACE "\;" "" fctbis ${fct})
497                 if(${fctbis} STREQUAL "va_copy((d),(s))")
498                         set(HAVE_VA_COPY 1)
499                         set(ac_cv_va_copy "C99")
500                         set(__VA_COPY_USE_C99 "va_copy((d),(s))")       
501                 endif(${fctbis} STREQUAL "va_copy((d),(s))")
502
503                 if(${fctbis} STREQUAL "VA_COPY((d),(s))")
504                         set(ac_cv_va_copy "GCM")
505                         set(__VA_COPY_USE_GCM "VA_COPY((d),(s))")
506                 endif(${fctbis} STREQUAL "VA_COPY((d),(s))")
507
508                 if(${fctbis} STREQUAL "__va_copy((d),(s))")
509                         set(ac_cv_va_copy "GCH")
510                         set(__VA_COPY_USE_GCH "__va_copy((d),(s))")
511                 endif(${fctbis} STREQUAL "__va_copy((d),(s))")
512
513                 if(${fctbis} STREQUAL "__builtin_va_copy((d),(s))")
514                         set(ac_cv_va_copy "GCB")
515                         set(__VA_COPY_USE_GCB "__builtin_va_copy((d),(s))")
516                 endif(${fctbis} STREQUAL "__builtin_va_copy((d),(s))")
517
518                 if(${fctbis} STREQUAL "do { (d) = (s) } while (0)")
519                         set(ac_cv_va_copy "ASS")
520                         set(__VA_COPY_USE_ASS "do { (d) = (s); } while (0)")
521                 endif(${fctbis} STREQUAL "do { (d) = (s) } while (0)")
522
523                 if(${fctbis} STREQUAL "do { *(d) = *(s) } while (0)")
524                         set(ac_cv_va_copy "ASP")
525                         set(__VA_COPY_USE_ASP "do { *(d) = *(s); } while (0)")
526                 endif(${fctbis} STREQUAL "do { *(d) = *(s) } while (0)")
527
528                 if(${fctbis} STREQUAL "memcpy((void *)&(d), (void *)&(s), sizeof(s))")
529                         set(ac_cv_va_copy "CPS")
530                         set(__VA_COPY_USE_CPS "memcpy((void *)&(d), (void *)&(s), sizeof(s))")
531                 endif(${fctbis} STREQUAL "memcpy((void *)&(d), (void *)&(s), sizeof(s))")
532
533                 if(${fctbis} STREQUAL "memcpy((void *)(d), (void *)(s), sizeof(*(s)))")
534                         set(ac_cv_va_copy "CPP")
535                         set(__VA_COPY_USE_CPP "memcpy((void *)(d), (void *)(s), sizeof(*(s)))")
536                 endif(${fctbis} STREQUAL "memcpy((void *)(d), (void *)(s), sizeof(*(s)))")
537                                 
538                 if(NOT STATUS_OK)
539                 set(__VA_COPY_USE "__VA_COPY_USE_${ac_cv_va_copy}(d, s)")
540                 endif(NOT STATUS_OK)
541                 set(STATUS_OK "1")
542                 
543         endif(COMPILE_VA_NULL_VAR)
544         
545 endforeach(fct ${diff_va})
546
547 #--------------------------------------------------------------------------------------------------
548 ### check for getline
549 try_compile(COMPILE_RESULT_VAR
550         ${simgrid_BINARY_DIR}
551         ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_getline.c
552         )
553
554 if(NOT COMPILE_RESULT_VAR)
555 SET(need_getline "#define SIMGRID_NEED_GETLINE 1")
556 SET(SIMGRID_NEED_GETLINE 1)
557 else(NOT COMPILE_RESULT_VAR)
558 SET(need_getline "")
559 SET(SIMGRID_NEED_GETLINE 0)
560 endif(NOT COMPILE_RESULT_VAR)
561
562 ### check for a working snprintf
563 if(HAVE_SNPRINTF AND HAVE_VSNPRINTF OR WIN32)
564     if(WIN32)
565         #set(HAVE_SNPRINTF 1)
566         #set(HAVE_VSNPRINTF 1)
567     endif(WIN32)
568     
569         if(CMAKE_CROSSCOMPILING)
570                 set(RUN_SNPRINTF_FUNC "cross")
571                 #set(PREFER_PORTABLE_SNPRINTF 1)
572         else(CMAKE_CROSSCOMPILING)
573             try_run(RUN_SNPRINTF_FUNC_VAR COMPILE_SNPRINTF_FUNC_VAR
574                 ${simgrid_BINARY_DIR}
575                 ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_snprintf.c
576             )   
577         endif(CMAKE_CROSSCOMPILING)
578
579         if(CMAKE_CROSSCOMPILING)
580                 set(RUN_VSNPRINTF_FUNC "cross")
581                 set(PREFER_PORTABLE_VSNPRINTF 1)
582         else(CMAKE_CROSSCOMPILING)
583            try_run(RUN_VSNPRINTF_FUNC_VAR COMPILE_VSNPRINTF_FUNC_VAR
584                 ${simgrid_BINARY_DIR}
585                 ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_vsnprintf.c
586            )
587         endif(CMAKE_CROSSCOMPILING)
588         
589         set(PREFER_PORTABLE_SNPRINTF 0)
590         if(RUN_VSNPRINTF_FUNC_VAR MATCHES "FAILED_TO_RUN")
591                 set(PREFER_PORTABLE_SNPRINTF 1)
592         endif(RUN_VSNPRINTF_FUNC_VAR MATCHES "FAILED_TO_RUN")
593         if(RUN_SNPRINTF_FUNC_VAR MATCHES "FAILED_TO_RUN")
594                 set(PREFER_PORTABLE_SNPRINTF 1)
595         endif(RUN_SNPRINTF_FUNC_VAR MATCHES "FAILED_TO_RUN")
596 endif(HAVE_SNPRINTF AND HAVE_VSNPRINTF OR WIN32)
597
598 ### check for asprintf function familly
599 if(HAVE_ASPRINTF)
600         SET(simgrid_need_asprintf "")
601         SET(NEED_ASPRINTF 0)
602 else(HAVE_ASPRINTF)
603         SET(simgrid_need_asprintf "#define SIMGRID_NEED_ASPRINTF 1")
604         SET(NEED_ASPRINTF 1)
605 endif(HAVE_ASPRINTF)
606
607 if(HAVE_VASPRINTF)
608         SET(simgrid_need_vasprintf "")
609         SET(NEED_VASPRINTF 0)
610 else(HAVE_VASPRINTF)
611         SET(simgrid_need_vasprintf "#define SIMGRID_NEED_VASPRINTF 1")
612         SET(NEED_VASPRINTF 1)
613 endif(HAVE_VASPRINTF)
614
615 ### check for addr2line
616
617 find_path(ADDR2LINE NAMES addr2line     PATHS NO_DEFAULT_PATHS  )
618 if(ADDR2LINE)
619 set(ADDR2LINE "${ADDR2LINE}/addr2line")
620 endif(ADDR2LINE)
621
622 ### File to create
623
624 configure_file("${CMAKE_HOME_DIRECTORY}/src/context_sysv_config.h.in"                   "${CMAKE_BINARY_DIR}/src/context_sysv_config.h" @ONLY IMMEDIATE)
625
626 SET( CMAKEDEFINE "#cmakedefine" )
627 configure_file("${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/gras_config.h.in"      "${CMAKE_BINARY_DIR}/src/gras_config.h" @ONLY IMMEDIATE)
628 configure_file("${CMAKE_BINARY_DIR}/src/gras_config.h"                  "${CMAKE_BINARY_DIR}/src/gras_config.h" @ONLY IMMEDIATE)
629 configure_file("${CMAKE_HOME_DIRECTORY}/include/simgrid_config.h.in"            "${CMAKE_BINARY_DIR}/include/simgrid_config.h" @ONLY IMMEDIATE)
630
631 set(top_srcdir "${CMAKE_HOME_DIRECTORY}")
632 set(srcdir "${CMAKE_HOME_DIRECTORY}/src")
633
634 set(exec_prefix ${CMAKE_INSTALL_PREFIX})
635 set(includedir ${CMAKE_INSTALL_PREFIX}/include)
636 set(top_builddir ${CMAKE_HOME_DIRECTORY})
637 set(libdir ${exec_prefix}/lib)
638 set(CMAKE_LINKARGS "${CMAKE_BINARY_DIR}/lib")
639 set(CMAKE_SMPI_COMMAND "export LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/lib:${GTNETS_LIB_PATH}:$LD_LIBRARY_PATH")
640
641 configure_file(${CMAKE_HOME_DIRECTORY}/include/smpi/smpif.h.in ${CMAKE_BINARY_DIR}/include/smpi/smpif.h @ONLY)
642 configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpicc.in ${CMAKE_BINARY_DIR}/bin/smpicc @ONLY)
643 configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpif2c.in ${CMAKE_BINARY_DIR}/bin/smpif2c @ONLY)
644 configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpiff.in ${CMAKE_BINARY_DIR}/bin/smpiff @ONLY)
645 configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpirun.in ${CMAKE_BINARY_DIR}/bin/smpirun @ONLY)
646
647 exec_program("chmod a=rwx ${CMAKE_BINARY_DIR}/bin/smpicc" OUTPUT_VARIABLE OKITOKI)
648 exec_program("chmod a=rwx ${CMAKE_BINARY_DIR}/bin/smpif2c" OUTPUT_VARIABLE OKITOKI)
649 exec_program("chmod a=rwx ${CMAKE_BINARY_DIR}/bin/smpiff" OUTPUT_VARIABLE OKITOKI)
650 exec_program("chmod a=rwx ${CMAKE_BINARY_DIR}/bin/smpirun" OUTPUT_VARIABLE OKITOKI)
651
652 set(generate_files_to_clean
653 ${CMAKE_BINARY_DIR}/src/context_sysv_config.h
654 ${CMAKE_BINARY_DIR}/src/gras_config.h
655 ${CMAKE_BINARY_DIR}/include/simgrid_config.h
656 ${CMAKE_BINARY_DIR}/include/smpi/smpif.h
657 ${CMAKE_BINARY_DIR}/bin/smpicc
658 ${CMAKE_BINARY_DIR}/bin/smpif2c
659 ${CMAKE_BINARY_DIR}/bin/smpiff
660 ${CMAKE_BINARY_DIR}/bin/smpirun
661 ${CMAKE_BINARY_DIR}/bin/colorize
662 ${CMAKE_BINARY_DIR}/bin/simgrid_update_xml
663 ${CMAKE_BINARY_DIR}/examples/smpi/smpi_traced.trace
664 ${CMAKE_BINARY_DIR}/src/supernovae_sg.c
665 ${CMAKE_BINARY_DIR}/src/supernovae_gras.c
666 ${CMAKE_BINARY_DIR}/src/supernovae_smpi.c
667 )
668
669 if("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_HOME_DIRECTORY}")
670 else("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_HOME_DIRECTORY}")
671         configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/hostfile ${CMAKE_BINARY_DIR}/examples/smpi/hostfile COPYONLY)
672         configure_file(${CMAKE_HOME_DIRECTORY}/examples/msg/small_platform.xml ${CMAKE_BINARY_DIR}/examples/msg/small_platform.xml COPYONLY)
673         configure_file(${CMAKE_HOME_DIRECTORY}/examples/msg/small_platform_with_routers.xml ${CMAKE_BINARY_DIR}/examples/msg/small_platform_with_routers.xml COPYONLY)
674         
675         set(generate_files_to_clean
676                 ${generate_files_to_clean}
677                 ${CMAKE_BINARY_DIR}/examples/smpi/hostfile
678                 ${CMAKE_BINARY_DIR}/examples/msg/small_platform.xml
679                 ${CMAKE_BINARY_DIR}/examples/msg/small_platform_with_routers.xml
680                 )
681 endif("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_HOME_DIRECTORY}")
682
683 SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES
684 "${generate_files_to_clean}")