Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'vmtrace'
[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 # x86_64
7 # x86
8 # i.86
9
10 IF(CMAKE_SYSTEM_PROCESSOR MATCHES ".86")
11   IF(${ARCH_32_BITS})
12     set(PROCESSOR_i686 1)
13     set(SIMGRID_SYSTEM_PROCESSOR "${CMAKE_SYSTEM_PROCESSOR}")
14     message(STATUS "System processor: ${CMAKE_SYSTEM_PROCESSOR}")
15   ELSE()
16     message(STATUS "System processor: amd64")
17     set(SIMGRID_SYSTEM_PROCESSOR "amd64")
18     set(PROCESSOR_x86_64 1)
19     set(PROCESSOR_i686 0)
20   ENDIF()
21   set(HAVE_RAWCTX 1)
22
23 ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "^alpha")
24   message(STATUS "System processor: alpha")
25
26 ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm")
27   # Subdir is "arm" for both big-endian (arm) and little-endian (armel).
28   message(STATUS "System processor: arm")
29
30 ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "^mips")
31   # mips* machines are bi-endian mostly so processor does not tell
32   # endianess of the underlying system.
33   message(STATUS "System processor: ${CMAKE_SYSTEM_PROCESSOR}" "mips" "mipsel" "mipseb")
34
35 ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64")
36   message(STATUS "System processor: ppc64")
37
38 ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)")
39   message(STATUS "System processor: ppc")
40
41 ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "^sparc")
42   # Both flavours can run on the same processor
43   message(STATUS "System processor: ${CMAKE_SYSTEM_PROCESSOR}" "sparc" "sparcv9")
44
45 ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "^(parisc|hppa)")
46   message(STATUS "System processor: parisc" "parisc64")
47
48 ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "^s390")
49   # s390 binaries can run on s390x machines
50   message(STATUS "System processor: ${CMAKE_SYSTEM_PROCESSOR}" "s390" "s390x")
51
52 ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "^sh")
53   message(STATUS "System processor: sh")
54
55 ELSE() #PROCESSOR NOT FOUND
56   message(STATUS "PROCESSOR NOT FOUND: ${CMAKE_SYSTEM_PROCESSOR}")
57
58 ENDIF()
59
60 message(STATUS "Cmake version ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}")
61
62 include(CheckFunctionExists)
63 include(CheckTypeSize)
64 include(CheckIncludeFile)
65 include(CheckIncludeFiles)
66 include(CheckLibraryExists)
67 include(TestBigEndian)
68 TEST_BIG_ENDIAN(BIGENDIAN)
69
70 include(FindGraphviz)
71 if(WIN32)
72   include(FindPcreWin)
73 else()
74   include(FindPCRE)
75 endif()
76
77 set(HAVE_GTNETS 0)
78 if(enable_gtnets)
79   include(FindGTnets)
80 endif()
81 if(enable_smpi)
82   include(FindF2c)
83   SET(HAVE_SMPI 1)
84 endif()
85 if(enable_lua)
86   include(FindLua51Simgrid)
87 endif()
88 set(HAVE_NS3 0)
89 if(enable_ns3)
90   include(FindNS3)
91 endif()
92
93 # Checks for header libraries functions.
94 CHECK_LIBRARY_EXISTS(pthread    pthread_create                  "" pthread)
95 CHECK_LIBRARY_EXISTS(pthread    sem_init                                "" HAVE_SEM_INIT_LIB)
96 CHECK_LIBRARY_EXISTS(pthread    sem_open                                "" HAVE_SEM_OPEN_LIB)
97 CHECK_LIBRARY_EXISTS(pthread    sem_timedwait                   "" HAVE_SEM_TIMEDWAIT_LIB)
98 CHECK_LIBRARY_EXISTS(pthread    pthread_mutex_timedlock "" HAVE_MUTEX_TIMEDLOCK_LIB)
99 CHECK_LIBRARY_EXISTS(rt                 clock_gettime                   "" HAVE_POSIX_GETTIME)
100
101 CHECK_INCLUDE_FILES("time.h;sys/time.h" TIME_WITH_SYS_TIME)
102 CHECK_INCLUDE_FILES("stdlib.h;stdarg.h;string.h;float.h" STDC_HEADERS)
103 CHECK_INCLUDE_FILE("pthread.h" HAVE_PTHREAD_H)
104 CHECK_INCLUDE_FILE("valgrind/valgrind.h" HAVE_VALGRIND_VALGRIND_H)
105 CHECK_INCLUDE_FILE("socket.h" HAVE_SOCKET_H)
106 CHECK_INCLUDE_FILE("sys/socket.h" HAVE_SYS_SOCKET_H)
107 CHECK_INCLUDE_FILE("stat.h" HAVE_STAT_H)
108 CHECK_INCLUDE_FILE("sys/stat.h" HAVE_SYS_STAT_H)
109 CHECK_INCLUDE_FILE("windows.h" HAVE_WINDOWS_H)
110 CHECK_INCLUDE_FILE("winsock.h" HAVE_WINSOCK_H)
111 CHECK_INCLUDE_FILE("winsock2.h" HAVE_WINSOCK2_H)
112 CHECK_INCLUDE_FILE("WinDef.h" HAVE_WINDEF_H)
113 CHECK_INCLUDE_FILE("errno.h" HAVE_ERRNO_H)
114 CHECK_INCLUDE_FILE("unistd.h" HAVE_UNISTD_H)
115 CHECK_INCLUDE_FILE("execinfo.h" HAVE_EXECINFO_H)
116 CHECK_INCLUDE_FILE("signal.h" HAVE_SIGNAL_H)
117 CHECK_INCLUDE_FILE("sys/time.h" HAVE_SYS_TIME_H)
118 CHECK_INCLUDE_FILE("sys/param.h" HAVE_SYS_PARAM_H)
119 CHECK_INCLUDE_FILE("sys/sysctl.h" HAVE_SYS_SYSCTL_H)
120 CHECK_INCLUDE_FILE("time.h" HAVE_TIME_H)
121 CHECK_INCLUDE_FILE("inttypes.h" HAVE_INTTYPES_H)
122 CHECK_INCLUDE_FILE("memory.h" HAVE_MEMORY_H)
123 CHECK_INCLUDE_FILE("stdlib.h" HAVE_STDLIB_H)
124 CHECK_INCLUDE_FILE("strings.h" HAVE_STRINGS_H)
125 CHECK_INCLUDE_FILE("string.h" HAVE_STRING_H)
126 CHECK_INCLUDE_FILE("ucontext.h" HAVE_UCONTEXT_H)
127 CHECK_INCLUDE_FILE("stdio.h" HAVE_STDIO_H)
128 CHECK_INCLUDE_FILE("linux/futex.h" HAVE_FUTEX_H)
129
130 CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
131 CHECK_FUNCTION_EXISTS(nanosleep HAVE_NANOSLEEP)
132 CHECK_FUNCTION_EXISTS(getdtablesize HAVE_GETDTABLESIZE)
133 CHECK_FUNCTION_EXISTS(sysconf HAVE_SYSCONF)
134 CHECK_FUNCTION_EXISTS(readv HAVE_READV)
135 CHECK_FUNCTION_EXISTS(popen HAVE_POPEN)
136 CHECK_FUNCTION_EXISTS(signal HAVE_SIGNAL)
137 CHECK_FUNCTION_EXISTS(snprintf HAVE_SNPRINTF)
138 CHECK_FUNCTION_EXISTS(vsnprintf HAVE_VSNPRINTF)
139 CHECK_FUNCTION_EXISTS(asprintf HAVE_ASPRINTF)
140 CHECK_FUNCTION_EXISTS(vasprintf HAVE_VASPRINTF)
141 CHECK_FUNCTION_EXISTS(makecontext HAVE_MAKECONTEXT)
142 CHECK_FUNCTION_EXISTS(mmap HAVE_MMAP)
143 CHECK_FUNCTION_EXISTS(mergesort HAVE_MERGESORT)
144
145 #Check if __thread is defined
146 execute_process(
147   COMMAND "${CMAKE_C_COMPILER} ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_thread_storage.c"
148   WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
149   RESULT_VARIABLE HAVE_thread_storage_run
150   )
151
152 if(HAVE_thread_storage_run)
153   set(HAVE_THREAD_LOCAL_STORAGE 0)
154 else()
155   set(HAVE_THREAD_LOCAL_STORAGE 1)
156 endif()
157
158 # Our usage of mmap is Linux-specific (flag MAP_ANONYMOUS), but kFreeBSD uses a GNU libc
159 IF(NOT "${CMAKE_SYSTEM}" MATCHES "Linux" AND NOT "${CMAKE_SYSTEM}" MATCHES "kFreeBSD" AND NOT "${CMAKE_SYSTEM}" MATCHES "GNU")
160   SET(HAVE_MMAP 0)
161   message(STATUS "Warning: MMAP is thought as non functional on this architecture (${CMAKE_SYSTEM})")
162 ENDIF()
163
164 if(WIN32) #THOSE FILES ARE FUNCTIONS ARE NOT DETECTED BUT THEY SHOULD...
165   set(HAVE_UCONTEXT_H 1)
166   set(HAVE_MAKECONTEXT 1)
167   set(HAVE_SNPRINTF 1)
168   set(HAVE_VSNPRINTF 1)
169 endif()
170
171 set(CONTEXT_UCONTEXT 0)
172 SET(CONTEXT_THREADS 0)
173 SET(HAVE_TRACING 1)
174
175 if(enable_tracing)
176   SET(HAVE_TRACING 1)
177 else()
178   SET(HAVE_TRACING 0)
179 endif()
180
181 if(enable_jedule)
182   SET(HAVE_JEDULE 1)
183 endif()
184
185 if(enable_latency_bound_tracking)
186   SET(HAVE_LATENCY_BOUND_TRACKING 1)
187 else()
188   if(enable_gtnets)
189     message(STATUS "Warning : Turning latency_bound_tracking to ON because GTNeTs is ON")
190     SET(enable_latency_bound_tracking ON)
191     SET(HAVE_LATENCY_BOUND_TRACKING 1)
192   else()
193     SET(HAVE_LATENCY_BOUND_TRACKING 0)
194   endif()
195 endif()
196
197 if(enable_mallocators)
198   SET(MALLOCATOR_IS_WANTED 1)
199 else()
200   SET(MALLOCATOR_IS_WANTED 0)
201 endif()
202
203 if(enable_model-checking AND HAVE_MMAP)
204   SET(HAVE_MC 1)
205   SET(MMALLOC_WANT_OVERRIDE_LEGACY 1)
206   include(FindLibunwind)
207 else()
208   SET(HAVE_MC 0)
209   SET(MMALLOC_WANT_OVERRIDE_LEGACY 0)
210 endif()
211
212 #--------------------------------------------------------------------------------------------------
213 ### Check for some architecture dependent values
214 CHECK_TYPE_SIZE(int SIZEOF_INT)
215 CHECK_TYPE_SIZE(void* SIZEOF_VOIDP)
216
217 #--------------------------------------------------------------------------------------------------
218 ### Check for GNU dynamic linker
219 CHECK_INCLUDE_FILE("dlfcn.h" HAVE_DLFCN_H)
220 if (HAVE_DLFCN_H)
221     execute_process(COMMAND ${CMAKE_C_COMPILER} ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_gnu_dynlinker.c -ldl -o test_gnu_ld
222       WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
223       OUTPUT_VARIABLE HAVE_GNU_LD_compil
224     )
225     if(HAVE_GNU_LD_compil)
226       set(HAVE_GNU_LD 0)
227       message(STATUS "Warning: test program toward GNU ld failed to compile:")
228       message(STATUS "${HAVE_GNU_LD_comp_output}")
229     else()
230
231       execute_process(COMMAND ./test_gnu_ld
232           WORKING_DIRECTORY ${CMAKE_BINARY_DIR} 
233           RESULT_VARIABLE HAVE_GNU_LD_run 
234           OUTPUT_VARIABLE var_exec
235       )
236
237       if(NOT HAVE_GNU_LD_run)
238         set(HAVE_GNU_LD 1)
239         message(STATUS "We are using GNU dynamic linker")
240       else()
241         set(HAVE_GNU_LD 0)
242         message(STATUS "Warning: error while checking for GNU ld:")
243         message(STATUS "Test output: '${var_exec}'")
244         message(STATUS "Exit status: ${HAVE_GNU_LD_run}")
245       endif()
246       file(REMOVE test_gnu_ld)
247     endif()
248 endif()
249
250
251 #--------------------------------------------------------------------------------------------------
252 ### Initialize of CONTEXT THREADS
253
254 if(pthread)
255   set(pthread 1)
256 elseif(pthread)
257   set(pthread 0)
258 endif()
259
260 if(pthread)
261   ### Test that we have a way to create semaphores
262
263   if(HAVE_SEM_OPEN_LIB)
264     execute_process(COMMAND ${CMAKE_C_COMPILER} ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_sem_open.c -lpthread -o sem_open
265     WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
266     OUTPUT_VARIABLE HAVE_SEM_OPEN_compil
267     )
268
269     if(HAVE_SEM_OPEN_compil)
270       set(HAVE_SEM_OPEN 0)
271       message(STATUS "Warning: sem_open not compilable")
272       message(STATUS "HAVE_SEM_OPEN_comp_output: ${HAVE_SEM_OPEN_comp_output}")
273     else()
274       set(HAVE_SEM_OPEN 1)
275       message(STATUS "sem_open is compilable")
276     endif()
277
278     execute_process(COMMAND ./sem_open
279     WORKING_DIRECTORY ${CMAKE_BINARY_DIR} 
280     RESULT_VARIABLE HAVE_SEM_OPEN_run 
281     OUTPUT_VARIABLE var_compil
282     )
283     file(REMOVE sem_open)
284
285     if(NOT HAVE_SEM_OPEN_run)
286       set(HAVE_SEM_OPEN 1)
287       message(STATUS "sem_open is executable")
288     else()
289       set(HAVE_SEM_OPEN 0)
290       if(EXISTS "${CMAKE_BINARY_DIR}/sem_open")
291         message(STATUS "Bin ${CMAKE_BINARY_DIR}/sem_open exists!")
292       else()
293         message(STATUS "Bin ${CMAKE_BINARY_DIR}/sem_open not exists!")
294       endif()
295       message(STATUS "Warning: sem_open not executable")
296       message(STATUS "Compilation output: '${var_compil}'")
297       message(STATUS "Exit result of sem_open: ${HAVE_SEM_OPEN_run}")
298     endif()
299
300   else()
301     set(HAVE_SEM_OPEN 0)
302   endif()
303
304   if(HAVE_SEM_INIT_LIB)
305     execute_process(COMMAND ${CMAKE_C_COMPILER} ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_sem_init.c -lpthread -o sem_init
306     WORKING_DIRECTORY ${CMAKE_BINARY_DIR} 
307     RESULT_VARIABLE HAVE_SEM_INIT_run OUTPUT_VARIABLE HAVE_SEM_INIT_compil)
308     
309     if(HAVE_SEM_INIT_compil)
310       set(HAVE_SEM_INIT 0)
311       message(STATUS "Warning: sem_init not compilable")
312       message(STATUS "HAVE_SEM_INIT_comp_output: ${HAVE_SEM_OPEN_comp_output}")
313     else()
314       set(HAVE_SEM_INIT 1)
315       message(STATUS "sem_init is compilable")
316     endif()
317     execute_process(COMMAND ./sem_init 
318     WORKING_DIRECTORY ${CMAKE_BINARY_DIR} 
319     RESULT_VARIABLE HAVE_SEM_INIT_run 
320     OUTPUT_VARIABLE var_compil
321     )
322     file(REMOVE sem_init)
323
324
325     if(NOT HAVE_SEM_INIT_run)
326       set(HAVE_SEM_INIT 1)
327       message(STATUS "sem_init is executable")
328     else()
329       set(HAVE_SEM_INIT 0)
330       if(EXISTS "${CMAKE_BINARY_DIR}/sem_init")
331         message(STATUS "Bin ${CMAKE_BINARY_DIR}/sem_init exists!")
332       else()
333         message(STATUS "Bin ${CMAKE_BINARY_DIR}/sem_init not exists!")
334       endif()
335       message(STATUS "Warning: sem_init not executable")
336       message(STATUS "Compilation output: '${var_compil}'")
337       message(STATUS "Exit result of sem_init: ${HAVE_SEM_INIT_run}")
338     endif()
339   endif()
340
341   if(NOT HAVE_SEM_OPEN AND NOT HAVE_SEM_INIT)
342     message(FATAL_ERROR "Semaphores are not usable (neither sem_open nor sem_init is both compilable and executable), but they are mandatory to threads (you may need to mount /dev).")
343   endif()
344
345   ### Test that we have a way to timewait for semaphores
346
347   if(HAVE_SEM_TIMEDWAIT_LIB)
348
349     execute_process(
350       COMMAND "${CMAKE_C_COMPILER} ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_sem_timedwait.c -lpthread"
351       WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
352       OUTPUT_VARIABLE HAVE_SEM_TIMEDWAIT_run
353       )
354
355     if(HAVE_SEM_TIMEDWAIT_run)
356       set(HAVE_SEM_TIMEDWAIT 0)
357       message(STATUS "timedwait not compilable")
358     else()
359       set(HAVE_SEM_TIMEDWAIT 1)
360       message(STATUS "timedwait is compilable")
361     endif()
362   endif()
363
364   ### HAVE_MUTEX_TIMEDLOCK
365
366   if(HAVE_MUTEX_TIMEDLOCK_LIB)
367
368     execute_process(
369       COMMAND "${CMAKE_C_COMPILER} ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_mutex_timedlock.c -lpthread"
370       WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
371       OUTPUT_VARIABLE HAVE_MUTEX_TIMEDLOCK_run
372       )
373
374     if(HAVE_MUTEX_TIMEDLOCK_run)
375       set(HAVE_MUTEX_TIMEDLOCK 0)
376       message(STATUS "timedlock not compilable")
377     else()
378       message(STATUS "timedlock is compilable")
379       set(HAVE_MUTEX_TIMEDLOCK 1)
380     endif()
381   endif()
382 endif()
383
384 # AC_CHECK_MCSC(mcsc=yes, mcsc=no)
385 set(mcsc_flags "")
386 if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
387   set(mcsc_flags "-D_XOPEN_SOURCE")
388 endif()
389
390 if(WIN32)
391   if(ARCH_32_BITS)
392     set(mcsc_flags "-D_XBT_WIN32 -D_I_X86_ -I${CMAKE_HOME_DIRECTORY}/include/xbt -I${CMAKE_HOME_DIRECTORY}/src/xbt")
393   else()
394     set(mcsc_flags "-D_XBT_WIN32 -D_AMD64_ -I${CMAKE_HOME_DIRECTORY}/include/xbt -I${CMAKE_HOME_DIRECTORY}/src/xbt")
395   endif()
396 endif()
397
398 IF(CMAKE_CROSSCOMPILING)
399   IF(WIN32)
400     set(windows_context "yes")
401     set(IS_WINDOWS 1)
402   ENDIF()
403 ELSE()
404   file(REMOVE "${CMAKE_BINARY_DIR}/testprog*")
405   file(REMOVE ${CMAKE_BINARY_DIR}/conftestval)
406   execute_process(COMMAND ${CMAKE_C_COMPILER} ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_AC_CHECK_MCSC.c ${mcsc_flags} -o testprog
407   WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/
408   OUTPUT_VARIABLE COMPILE_mcsc_VAR)
409
410   if(NOT COMPILE_mcsc_VAR)
411     message(STATUS "prog_AC_CHECK_MCSC.c is compilable")
412     execute_process(COMMAND ./testprog
413     WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/
414     OUTPUT_VARIABLE var_compil)
415   else()
416     message(STATUS "prog_AC_CHECK_MCSC.c is not compilable")
417   endif()
418   file(REMOVE "${CMAKE_BINARY_DIR}/testprog*")
419
420   if(EXISTS "${CMAKE_BINARY_DIR}/conftestval")
421     file(READ "${CMAKE_BINARY_DIR}/conftestval" mcsc)
422     STRING(REPLACE "\n" "" mcsc "${mcsc}")
423     if(mcsc)
424       set(mcsc "yes")
425       set(HAVE_UCONTEXT_H 1)
426     else()
427       set(mcsc "no")
428     endif()
429   else()
430     set(mcsc "no")
431   endif()
432
433   message(STATUS "mcsc: ${mcsc}")
434 ENDIF()
435
436 if(mcsc MATCHES "no" AND pthread)
437   if(HAVE_WINDOWS_H)
438     set(windows_context "yes")
439     set(IS_WINDOWS 1)
440   elseif(HAVE_WINDOWS_H)
441     message(FATAL_ERROR "no appropriate backend found")
442   endif()
443 endif()
444
445 #Only windows
446
447 if(WIN32)
448   if(NOT HAVE_WINDOWS_H)
449     message(FATAL_ERROR "no appropriate backend found windows")
450   endif()
451 endif()
452
453 if(windows_context MATCHES "yes")
454   message(STATUS "Context change to windows")
455 endif()
456
457 #If can have both context
458
459 if(mcsc)
460   set(CONTEXT_UCONTEXT 1)
461 endif()
462
463 if(pthread)
464   set(CONTEXT_THREADS 1)
465 endif()
466
467 ###############
468 ## GIT version check
469 ##
470 if(EXISTS ${CMAKE_HOME_DIRECTORY}/.git/ AND NOT WIN32)
471   execute_process(COMMAND git remote
472   COMMAND head -n 1
473   WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/.git/
474   OUTPUT_VARIABLE remote
475   RESULT_VARIABLE ret
476   )
477   string(REPLACE "\n" "" remote "${remote}")
478   #message(STATUS "Git remote: ${remote}")
479   execute_process(COMMAND git config --get remote.${remote}.url
480   WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/.git/
481   OUTPUT_VARIABLE url
482   RESULT_VARIABLE ret
483   )
484   string(REPLACE "\n" "" url "${url}")
485   #message(STATUS "Git url: ${url}")
486   if(url)
487     execute_process(COMMAND git --git-dir=${CMAKE_HOME_DIRECTORY}/.git log --pretty=oneline --abbrev-commit -1
488     WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/.git/
489     OUTPUT_VARIABLE GIT_VERSION
490     RESULT_VARIABLE ret
491     )
492     string(REPLACE "\n" "" GIT_VERSION "${GIT_VERSION}")
493     message(STATUS "Git version: ${GIT_VERSION}")
494     execute_process(COMMAND git --git-dir=${CMAKE_HOME_DIRECTORY}/.git log -n 1 --pretty=format:%ai .
495     WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/.git/
496     OUTPUT_VARIABLE GIT_DATE
497     RESULT_VARIABLE ret
498     )
499     string(REPLACE "\n" "" GIT_DATE "${GIT_DATE}")
500     message(STATUS "Git date: ${GIT_DATE}")
501     string(REGEX REPLACE " .*" "" GIT_VERSION "${GIT_VERSION}")
502     STRING(REPLACE " +0000" "" GIT_DATE "${GIT_DATE}")
503     STRING(REPLACE " " "~" GIT_DATE "${GIT_DATE}")
504     STRING(REPLACE ":" "-" GIT_DATE "${GIT_DATE}")
505   endif()
506 endif()
507
508 #--------------------------------------------------------------------------------------------------
509
510 set(makecontext_CPPFLAGS_2 "")
511 if(HAVE_MAKECONTEXT OR WIN32)
512   set(makecontext_CPPFLAGS "-DTEST_makecontext")
513   if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
514     set(makecontext_CPPFLAGS_2 "-D_XOPEN_SOURCE")
515   endif()
516
517   if(WIN32)
518     if(ARCH_32_BITS)
519       set(makecontext_CPPFLAGS "-DTEST_makecontext -D_I_X86_")
520     else()
521       set(makecontext_CPPFLAGS "-DTEST_makecontext -D_AMD64_")
522     endif()
523     set(makecontext_CPPFLAGS_2 "-D_XBT_WIN32 -I${CMAKE_HOME_DIRECTORY}/include/xbt -I${CMAKE_HOME_DIRECTORY}/src/xbt")
524   endif()
525
526   file(REMOVE ${CMAKE_BINARY_DIR}/conftestval)
527
528   try_run(RUN_makecontext_VAR COMPILE_makecontext_VAR
529     ${CMAKE_BINARY_DIR}
530     ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_stacksetup.c
531     COMPILE_DEFINITIONS "${makecontext_CPPFLAGS} ${makecontext_CPPFLAGS_2}"
532     )
533
534   if(EXISTS ${CMAKE_BINARY_DIR}/conftestval)
535     file(READ ${CMAKE_BINARY_DIR}/conftestval MAKECONTEXT_ADDR_SIZE)
536     string(REPLACE "\n" "" MAKECONTEXT_ADDR_SIZE "${MAKECONTEXT_ADDR_SIZE}")
537     string(REGEX MATCH ;^.*,;MAKECONTEXT_ADDR "${MAKECONTEXT_ADDR_SIZE}")
538     string(REGEX MATCH ;,.*$; MAKECONTEXT_SIZE "${MAKECONTEXT_ADDR_SIZE}")
539     string(REPLACE "," "" makecontext_addr "${MAKECONTEXT_ADDR}")
540     string(REPLACE "," "" makecontext_size "${MAKECONTEXT_SIZE}")
541     set(pth_skaddr_makecontext "#define pth_skaddr_makecontext(skaddr,sksize) (${makecontext_addr})")
542     set(pth_sksize_makecontext "#define pth_sksize_makecontext(skaddr,sksize) (${makecontext_size})")
543     message(STATUS "${pth_skaddr_makecontext}")
544     message(STATUS "${pth_sksize_makecontext}")
545   else()
546     #       message(FATAL_ERROR "makecontext is not compilable")
547   endif()
548 endif()
549
550 #--------------------------------------------------------------------------------------------------
551
552 ### check for stackgrowth
553 if (NOT CMAKE_CROSSCOMPILING)
554   try_run(RUN_makecontext_VAR COMPILE_makecontext_VAR
555     ${CMAKE_BINARY_DIR}
556     ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_stackgrowth.c
557     )
558   file(READ "${CMAKE_BINARY_DIR}/conftestval" stack)
559   if(stack MATCHES "down")
560     set(PTH_STACKGROWTH "-1")
561   endif()
562   if(stack MATCHES "up")
563     set(PTH_STACKGROWTH "1")
564   endif()
565
566 endif()
567 ###############
568 ## System checks
569 ##
570
571 #SG_CONFIGURE_PART([System checks...])
572 #AC_PROG_CC(xlC gcc cc) -auto
573 #AM_SANITY_CHECK -auto
574
575 #AC_PROG_MAKE_SET
576
577 #AC_PRINTF_NULL FIXME: this is too ancient to survive!
578 try_run(RUN_PRINTF_NULL_VAR COMPILE_PRINTF_NULL_VAR
579   ${CMAKE_BINARY_DIR}
580   ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_printf_null.c
581   )
582
583 if(RUN_PRINTF_NULL_VAR MATCHES "FAILED_TO_RUN")
584   SET(PRINTF_NULL_WORKING "0")
585 else()
586   SET(PRINTF_NULL_WORKING "1")
587 endif()
588
589 #AC_CHECK_VA_COPY
590
591 set(diff_va "va_copy((d),(s))"
592   "VA_COPY((d),(s))"
593   "__va_copy((d),(s))"
594   "__builtin_va_copy((d),(s))"
595   "do { (d) = (s)\; } while (0)"
596   "do { *(d) = *(s)\; } while (0)"
597   "memcpy((void *)&(d), (void *)&(s), sizeof(s))"
598   "memcpy((void *)(d), (void *)(s), sizeof(*(s)))"
599   )
600
601 foreach(fct ${diff_va})
602   write_file("${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_va_copy.c" "#include <stdlib.h>
603         #include <stdarg.h>
604         #include <string.h>
605         #define DO_VA_COPY(d,s) ${fct}
606         void test(char *str, ...)
607         {
608             va_list ap, ap2;
609             int i;
610             va_start(ap, str);
611             DO_VA_COPY(ap2, ap);
612             for (i = 1; i <= 9; i++) {
613                 int k = (int)va_arg(ap, int);
614                 if (k != i)
615                     abort();
616             }
617             DO_VA_COPY(ap, ap2);
618             for (i = 1; i <= 9; i++) {
619                 int k = (int)va_arg(ap, int);
620                 if (k != i)
621                     abort();
622             }
623             va_end(ap);
624         }
625         int main(void)
626         {
627             test(\"test\", 1, 2, 3, 4, 5, 6, 7, 8, 9);
628             exit(0);
629         }"
630     )
631   try_compile(COMPILE_VA_NULL_VAR
632     ${CMAKE_BINARY_DIR}
633     ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_va_copy.c
634     )
635   if(COMPILE_VA_NULL_VAR)
636     string(REGEX REPLACE "\;" "" fctbis ${fct})
637     if(${fctbis} STREQUAL "va_copy((d),(s))")
638       set(HAVE_VA_COPY 1)
639       set(ac_cv_va_copy "C99")
640       set(__VA_COPY_USE_C99 "va_copy((d),(s))")
641     endif()
642
643     if(${fctbis} STREQUAL "VA_COPY((d),(s))")
644       set(ac_cv_va_copy "GCM")
645       set(__VA_COPY_USE_GCM "VA_COPY((d),(s))")
646     endif()
647
648     if(${fctbis} STREQUAL "__va_copy((d),(s))")
649       set(ac_cv_va_copy "GCH")
650       set(__VA_COPY_USE_GCH "__va_copy((d),(s))")
651     endif()
652
653     if(${fctbis} STREQUAL "__builtin_va_copy((d),(s))")
654       set(ac_cv_va_copy "GCB")
655       set(__VA_COPY_USE_GCB "__builtin_va_copy((d),(s))")
656     endif()
657
658     if(${fctbis} STREQUAL "do { (d) = (s) } while (0)")
659       set(ac_cv_va_copy "ASS")
660       set(__VA_COPY_USE_ASS "do { (d) = (s); } while (0)")
661     endif()
662
663     if(${fctbis} STREQUAL "do { *(d) = *(s) } while (0)")
664       set(ac_cv_va_copy "ASP")
665       set(__VA_COPY_USE_ASP "do { *(d) = *(s); } while (0)")
666     endif()
667
668     if(${fctbis} STREQUAL "memcpy((void *)&(d), (void *)&(s), sizeof(s))")
669       set(ac_cv_va_copy "CPS")
670       set(__VA_COPY_USE_CPS "memcpy((void *)&(d), (void *)&(s), sizeof(s))")
671     endif()
672
673     if(${fctbis} STREQUAL "memcpy((void *)(d), (void *)(s), sizeof(*(s)))")
674       set(ac_cv_va_copy "CPP")
675       set(__VA_COPY_USE_CPP "memcpy((void *)(d), (void *)(s), sizeof(*(s)))")
676     endif()
677
678     if(NOT STATUS_OK)
679       set(__VA_COPY_USE "__VA_COPY_USE_${ac_cv_va_copy}(d, s)")
680     endif()
681     set(STATUS_OK "1")
682
683   endif()
684
685 endforeach(fct ${diff_va})
686
687 #--------------------------------------------------------------------------------------------------
688 ### check for getline
689 try_compile(COMPILE_RESULT_VAR
690   ${CMAKE_BINARY_DIR}
691   ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_getline.c
692   )
693
694 if(NOT COMPILE_RESULT_VAR)
695   SET(need_getline "#define SIMGRID_NEED_GETLINE 1")
696   SET(SIMGRID_NEED_GETLINE 1)
697 else()
698   SET(need_getline "")
699   SET(SIMGRID_NEED_GETLINE 0)
700 endif()
701
702 ### check for a working snprintf
703 if(HAVE_SNPRINTF AND HAVE_VSNPRINTF OR WIN32)
704   if(WIN32)
705     #set(HAVE_SNPRINTF 1)
706     #set(HAVE_VSNPRINTF 1)
707   endif()
708
709   if(CMAKE_CROSSCOMPILING)
710     set(RUN_SNPRINTF_FUNC "cross")
711     #set(PREFER_PORTABLE_SNPRINTF 1)
712   else()
713     try_run(RUN_SNPRINTF_FUNC_VAR COMPILE_SNPRINTF_FUNC_VAR
714       ${CMAKE_BINARY_DIR}
715       ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_snprintf.c
716       )
717   endif()
718
719   if(CMAKE_CROSSCOMPILING)
720     set(RUN_VSNPRINTF_FUNC "cross")
721     set(PREFER_PORTABLE_VSNPRINTF 1)
722   else()
723     try_run(RUN_VSNPRINTF_FUNC_VAR COMPILE_VSNPRINTF_FUNC_VAR
724       ${CMAKE_BINARY_DIR}
725       ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_vsnprintf.c
726       )
727   endif()
728
729   set(PREFER_PORTABLE_SNPRINTF 0)
730   if(RUN_VSNPRINTF_FUNC_VAR MATCHES "FAILED_TO_RUN")
731     set(PREFER_PORTABLE_SNPRINTF 1)
732   endif()
733   if(RUN_SNPRINTF_FUNC_VAR MATCHES "FAILED_TO_RUN")
734     set(PREFER_PORTABLE_SNPRINTF 1)
735   endif()
736 endif()
737
738 ### check for asprintf function familly
739 if(HAVE_ASPRINTF)
740   SET(simgrid_need_asprintf "")
741   SET(NEED_ASPRINTF 0)
742 else()
743   SET(simgrid_need_asprintf "#define SIMGRID_NEED_ASPRINTF 1")
744   SET(NEED_ASPRINTF 1)
745 endif()
746
747 if(HAVE_VASPRINTF)
748   SET(simgrid_need_vasprintf "")
749   SET(NEED_VASPRINTF 0)
750 else()
751   SET(simgrid_need_vasprintf "#define SIMGRID_NEED_VASPRINTF 1")
752   SET(NEED_VASPRINTF 1)
753 endif()
754
755 ### check for addr2line
756
757 find_path(ADDR2LINE NAMES addr2line     PATHS NO_DEFAULT_PATHS  )
758 if(ADDR2LINE)
759   set(ADDR2LINE "${ADDR2LINE}/addr2line")
760 endif()
761
762 ### Check if OSX can compile with ucontext (with gcc 4.[1-5] it is broken)
763 if(APPLE)
764   if(APPLE_NEED_GCC_VERSION GREATER COMPILER_C_VERSION_MAJOR_MINOR)
765     message(STATUS "Ucontext can't be used with this version of gcc (must be greater than 4.5)")
766     set(HAVE_UCONTEXT_H 0)
767   endif()
768 endif()
769
770 ### File to create
771
772 configure_file("${CMAKE_HOME_DIRECTORY}/src/context_sysv_config.h.in"                   "${CMAKE_BINARY_DIR}/src/context_sysv_config.h" @ONLY IMMEDIATE)
773
774 SET( CMAKEDEFINE "#cmakedefine" )
775 configure_file("${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/src/internal_config.h.in"      "${CMAKE_BINARY_DIR}/src/internal_config.h" @ONLY IMMEDIATE)
776 configure_file("${CMAKE_BINARY_DIR}/src/internal_config.h"                      "${CMAKE_BINARY_DIR}/src/internal_config.h" @ONLY IMMEDIATE)
777 configure_file("${CMAKE_HOME_DIRECTORY}/include/simgrid_config.h.in"            "${CMAKE_BINARY_DIR}/include/simgrid_config.h" @ONLY IMMEDIATE)
778
779 set(top_srcdir "${CMAKE_HOME_DIRECTORY}")
780 set(srcdir "${CMAKE_HOME_DIRECTORY}/src")
781
782 ### Script used when simgrid is installed
783 set(exec_prefix ${CMAKE_INSTALL_PREFIX})
784 set(includeflag "-I${CMAKE_INSTALL_PREFIX}/include -I${CMAKE_INSTALL_PREFIX}/include/smpi")
785 set(includedir "${CMAKE_INSTALL_PREFIX}/include")
786 set(libdir ${exec_prefix}/lib)
787 set(CMAKE_SMPI_COMMAND "export LD_LIBRARY_PATH=${CMAKE_INSTALL_PREFIX}/lib:${GTNETS_LIB_PATH}:${HAVE_NS3_LIB}:$LD_LIBRARY_PATH")
788
789 configure_file(${CMAKE_HOME_DIRECTORY}/include/smpi/smpif.h.in ${CMAKE_BINARY_DIR}/include/smpi/smpif.h @ONLY)
790 configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpicc.in ${CMAKE_BINARY_DIR}/bin/smpicc @ONLY)
791 configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpif2c.in ${CMAKE_BINARY_DIR}/bin/smpif2c @ONLY)
792 configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpiff.in ${CMAKE_BINARY_DIR}/bin/smpiff @ONLY)
793 configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpif90.in ${CMAKE_BINARY_DIR}/bin/smpif90 @ONLY)
794 configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpirun.in ${CMAKE_BINARY_DIR}/bin/smpirun @ONLY)
795
796 ### Script used when simgrid is compiling
797 set(includeflag "-I${CMAKE_HOME_DIRECTORY}/include -I${CMAKE_HOME_DIRECTORY}/include/smpi")
798 set(includeflag "${includeflag} -I${CMAKE_BINARY_DIR}/include -I${CMAKE_BINARY_DIR}/include/smpi")
799 set(includedir "${CMAKE_HOME_DIRECTORY}/include")
800 set(exec_prefix "${CMAKE_BINARY_DIR}/smpi_script/")
801 set(CMAKE_SMPI_COMMAND "export LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/lib:${GTNETS_LIB_PATH}:${HAVE_NS3_LIB}:$LD_LIBRARY_PATH")
802 set(libdir "${CMAKE_BINARY_DIR}/lib")
803
804 configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpicc.in ${CMAKE_BINARY_DIR}/smpi_script/bin/smpicc @ONLY)
805 configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpif2c.in ${CMAKE_BINARY_DIR}/smpi_script/bin/smpif2c @ONLY)
806 configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpiff.in ${CMAKE_BINARY_DIR}/smpi_script/bin/smpiff @ONLY)
807 configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpif90.in ${CMAKE_BINARY_DIR}/smpi_script/bin/smpif90 @ONLY)
808 configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpirun.in ${CMAKE_BINARY_DIR}/smpi_script/bin/smpirun @ONLY)
809
810 set(top_builddir ${CMAKE_HOME_DIRECTORY})
811
812 if(NOT WIN32)
813   execute_process(COMMAND chmod a=rwx ${CMAKE_BINARY_DIR}/bin/smpicc)
814   execute_process(COMMAND chmod a=rwx ${CMAKE_BINARY_DIR}/bin/smpif2c)
815   execute_process(COMMAND chmod a=rwx ${CMAKE_BINARY_DIR}/bin/smpiff)
816   execute_process(COMMAND chmod a=rwx ${CMAKE_BINARY_DIR}/bin/smpif90)
817   execute_process(COMMAND chmod a=rwx ${CMAKE_BINARY_DIR}/bin/smpirun)
818   execute_process(COMMAND chmod a=rwx ${CMAKE_BINARY_DIR}/smpi_script/bin/smpicc)
819   execute_process(COMMAND chmod a=rwx ${CMAKE_BINARY_DIR}/smpi_script/bin/smpif2c)
820   execute_process(COMMAND chmod a=rwx ${CMAKE_BINARY_DIR}/smpi_script/bin/smpiff)
821   execute_process(COMMAND chmod a=rwx ${CMAKE_BINARY_DIR}/smpi_script/bin/smpif90)
822   execute_process(COMMAND chmod a=rwx ${CMAKE_BINARY_DIR}/smpi_script/bin/smpirun)
823 endif()
824
825 set(generated_headers_to_install
826   ${CMAKE_CURRENT_BINARY_DIR}/include/smpi/smpif.h
827   ${CMAKE_CURRENT_BINARY_DIR}/include/simgrid_config.h
828   )
829
830 set(generated_headers
831   ${CMAKE_CURRENT_BINARY_DIR}/src/context_sysv_config.h
832   ${CMAKE_CURRENT_BINARY_DIR}/src/internal_config.h
833   )
834
835 set(generated_files_to_clean
836   ${generated_headers}
837   ${generated_headers_to_install}
838   ${CMAKE_BINARY_DIR}/bin/smpicc
839   ${CMAKE_BINARY_DIR}/bin/smpif2c
840   ${CMAKE_BINARY_DIR}/bin/smpiff
841   ${CMAKE_BINARY_DIR}/bin/smpif90
842   ${CMAKE_BINARY_DIR}/bin/smpirun
843   ${CMAKE_BINARY_DIR}/bin/colorize
844   ${CMAKE_BINARY_DIR}/bin/simgrid_update_xml
845   ${CMAKE_BINARY_DIR}/examples/smpi/tracing/smpi_traced.trace
846   ${CMAKE_BINARY_DIR}/src/supernovae_sg.c
847   ${CMAKE_BINARY_DIR}/src/supernovae_smpi.c
848   )
849
850 if("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_HOME_DIRECTORY}")
851 else()
852   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/hostfile ${CMAKE_BINARY_DIR}/examples/smpi/hostfile COPYONLY)
853   configure_file(${CMAKE_HOME_DIRECTORY}/examples/msg/small_platform.xml ${CMAKE_BINARY_DIR}/examples/msg/small_platform.xml COPYONLY)
854   configure_file(${CMAKE_HOME_DIRECTORY}/examples/msg/small_platform_with_routers.xml ${CMAKE_BINARY_DIR}/examples/msg/small_platform_with_routers.xml COPYONLY)
855   configure_file(${CMAKE_HOME_DIRECTORY}/examples/msg/tracing/platform.xml ${CMAKE_BINARY_DIR}/examples/msg/tracing/platform.xml COPYONLY)
856   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay/actions0.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay/actions0.txt COPYONLY)
857   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay/actions1.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay/actions1.txt COPYONLY)
858   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay/actions_allReduce.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay/actions_allReduce.txt COPYONLY)
859   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay/actions_barrier.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay/actions_barrier.txt COPYONLY)
860   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay/actions_bcast.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay/actions_bcast.txt COPYONLY)
861   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay/actions_with_isend.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay/actions_with_isend.txt COPYONLY)
862   configure_file(${CMAKE_HOME_DIRECTORY}/teshsuite/smpi/hostfile ${CMAKE_BINARY_DIR}/teshsuite/smpi/hostfile COPYONLY)
863
864   set(generated_files_to_clean
865     ${generated_files_to_clean}
866     ${CMAKE_BINARY_DIR}/examples/smpi/hostfile
867     ${CMAKE_BINARY_DIR}/examples/msg/small_platform.xml
868     ${CMAKE_BINARY_DIR}/examples/msg/small_platform_with_routers.xml
869     ${CMAKE_BINARY_DIR}/examples/msg/tracing/platform.xml
870     ${CMAKE_BINARY_DIR}/examples/smpi/replay/actions0.txt
871     ${CMAKE_BINARY_DIR}/examples/smpi/replay/actions1.txt
872     ${CMAKE_BINARY_DIR}/examples/smpi/replay/actions_allReduce.txt
873     ${CMAKE_BINARY_DIR}/examples/smpi/replay/actions_barrier.txt
874     ${CMAKE_BINARY_DIR}/examples/smpi/replay/actions_bcast.txt
875     ${CMAKE_BINARY_DIR}/examples/smpi/replay/actions_with_isend.txt
876     ${CMAKE_BINARY_DIR}/teshsuite/smpi/hostfile
877     )
878 endif()
879
880 SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES
881   "${generated_files_to_clean}")
882
883 IF(${ARCH_32_BITS})
884   set(WIN_ARCH "32")
885 ELSE()
886   set(WIN_ARCH "64")
887 ENDIF()
888 configure_file("${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/src/simgrid.nsi.in"    "${CMAKE_BINARY_DIR}/simgrid.nsi" @ONLY IMMEDIATE)