Logo AND Algorithmique Numérique Distribuée

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