Logo AND Algorithmique Numérique Distribuée

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