Logo AND Algorithmique Numérique Distribuée

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