Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
New way to find svn version
[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 else(IS_DIRECTORY ${CMAKE_HOME_DIRECTORY}/.svn)
249         exec_program("git config --get svn-remote.svn.url"
250                 OUTPUT_VARIABLE url
251                 RETURN_VALUE ret)
252 endif(IS_DIRECTORY ${CMAKE_HOME_DIRECTORY}/.svn)
253
254 if(url)
255         exec_program("git --git-dir=${CMAKE_HOME_DIRECTORY}/.git log --oneline -1" OUTPUT_VARIABLE "GIT_VERSION")
256         exec_program("git --git-dir=${CMAKE_HOME_DIRECTORY}/.git log -n 1 --format=%ai ." OUTPUT_VARIABLE "GIT_DATE")
257         
258         string(REGEX REPLACE " .*" "" GIT_VERSION "${GIT_VERSION}")
259         STRING(REPLACE " +0000" "" GIT_DATE ${GIT_DATE})
260         STRING(REPLACE " " "~" GIT_DATE ${GIT_DATE})
261         STRING(REPLACE ":" "-" GIT_DATE ${GIT_DATE})
262         
263         exec_program("git svn info" ${CMAKE_HOME_DIRECTORY}
264                 OUTPUT_VARIABLE "GIT_SVN_VERSION")
265         string(REPLACE "\n" ";" GIT_SVN_VERSION ${GIT_SVN_VERSION})
266         foreach(line ${GIT_SVN_VERSION})
267                 string(REGEX MATCH "^Revision:.*" line_good ${line})
268                 if(line_good)
269                         string(REPLACE "Revision: " ""
270                                 line_good ${line_good})
271                         set(SVN_VERSION ${line_good})
272                 endif(line_good)
273         endforeach(line ${GIT_SVN_VERSION})
274 endif(url)
275
276
277 ###################################
278 ## SimGrid and GRAS specific checks
279 ##
280
281 IF(NOT CMAKE_CROSSCOMPILING)
282 # Check architecture signature begin
283 try_run(RUN_GRAS_VAR COMPILE_GRAS_VAR
284         ${simgrid_BINARY_DIR}
285         ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_GRAS_ARCH.c
286         RUN_OUTPUT_VARIABLE var1
287         )
288 if(BIGENDIAN)
289   set(val_big "B${var1}")
290   set(GRAS_BIGENDIAN 1)
291 else(BIGENDIAN)
292   set(val_big "l${var1}")
293   set(GRAS_BIGENDIAN 0)
294 endif(BIGENDIAN)
295
296 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:")
297         #gras_arch=0; gras_size=32; gras_arch_name=little32_1;
298         SET(GRAS_ARCH_32_BITS 1)
299         SET(GRAS_THISARCH 0)
300 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:")
301 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:")
302         #gras_arch=1; gras_size=32; gras_arch_name=little32_2;
303         SET(GRAS_ARCH_32_BITS 1)
304         SET(GRAS_THISARCH 1)
305 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:")
306 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:") 
307         #gras_arch=2; gras_size=32; gras_arch_name=little32_4;
308         SET(GRAS_ARCH_32_BITS 1)
309         SET(GRAS_THISARCH 2)
310 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:")
311 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:") 
312         #gras_arch=3; gras_size=32; gras_arch_name=little32_8;
313         SET(GRAS_ARCH_32_BITS 1)
314         SET(GRAS_THISARCH 3)
315 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:") 
316 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:") 
317         #gras_arch=4; gras_size=64; gras_arch_name=little64;
318         SET(GRAS_ARCH_32_BITS 0)
319         SET(GRAS_THISARCH 4)
320 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:")
321
322 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:") 
323         #gras_arch=5; gras_size=32; gras_arch_name=big32;
324         SET(GRAS_ARCH_32_BITS 1)
325         SET(GRAS_THISARCH 5)
326 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:")
327 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:") 
328         #gras_arch=6; gras_size=32; gras_arch_name=big32_8_4;
329         SET(GRAS_ARCH_32_BITS 1)
330         SET(GRAS_THISARCH 6)
331 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:")
332 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:") 
333         #gras_arch=7; gras_size=32; gras_arch_name=big32_4;
334         SET(GRAS_ARCH_32_BITS 1)
335         SET(GRAS_THISARCH 7)
336 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:")
337 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:") 
338         #gras_arch=8; gras_size=32; gras_arch_name=big32_2;
339         SET(GRAS_ARCH_32_BITS 1)
340         SET(GRAS_THISARCH 8)
341 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:") 
342 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:") 
343         #gras_arch=9; gras_size=64; gras_arch_name=big64;
344         SET(GRAS_ARCH_32_BITS 0)
345         SET(GRAS_THISARCH 9)
346 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:")
347 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:") 
348         #gras_arch=10;gras_size=64; gras_arch_name=big64_8_4;
349         SET(GRAS_ARCH_32_BITS 0)
350         SET(GRAS_THISARCH 10)
351 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:") 
352
353
354 # Check architecture signature end
355 try_run(RUN_GRAS_VAR COMPILE_GRAS_VAR
356         ${simgrid_BINARY_DIR}
357         ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_GRAS_CHECK_STRUCT_COMPACTION.c
358         RUN_OUTPUT_VARIABLE var2
359         )
360 separate_arguments(var2)
361 foreach(var_tmp ${var2})
362         set(${var_tmp} 1)
363 endforeach(var_tmp ${var2})
364
365 # Check for [SIZEOF_MAX]
366 try_run(RUN_SM_VAR COMPILE_SM_VAR
367         ${simgrid_BINARY_DIR}
368         ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_max_size.c
369         RUN_OUTPUT_VARIABLE var3
370         )
371 SET(SIZEOF_MAX ${var3})
372 ENDIF(NOT CMAKE_CROSSCOMPILING)
373
374 #--------------------------------------------------------------------------------------------------
375
376 set(makecontext_CPPFLAGS_2 "")
377 if(HAVE_MAKECONTEXT OR WIN32)
378         set(makecontext_CPPFLAGS "-DTEST_makecontext")
379         if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
380                 set(makecontext_CPPFLAGS_2 "-DOSX")
381         endif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
382         
383     if(WIN32 AND __VISUALC__)
384         set(makecontext_CPPFLAGS "/DTEST_makecontext")
385             set(makecontext_CPPFLAGS_2 "/D_XBT_WIN32 /I${CMAKE_HOME_DIRECTORY}/include/xbt /I${CMAKE_HOME_DIRECTORY}/src/xbt")
386         endif(WIN32 AND __VISUALC__)
387         if(WIN32 AND __GNUC__)
388             set(makecontext_CPPFLAGS "-DTEST_makecontext")
389             set(makecontext_CPPFLAGS_2 "-D_XBT_WIN32 -I${CMAKE_HOME_DIRECTORY}/include/xbt -I${CMAKE_HOME_DIRECTORY}/src/xbt")
390         endif(WIN32 AND __GNUC__)
391         
392         try_run(RUN_makecontext_VAR COMPILE_makecontext_VAR
393                 ${simgrid_BINARY_DIR}
394                 ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_stacksetup.c
395                 COMPILE_DEFINITIONS "${makecontext_CPPFLAGS} ${makecontext_CPPFLAGS_2}"
396                 )
397         file(READ ${simgrid_BINARY_DIR}/conftestval MAKECONTEXT_ADDR_SIZE)
398         string(REPLACE "\n" "" MAKECONTEXT_ADDR_SIZE "${MAKECONTEXT_ADDR_SIZE}")
399         string(REGEX MATCH ;^.*,;MAKECONTEXT_ADDR "${MAKECONTEXT_ADDR_SIZE}")
400         string(REGEX MATCH ;,.*$; MAKECONTEXT_SIZE "${MAKECONTEXT_ADDR_SIZE}")
401         string(REPLACE "," "" makecontext_addr "${MAKECONTEXT_ADDR}")
402         string(REPLACE "," "" makecontext_size "${MAKECONTEXT_SIZE}")   
403         set(pth_skaddr_makecontext "#define pth_skaddr_makecontext(skaddr,sksize) (${makecontext_addr})")
404         set(pth_sksize_makecontext "#define pth_sksize_makecontext(skaddr,sksize) (${makecontext_size})")
405         
406 endif(HAVE_MAKECONTEXT OR WIN32)
407
408 #--------------------------------------------------------------------------------------------------
409
410 ### check for stackgrowth
411 if (NOT CMAKE_CROSSCOMPILING)
412         try_run(RUN_makecontext_VAR COMPILE_makecontext_VAR
413                 ${simgrid_BINARY_DIR}
414                 ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_stackgrowth.c
415                 )
416 file(READ "${simgrid_BINARY_DIR}/conftestval" stack)
417 if(stack MATCHES "down")
418         set(PTH_STACKGROWTH "-1")
419 endif(stack MATCHES "down")
420 if(stack MATCHES "up")
421         set(PTH_STACKGROWTH "1")
422 endif(stack MATCHES "up")
423
424 endif(NOT CMAKE_CROSSCOMPILING)
425 ###############
426 ## System checks
427 ##
428
429 #SG_CONFIGURE_PART([System checks...])
430 #AC_PROG_CC(xlC gcc cc) -auto
431 #AM_SANITY_CHECK -auto
432
433 #AC_PROG_MAKE_SET
434
435
436 #AC_PRINTF_NULL
437 try_run(RUN_PRINTF_NULL_VAR COMPILE_PRINTF_NULL_VAR
438         ${simgrid_BINARY_DIR}
439         ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_printf_null.c
440         )
441
442 if(RUN_PRINTF_NULL_VAR MATCHES "FAILED_TO_RUN")
443 SET(PRINTF_NULL_WORKING "0")
444 else(RUN_PRINTF_NULL_VAR MATCHES "FAILED_TO_RUN")
445 SET(PRINTF_NULL_WORKING "1")
446 endif(RUN_PRINTF_NULL_VAR MATCHES "FAILED_TO_RUN")
447
448 #AC_CHECK_VA_COPY
449
450 set(diff_va "va_copy((d),(s))"
451 "VA_COPY((d),(s))"
452 "__va_copy((d),(s))"
453 "__builtin_va_copy((d),(s))"
454 "do { (d) = (s)\; } while (0)"
455 "do { *(d) = *(s)\; } while (0)"
456 "memcpy((void *)&(d), (void *)&(s), sizeof(s))"
457 "memcpy((void *)(d), (void *)(s), sizeof(*(s)))"
458 )
459
460 foreach(fct ${diff_va})
461         write_file("${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_va_copy.c" "#include <stdlib.h>
462         #include <stdarg.h>
463         #include <string.h>
464         #define DO_VA_COPY(d,s) ${fct}
465         void test(char *str, ...)
466         {
467             va_list ap, ap2;
468             int i;
469             va_start(ap, str);
470             DO_VA_COPY(ap2, ap);
471             for (i = 1; i <= 9; i++) {
472                 int k = (int)va_arg(ap, int);
473                 if (k != i)
474                     abort();
475             }
476             DO_VA_COPY(ap, ap2);
477             for (i = 1; i <= 9; i++) {
478                 int k = (int)va_arg(ap, int);
479                 if (k != i)
480                     abort();
481             }
482             va_end(ap);
483         }
484         int main(int argc, char *argv[])
485         {
486             test("test", 1, 2, 3, 4, 5, 6, 7, 8, 9);
487             exit(0);
488         }"
489         )
490         try_compile(COMPILE_VA_NULL_VAR
491         ${simgrid_BINARY_DIR}
492         ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_va_copy.c
493         )
494         if(COMPILE_VA_NULL_VAR)
495                 string(REGEX REPLACE "\;" "" fctbis ${fct})
496                 if(${fctbis} STREQUAL "va_copy((d),(s))")
497                         set(HAVE_VA_COPY 1)
498                         set(ac_cv_va_copy "C99")
499                         set(__VA_COPY_USE_C99 "va_copy((d),(s))")       
500                 endif(${fctbis} STREQUAL "va_copy((d),(s))")
501
502                 if(${fctbis} STREQUAL "VA_COPY((d),(s))")
503                         set(ac_cv_va_copy "GCM")
504                         set(__VA_COPY_USE_GCM "VA_COPY((d),(s))")
505                 endif(${fctbis} STREQUAL "VA_COPY((d),(s))")
506
507                 if(${fctbis} STREQUAL "__va_copy((d),(s))")
508                         set(ac_cv_va_copy "GCH")
509                         set(__VA_COPY_USE_GCH "__va_copy((d),(s))")
510                 endif(${fctbis} STREQUAL "__va_copy((d),(s))")
511
512                 if(${fctbis} STREQUAL "__builtin_va_copy((d),(s))")
513                         set(ac_cv_va_copy "GCB")
514                         set(__VA_COPY_USE_GCB "__builtin_va_copy((d),(s))")
515                 endif(${fctbis} STREQUAL "__builtin_va_copy((d),(s))")
516
517                 if(${fctbis} STREQUAL "do { (d) = (s) } while (0)")
518                         set(ac_cv_va_copy "ASS")
519                         set(__VA_COPY_USE_ASS "do { (d) = (s); } while (0)")
520                 endif(${fctbis} STREQUAL "do { (d) = (s) } while (0)")
521
522                 if(${fctbis} STREQUAL "do { *(d) = *(s) } while (0)")
523                         set(ac_cv_va_copy "ASP")
524                         set(__VA_COPY_USE_ASP "do { *(d) = *(s); } while (0)")
525                 endif(${fctbis} STREQUAL "do { *(d) = *(s) } while (0)")
526
527                 if(${fctbis} STREQUAL "memcpy((void *)&(d), (void *)&(s), sizeof(s))")
528                         set(ac_cv_va_copy "CPS")
529                         set(__VA_COPY_USE_CPS "memcpy((void *)&(d), (void *)&(s), sizeof(s))")
530                 endif(${fctbis} STREQUAL "memcpy((void *)&(d), (void *)&(s), sizeof(s))")
531
532                 if(${fctbis} STREQUAL "memcpy((void *)(d), (void *)(s), sizeof(*(s)))")
533                         set(ac_cv_va_copy "CPP")
534                         set(__VA_COPY_USE_CPP "memcpy((void *)(d), (void *)(s), sizeof(*(s)))")
535                 endif(${fctbis} STREQUAL "memcpy((void *)(d), (void *)(s), sizeof(*(s)))")
536                                 
537                 if(NOT STATUS_OK)
538                 set(__VA_COPY_USE "__VA_COPY_USE_${ac_cv_va_copy}(d, s)")
539                 endif(NOT STATUS_OK)
540                 set(STATUS_OK "1")
541                 
542         endif(COMPILE_VA_NULL_VAR)
543         
544 endforeach(fct ${diff_va})
545
546 #--------------------------------------------------------------------------------------------------
547 ### check for getline
548 try_compile(COMPILE_RESULT_VAR
549         ${simgrid_BINARY_DIR}
550         ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_getline.c
551         )
552
553 if(NOT COMPILE_RESULT_VAR)
554 SET(need_getline "#define SIMGRID_NEED_GETLINE 1")
555 SET(SIMGRID_NEED_GETLINE 1)
556 else(NOT COMPILE_RESULT_VAR)
557 SET(need_getline "")
558 SET(SIMGRID_NEED_GETLINE 0)
559 endif(NOT COMPILE_RESULT_VAR)
560
561 ### check for a working snprintf
562 if(HAVE_SNPRINTF AND HAVE_VSNPRINTF OR WIN32)
563     if(WIN32)
564         #set(HAVE_SNPRINTF 1)
565         #set(HAVE_VSNPRINTF 1)
566     endif(WIN32)
567     
568         if(CMAKE_CROSSCOMPILING)
569                 set(RUN_SNPRINTF_FUNC "cross")
570                 #set(PREFER_PORTABLE_SNPRINTF 1)
571         else(CMAKE_CROSSCOMPILING)
572             try_run(RUN_SNPRINTF_FUNC_VAR COMPILE_SNPRINTF_FUNC_VAR
573                 ${simgrid_BINARY_DIR}
574                 ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_snprintf.c
575             )   
576         endif(CMAKE_CROSSCOMPILING)
577
578         if(CMAKE_CROSSCOMPILING)
579                 set(RUN_VSNPRINTF_FUNC "cross")
580                 set(PREFER_PORTABLE_VSNPRINTF 1)
581         else(CMAKE_CROSSCOMPILING)
582            try_run(RUN_VSNPRINTF_FUNC_VAR COMPILE_VSNPRINTF_FUNC_VAR
583                 ${simgrid_BINARY_DIR}
584                 ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_vsnprintf.c
585            )
586         endif(CMAKE_CROSSCOMPILING)
587         
588         set(PREFER_PORTABLE_SNPRINTF 0)
589         if(RUN_VSNPRINTF_FUNC_VAR MATCHES "FAILED_TO_RUN")
590                 set(PREFER_PORTABLE_SNPRINTF 1)
591         endif(RUN_VSNPRINTF_FUNC_VAR MATCHES "FAILED_TO_RUN")
592         if(RUN_SNPRINTF_FUNC_VAR MATCHES "FAILED_TO_RUN")
593                 set(PREFER_PORTABLE_SNPRINTF 1)
594         endif(RUN_SNPRINTF_FUNC_VAR MATCHES "FAILED_TO_RUN")
595 endif(HAVE_SNPRINTF AND HAVE_VSNPRINTF OR WIN32)
596
597 ### check for asprintf function familly
598 if(HAVE_ASPRINTF)
599         SET(simgrid_need_asprintf "")
600         SET(NEED_ASPRINTF 0)
601 else(HAVE_ASPRINTF)
602         SET(simgrid_need_asprintf "#define SIMGRID_NEED_ASPRINTF 1")
603         SET(NEED_ASPRINTF 1)
604 endif(HAVE_ASPRINTF)
605
606 if(HAVE_VASPRINTF)
607         SET(simgrid_need_vasprintf "")
608         SET(NEED_VASPRINTF 0)
609 else(HAVE_VASPRINTF)
610         SET(simgrid_need_vasprintf "#define SIMGRID_NEED_VASPRINTF 1")
611         SET(NEED_VASPRINTF 1)
612 endif(HAVE_VASPRINTF)
613
614 ### check for addr2line
615
616 find_path(ADDR2LINE NAMES addr2line     PATHS NO_DEFAULT_PATHS  )
617 if(ADDR2LINE)
618 set(ADDR2LINE "${ADDR2LINE}/addr2line")
619 endif(ADDR2LINE)
620
621 ### File to create
622
623 configure_file("${CMAKE_HOME_DIRECTORY}/src/context_sysv_config.h.in"                   "${CMAKE_BINARY_DIR}/src/context_sysv_config.h" @ONLY IMMEDIATE)
624
625 SET( CMAKEDEFINE "#cmakedefine" )
626 configure_file("${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/gras_config.h.in"      "${CMAKE_BINARY_DIR}/src/gras_config.h" @ONLY IMMEDIATE)
627 configure_file("${CMAKE_BINARY_DIR}/src/gras_config.h"                  "${CMAKE_BINARY_DIR}/src/gras_config.h" @ONLY IMMEDIATE)
628 configure_file("${CMAKE_HOME_DIRECTORY}/include/simgrid_config.h.in"            "${CMAKE_BINARY_DIR}/include/simgrid_config.h" @ONLY IMMEDIATE)
629
630 set(top_srcdir "${CMAKE_HOME_DIRECTORY}")
631 set(srcdir "${CMAKE_HOME_DIRECTORY}/src")
632
633 set(exec_prefix ${CMAKE_INSTALL_PREFIX})
634 set(includedir ${CMAKE_INSTALL_PREFIX}/include)
635 set(top_builddir ${CMAKE_HOME_DIRECTORY})
636 set(libdir ${exec_prefix}/lib)
637 set(CMAKE_LINKARGS "${CMAKE_BINARY_DIR}/lib")
638 set(CMAKE_SMPI_COMMAND "export LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/lib:${GTNETS_LIB_PATH}:$LD_LIBRARY_PATH")
639
640 configure_file(${CMAKE_HOME_DIRECTORY}/include/smpi/smpif.h.in ${CMAKE_BINARY_DIR}/include/smpi/smpif.h @ONLY)
641 configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpicc.in ${CMAKE_BINARY_DIR}/bin/smpicc @ONLY)
642 configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpif2c.in ${CMAKE_BINARY_DIR}/bin/smpif2c @ONLY)
643 configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpiff.in ${CMAKE_BINARY_DIR}/bin/smpiff @ONLY)
644 configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpirun.in ${CMAKE_BINARY_DIR}/bin/smpirun @ONLY)
645
646 exec_program("chmod a=rwx ${CMAKE_BINARY_DIR}/bin/smpicc" OUTPUT_VARIABLE OKITOKI)
647 exec_program("chmod a=rwx ${CMAKE_BINARY_DIR}/bin/smpif2c" OUTPUT_VARIABLE OKITOKI)
648 exec_program("chmod a=rwx ${CMAKE_BINARY_DIR}/bin/smpiff" OUTPUT_VARIABLE OKITOKI)
649 exec_program("chmod a=rwx ${CMAKE_BINARY_DIR}/bin/smpirun" OUTPUT_VARIABLE OKITOKI)
650
651 set(generate_files_to_clean
652 ${CMAKE_BINARY_DIR}/src/context_sysv_config.h
653 ${CMAKE_BINARY_DIR}/src/gras_config.h
654 ${CMAKE_BINARY_DIR}/include/simgrid_config.h
655 ${CMAKE_BINARY_DIR}/include/smpi/smpif.h
656 ${CMAKE_BINARY_DIR}/bin/smpicc
657 ${CMAKE_BINARY_DIR}/bin/smpif2c
658 ${CMAKE_BINARY_DIR}/bin/smpiff
659 ${CMAKE_BINARY_DIR}/bin/smpirun
660 ${CMAKE_BINARY_DIR}/bin/colorize
661 ${CMAKE_BINARY_DIR}/bin/simgrid_update_xml
662 ${CMAKE_BINARY_DIR}/examples/smpi/smpi_traced.trace
663 ${CMAKE_BINARY_DIR}/src/supernovae_sg.c
664 ${CMAKE_BINARY_DIR}/src/supernovae_gras.c
665 ${CMAKE_BINARY_DIR}/src/supernovae_smpi.c
666 )
667
668 if("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_HOME_DIRECTORY}")
669 else("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_HOME_DIRECTORY}")
670         configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/hostfile ${CMAKE_BINARY_DIR}/examples/smpi/hostfile COPYONLY)
671         configure_file(${CMAKE_HOME_DIRECTORY}/examples/msg/small_platform.xml ${CMAKE_BINARY_DIR}/examples/msg/small_platform.xml COPYONLY)
672         configure_file(${CMAKE_HOME_DIRECTORY}/examples/msg/small_platform_with_routers.xml ${CMAKE_BINARY_DIR}/examples/msg/small_platform_with_routers.xml COPYONLY)
673         
674         set(generate_files_to_clean
675                 ${generate_files_to_clean}
676                 ${CMAKE_BINARY_DIR}/examples/smpi/hostfile
677                 ${CMAKE_BINARY_DIR}/examples/msg/small_platform.xml
678                 ${CMAKE_BINARY_DIR}/examples/msg/small_platform_with_routers.xml
679                 )
680 endif("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_HOME_DIRECTORY}")
681
682 SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES
683 "${generate_files_to_clean}")