Logo AND Algorithmique Numérique Distribuée

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