Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Typo + kill useless empty lines.
[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("dlfcn.h" HAVE_DLFCN_H)
122 CHECK_INCLUDE_FILE("inttypes.h" HAVE_INTTYPES_H)
123 CHECK_INCLUDE_FILE("memory.h" HAVE_MEMORY_H)
124 CHECK_INCLUDE_FILE("stdlib.h" HAVE_STDLIB_H)
125 CHECK_INCLUDE_FILE("strings.h" HAVE_STRINGS_H)
126 CHECK_INCLUDE_FILE("string.h" HAVE_STRING_H)
127 CHECK_INCLUDE_FILE("ucontext.h" HAVE_UCONTEXT_H)
128 CHECK_INCLUDE_FILE("stdio.h" HAVE_STDIO_H)
129 CHECK_INCLUDE_FILE("linux/futex.h" HAVE_FUTEX_H)
130
131 CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
132 CHECK_FUNCTION_EXISTS(nanosleep HAVE_NANOSLEEP)
133 CHECK_FUNCTION_EXISTS(getdtablesize HAVE_GETDTABLESIZE)
134 CHECK_FUNCTION_EXISTS(sysconf HAVE_SYSCONF)
135 CHECK_FUNCTION_EXISTS(readv HAVE_READV)
136 CHECK_FUNCTION_EXISTS(popen HAVE_POPEN)
137 CHECK_FUNCTION_EXISTS(signal HAVE_SIGNAL)
138 CHECK_FUNCTION_EXISTS(snprintf HAVE_SNPRINTF)
139 CHECK_FUNCTION_EXISTS(vsnprintf HAVE_VSNPRINTF)
140 CHECK_FUNCTION_EXISTS(asprintf HAVE_ASPRINTF)
141 CHECK_FUNCTION_EXISTS(vasprintf HAVE_VASPRINTF)
142 CHECK_FUNCTION_EXISTS(makecontext HAVE_MAKECONTEXT)
143 CHECK_FUNCTION_EXISTS(mmap HAVE_MMAP)
144 CHECK_FUNCTION_EXISTS(mergesort HAVE_MERGESORT)
145
146 #Check if __thread is defined
147 execute_process(
148   COMMAND "${CMAKE_C_COMPILER} ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_thread_storage.c"
149   WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
150   RESULT_VARIABLE HAVE_thread_storage_run
151   )
152
153 if(HAVE_thread_storage_run)
154   set(HAVE_THREAD_LOCAL_STORAGE 0)
155 else()
156   set(HAVE_THREAD_LOCAL_STORAGE 1)
157 endif()
158
159 # Our usage of mmap is Linux-specific (flag MAP_ANONYMOUS), but kFreeBSD uses a GNU libc
160 IF(NOT "${CMAKE_SYSTEM}" MATCHES "Linux" AND NOT "${CMAKE_SYSTEM}" MATCHES "kFreeBSD" AND NOT "${CMAKE_SYSTEM}" MATCHES "GNU")
161   SET(HAVE_MMAP 0)
162   message(STATUS "Warning: MMAP is thought as non functional on this architecture (${CMAKE_SYSTEM})")
163 ENDIF()
164
165 if(WIN32) #THOSE FILES ARE FUNCTIONS ARE NOT DETECTED BUT THEY SHOULD...
166   set(HAVE_UCONTEXT_H 1)
167   set(HAVE_MAKECONTEXT 1)
168   set(HAVE_SNPRINTF 1)
169   set(HAVE_VSNPRINTF 1)
170 endif()
171
172 set(CONTEXT_UCONTEXT 0)
173 SET(CONTEXT_THREADS 0)
174 SET(HAVE_TRACING 1)
175
176 if(enable_tracing)
177   SET(HAVE_TRACING 1)
178 else()
179   SET(HAVE_TRACING 0)
180 endif()
181
182 if(enable_jedule)
183   SET(HAVE_JEDULE 1)
184 endif()
185
186 if(enable_latency_bound_tracking)
187   SET(HAVE_LATENCY_BOUND_TRACKING 1)
188 else()
189   if(enable_gtnets)
190     message(STATUS "Warning : Turning latency_bound_tracking to ON because GTNeTs is ON")
191     SET(enable_latency_bound_tracking ON)
192     SET(HAVE_LATENCY_BOUND_TRACKING 1)
193   else()
194     SET(HAVE_LATENCY_BOUND_TRACKING 0)
195   endif()
196 endif()
197
198 if(enable_mallocators)
199   SET(MALLOCATOR_IS_WANTED 1)
200 else()
201   SET(MALLOCATOR_IS_WANTED 0)
202 endif()
203
204 if(enable_model-checking AND HAVE_MMAP)
205   SET(HAVE_MC 1)
206   SET(MMALLOC_WANT_OVERRIDE_LEGACY 1)
207   include(FindLibunwind)
208 else()
209   SET(HAVE_MC 0)
210   SET(MMALLOC_WANT_OVERRIDE_LEGACY 0)
211 endif()
212
213 #--------------------------------------------------------------------------------------------------
214 ### Check for some architecture dependent values
215 CHECK_TYPE_SIZE(int SIZEOF_INT)
216 CHECK_TYPE_SIZE(void* SIZEOF_VOIDP)
217
218 #--------------------------------------------------------------------------------------------------
219 ### Initialize of CONTEXT THREADS
220
221 if(pthread)
222   set(pthread 1)
223 elseif(pthread)
224   set(pthread 0)
225 endif()
226
227 if(pthread)
228   ### Test that we have a way to create semaphores
229
230   if(HAVE_SEM_OPEN_LIB)
231     execute_process(COMMAND ${CMAKE_C_COMPILER} ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_sem_open.c -lpthread -o sem_open
232     WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
233     OUTPUT_VARIABLE HAVE_SEM_OPEN_compil
234     )
235
236     if(HAVE_SEM_OPEN_compil)
237       set(HAVE_SEM_OPEN 0)
238       message(STATUS "Warning: sem_open not compilable")
239       message(STATUS "HAVE_SEM_OPEN_comp_output: ${HAVE_SEM_OPEN_comp_output}")
240     else()
241       set(HAVE_SEM_OPEN 1)
242       message(STATUS "sem_open is compilable")
243     endif()
244
245     execute_process(COMMAND ./sem_open
246     WORKING_DIRECTORY ${CMAKE_BINARY_DIR} 
247     RESULT_VARIABLE HAVE_SEM_OPEN_run 
248     OUTPUT_VARIABLE var_compil
249     )
250     file(REMOVE sem_open)
251
252     if(NOT HAVE_SEM_OPEN_run)
253       set(HAVE_SEM_OPEN 1)
254       message(STATUS "sem_open is executable")
255     else()
256       set(HAVE_SEM_OPEN 0)
257       if(EXISTS "${CMAKE_BINARY_DIR}/sem_open")
258         message(STATUS "Bin ${CMAKE_BINARY_DIR}/sem_open exists!")
259       else()
260         message(STATUS "Bin ${CMAKE_BINARY_DIR}/sem_open not exists!")
261       endif()
262       message(STATUS "Warning: sem_open not executable")
263       message(STATUS "Compilation output: '${var_compil}'")
264       message(STATUS "Exit result of sem_open: ${HAVE_SEM_OPEN_run}")
265     endif()
266
267   else()
268     set(HAVE_SEM_OPEN 0)
269   endif()
270
271   if(HAVE_SEM_INIT_LIB)
272     execute_process(COMMAND ${CMAKE_C_COMPILER} ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_sem_init.c -lpthread -o sem_init
273     WORKING_DIRECTORY ${CMAKE_BINARY_DIR} 
274     RESULT_VARIABLE HAVE_SEM_INIT_run OUTPUT_VARIABLE HAVE_SEM_INIT_compil)
275     
276     if(HAVE_SEM_INIT_compil)
277       set(HAVE_SEM_INIT 0)
278       message(STATUS "Warning: sem_init not compilable")
279       message(STATUS "HAVE_SEM_INIT_comp_output: ${HAVE_SEM_OPEN_comp_output}")
280     else()
281       set(HAVE_SEM_INIT 1)
282       message(STATUS "sem_init is compilable")
283     endif()
284     execute_process(COMMAND ./sem_init 
285     WORKING_DIRECTORY ${CMAKE_BINARY_DIR} 
286     RESULT_VARIABLE HAVE_SEM_INIT_run 
287     OUTPUT_VARIABLE var_compil
288     )
289     file(REMOVE sem_init)
290
291
292     if(NOT HAVE_SEM_INIT_run)
293       set(HAVE_SEM_INIT 1)
294       message(STATUS "sem_init is executable")
295     else()
296       set(HAVE_SEM_INIT 0)
297       if(EXISTS "${CMAKE_BINARY_DIR}/sem_init")
298         message(STATUS "Bin ${CMAKE_BINARY_DIR}/sem_init exists!")
299       else()
300         message(STATUS "Bin ${CMAKE_BINARY_DIR}/sem_init not exists!")
301       endif()
302       message(STATUS "Warning: sem_init not executable")
303       message(STATUS "Compilation output: '${var_compil}'")
304       message(STATUS "Exit result of sem_init: ${HAVE_SEM_INIT_run}")
305     endif()
306   endif()
307
308   if(NOT HAVE_SEM_OPEN AND NOT HAVE_SEM_INIT)
309     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).")
310   endif()
311
312   ### Test that we have a way to timewait for semaphores
313
314   if(HAVE_SEM_TIMEDWAIT_LIB)
315
316     execute_process(
317       COMMAND "${CMAKE_C_COMPILER} ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_sem_timedwait.c -lpthread"
318       WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
319       OUTPUT_VARIABLE HAVE_SEM_TIMEDWAIT_run
320       )
321
322     if(HAVE_SEM_TIMEDWAIT_run)
323       set(HAVE_SEM_TIMEDWAIT 0)
324       message(STATUS "timedwait not compilable")
325     else()
326       set(HAVE_SEM_TIMEDWAIT 1)
327       message(STATUS "timedwait is compilable")
328     endif()
329   endif()
330
331   ### HAVE_MUTEX_TIMEDLOCK
332
333   if(HAVE_MUTEX_TIMEDLOCK_LIB)
334
335     execute_process(
336       COMMAND "${CMAKE_C_COMPILER} ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_mutex_timedlock.c -lpthread"
337       WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
338       OUTPUT_VARIABLE HAVE_MUTEX_TIMEDLOCK_run
339       )
340
341     if(HAVE_MUTEX_TIMEDLOCK_run)
342       set(HAVE_MUTEX_TIMEDLOCK 0)
343       message(STATUS "timedlock not compilable")
344     else()
345       message(STATUS "timedlock is compilable")
346       set(HAVE_MUTEX_TIMEDLOCK 1)
347     endif()
348   endif()
349 endif()
350
351 # AC_CHECK_MCSC(mcsc=yes, mcsc=no)
352 set(mcsc_flags "")
353 if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
354   set(mcsc_flags "-D_XOPEN_SOURCE")
355 endif()
356
357 if(WIN32)
358   if(ARCH_32_BITS)
359     set(mcsc_flags "-D_XBT_WIN32 -D_I_X86_ -I${CMAKE_HOME_DIRECTORY}/include/xbt -I${CMAKE_HOME_DIRECTORY}/src/xbt")
360   else()
361     set(mcsc_flags "-D_XBT_WIN32 -D_AMD64_ -I${CMAKE_HOME_DIRECTORY}/include/xbt -I${CMAKE_HOME_DIRECTORY}/src/xbt")
362   endif()
363 endif()
364
365 IF(CMAKE_CROSSCOMPILING)
366   IF(WIN32)
367     set(windows_context "yes")
368     set(IS_WINDOWS 1)
369   ENDIF()
370 ELSE()
371   file(REMOVE "${CMAKE_BINARY_DIR}/testprog*")
372   file(REMOVE ${CMAKE_BINARY_DIR}/conftestval)
373   execute_process(COMMAND ${CMAKE_C_COMPILER} ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_AC_CHECK_MCSC.c ${mcsc_flags} -o testprog
374   WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/
375   OUTPUT_VARIABLE COMPILE_mcsc_VAR)
376
377   if(NOT COMPILE_mcsc_VAR)
378     message(STATUS "prog_AC_CHECK_MCSC.c is compilable")
379     execute_process(COMMAND ./testprog
380     WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/
381     OUTPUT_VARIABLE var_compil)
382   else()
383     message(STATUS "prog_AC_CHECK_MCSC.c is not compilable")
384   endif()
385   file(REMOVE "${CMAKE_BINARY_DIR}/testprog*")
386
387   if(EXISTS "${CMAKE_BINARY_DIR}/conftestval")
388     file(READ "${CMAKE_BINARY_DIR}/conftestval" mcsc)
389     STRING(REPLACE "\n" "" mcsc "${mcsc}")
390     if(mcsc)
391       set(mcsc "yes")
392       set(HAVE_UCONTEXT_H 1)
393     else()
394       set(mcsc "no")
395     endif()
396   else()
397     set(mcsc "no")
398   endif()
399
400   message(STATUS "mcsc: ${mcsc}")
401 ENDIF()
402
403 if(mcsc MATCHES "no" AND pthread)
404   if(HAVE_WINDOWS_H)
405     set(windows_context "yes")
406     set(IS_WINDOWS 1)
407   elseif(HAVE_WINDOWS_H)
408     message(FATAL_ERROR "no appropriate backend found")
409   endif()
410 endif()
411
412 #Only windows
413
414 if(WIN32)
415   if(NOT HAVE_WINDOWS_H)
416     message(FATAL_ERROR "no appropriate backend found windows")
417   endif()
418 endif()
419
420 if(windows_context MATCHES "yes")
421   message(STATUS "Context change to windows")
422 endif()
423
424 #If can have both context
425
426 if(mcsc)
427   set(CONTEXT_UCONTEXT 1)
428 endif()
429
430 if(pthread)
431   set(CONTEXT_THREADS 1)
432 endif()
433
434 ###############
435 ## GIT version check
436 ##
437 if(EXISTS ${CMAKE_HOME_DIRECTORY}/.git/ AND NOT WIN32)
438   execute_process(COMMAND git remote
439   COMMAND head -n 1
440   WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/.git/
441   OUTPUT_VARIABLE remote
442   RESULT_VARIABLE ret
443   )
444   string(REPLACE "\n" "" remote "${remote}")
445   #message(STATUS "Git remote: ${remote}")
446   execute_process(COMMAND git config --get remote.${remote}.url
447   WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/.git/
448   OUTPUT_VARIABLE url
449   RESULT_VARIABLE ret
450   )
451   string(REPLACE "\n" "" url "${url}")
452   #message(STATUS "Git url: ${url}")
453   if(url)
454     execute_process(COMMAND git --git-dir=${CMAKE_HOME_DIRECTORY}/.git log --pretty=oneline --abbrev-commit -1
455     WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/.git/
456     OUTPUT_VARIABLE GIT_VERSION
457     RESULT_VARIABLE ret
458     )
459     string(REPLACE "\n" "" GIT_VERSION "${GIT_VERSION}")
460     message(STATUS "Git version: ${GIT_VERSION}")
461     execute_process(COMMAND git --git-dir=${CMAKE_HOME_DIRECTORY}/.git log -n 1 --pretty=format:%ai .
462     WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/.git/
463     OUTPUT_VARIABLE GIT_DATE
464     RESULT_VARIABLE ret
465     )
466     string(REPLACE "\n" "" GIT_DATE "${GIT_DATE}")
467     message(STATUS "Git date: ${GIT_DATE}")
468     string(REGEX REPLACE " .*" "" GIT_VERSION "${GIT_VERSION}")
469     STRING(REPLACE " +0000" "" GIT_DATE "${GIT_DATE}")
470     STRING(REPLACE " " "~" GIT_DATE "${GIT_DATE}")
471     STRING(REPLACE ":" "-" GIT_DATE "${GIT_DATE}")
472   endif()
473 endif()
474
475 #--------------------------------------------------------------------------------------------------
476
477 set(makecontext_CPPFLAGS_2 "")
478 if(HAVE_MAKECONTEXT OR WIN32)
479   set(makecontext_CPPFLAGS "-DTEST_makecontext")
480   if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
481     set(makecontext_CPPFLAGS_2 "-D_XOPEN_SOURCE")
482   endif()
483
484   if(WIN32)
485     if(ARCH_32_BITS)
486       set(makecontext_CPPFLAGS "-DTEST_makecontext -D_I_X86_")
487     else()
488       set(makecontext_CPPFLAGS "-DTEST_makecontext -D_AMD64_")
489     endif()
490     set(makecontext_CPPFLAGS_2 "-D_XBT_WIN32 -I${CMAKE_HOME_DIRECTORY}/include/xbt -I${CMAKE_HOME_DIRECTORY}/src/xbt")
491   endif()
492
493   file(REMOVE ${CMAKE_BINARY_DIR}/conftestval)
494
495   try_run(RUN_makecontext_VAR COMPILE_makecontext_VAR
496     ${CMAKE_BINARY_DIR}
497     ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_stacksetup.c
498     COMPILE_DEFINITIONS "${makecontext_CPPFLAGS} ${makecontext_CPPFLAGS_2}"
499     )
500
501   if(EXISTS ${CMAKE_BINARY_DIR}/conftestval)
502     file(READ ${CMAKE_BINARY_DIR}/conftestval MAKECONTEXT_ADDR_SIZE)
503     string(REPLACE "\n" "" MAKECONTEXT_ADDR_SIZE "${MAKECONTEXT_ADDR_SIZE}")
504     string(REGEX MATCH ;^.*,;MAKECONTEXT_ADDR "${MAKECONTEXT_ADDR_SIZE}")
505     string(REGEX MATCH ;,.*$; MAKECONTEXT_SIZE "${MAKECONTEXT_ADDR_SIZE}")
506     string(REPLACE "," "" makecontext_addr "${MAKECONTEXT_ADDR}")
507     string(REPLACE "," "" makecontext_size "${MAKECONTEXT_SIZE}")
508     set(pth_skaddr_makecontext "#define pth_skaddr_makecontext(skaddr,sksize) (${makecontext_addr})")
509     set(pth_sksize_makecontext "#define pth_sksize_makecontext(skaddr,sksize) (${makecontext_size})")
510     message(STATUS "${pth_skaddr_makecontext}")
511     message(STATUS "${pth_sksize_makecontext}")
512   else()
513     #       message(FATAL_ERROR "makecontext is not compilable")
514   endif()
515 endif()
516
517 #--------------------------------------------------------------------------------------------------
518
519 ### check for stackgrowth
520 if (NOT CMAKE_CROSSCOMPILING)
521   try_run(RUN_makecontext_VAR COMPILE_makecontext_VAR
522     ${CMAKE_BINARY_DIR}
523     ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_stackgrowth.c
524     )
525   file(READ "${CMAKE_BINARY_DIR}/conftestval" stack)
526   if(stack MATCHES "down")
527     set(PTH_STACKGROWTH "-1")
528   endif()
529   if(stack MATCHES "up")
530     set(PTH_STACKGROWTH "1")
531   endif()
532
533 endif()
534 ###############
535 ## System checks
536 ##
537
538 #SG_CONFIGURE_PART([System checks...])
539 #AC_PROG_CC(xlC gcc cc) -auto
540 #AM_SANITY_CHECK -auto
541
542 #AC_PROG_MAKE_SET
543
544 #AC_PRINTF_NULL
545 try_run(RUN_PRINTF_NULL_VAR COMPILE_PRINTF_NULL_VAR
546   ${CMAKE_BINARY_DIR}
547   ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_printf_null.c
548   )
549
550 if(RUN_PRINTF_NULL_VAR MATCHES "FAILED_TO_RUN")
551   SET(PRINTF_NULL_WORKING "0")
552 else()
553   SET(PRINTF_NULL_WORKING "1")
554 endif()
555
556 #AC_CHECK_VA_COPY
557
558 set(diff_va "va_copy((d),(s))"
559   "VA_COPY((d),(s))"
560   "__va_copy((d),(s))"
561   "__builtin_va_copy((d),(s))"
562   "do { (d) = (s)\; } while (0)"
563   "do { *(d) = *(s)\; } while (0)"
564   "memcpy((void *)&(d), (void *)&(s), sizeof(s))"
565   "memcpy((void *)(d), (void *)(s), sizeof(*(s)))"
566   )
567
568 foreach(fct ${diff_va})
569   write_file("${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_va_copy.c" "#include <stdlib.h>
570         #include <stdarg.h>
571         #include <string.h>
572         #define DO_VA_COPY(d,s) ${fct}
573         void test(char *str, ...)
574         {
575             va_list ap, ap2;
576             int i;
577             va_start(ap, str);
578             DO_VA_COPY(ap2, ap);
579             for (i = 1; i <= 9; i++) {
580                 int k = (int)va_arg(ap, int);
581                 if (k != i)
582                     abort();
583             }
584             DO_VA_COPY(ap, ap2);
585             for (i = 1; i <= 9; i++) {
586                 int k = (int)va_arg(ap, int);
587                 if (k != i)
588                     abort();
589             }
590             va_end(ap);
591         }
592         int main(void)
593         {
594             test(\"test\", 1, 2, 3, 4, 5, 6, 7, 8, 9);
595             exit(0);
596         }"
597     )
598   try_compile(COMPILE_VA_NULL_VAR
599     ${CMAKE_BINARY_DIR}
600     ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_va_copy.c
601     )
602   if(COMPILE_VA_NULL_VAR)
603     string(REGEX REPLACE "\;" "" fctbis ${fct})
604     if(${fctbis} STREQUAL "va_copy((d),(s))")
605       set(HAVE_VA_COPY 1)
606       set(ac_cv_va_copy "C99")
607       set(__VA_COPY_USE_C99 "va_copy((d),(s))")
608     endif()
609
610     if(${fctbis} STREQUAL "VA_COPY((d),(s))")
611       set(ac_cv_va_copy "GCM")
612       set(__VA_COPY_USE_GCM "VA_COPY((d),(s))")
613     endif()
614
615     if(${fctbis} STREQUAL "__va_copy((d),(s))")
616       set(ac_cv_va_copy "GCH")
617       set(__VA_COPY_USE_GCH "__va_copy((d),(s))")
618     endif()
619
620     if(${fctbis} STREQUAL "__builtin_va_copy((d),(s))")
621       set(ac_cv_va_copy "GCB")
622       set(__VA_COPY_USE_GCB "__builtin_va_copy((d),(s))")
623     endif()
624
625     if(${fctbis} STREQUAL "do { (d) = (s) } while (0)")
626       set(ac_cv_va_copy "ASS")
627       set(__VA_COPY_USE_ASS "do { (d) = (s); } while (0)")
628     endif()
629
630     if(${fctbis} STREQUAL "do { *(d) = *(s) } while (0)")
631       set(ac_cv_va_copy "ASP")
632       set(__VA_COPY_USE_ASP "do { *(d) = *(s); } while (0)")
633     endif()
634
635     if(${fctbis} STREQUAL "memcpy((void *)&(d), (void *)&(s), sizeof(s))")
636       set(ac_cv_va_copy "CPS")
637       set(__VA_COPY_USE_CPS "memcpy((void *)&(d), (void *)&(s), sizeof(s))")
638     endif()
639
640     if(${fctbis} STREQUAL "memcpy((void *)(d), (void *)(s), sizeof(*(s)))")
641       set(ac_cv_va_copy "CPP")
642       set(__VA_COPY_USE_CPP "memcpy((void *)(d), (void *)(s), sizeof(*(s)))")
643     endif()
644
645     if(NOT STATUS_OK)
646       set(__VA_COPY_USE "__VA_COPY_USE_${ac_cv_va_copy}(d, s)")
647     endif()
648     set(STATUS_OK "1")
649
650   endif()
651
652 endforeach(fct ${diff_va})
653
654 #--------------------------------------------------------------------------------------------------
655 ### check for getline
656 try_compile(COMPILE_RESULT_VAR
657   ${CMAKE_BINARY_DIR}
658   ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_getline.c
659   )
660
661 if(NOT COMPILE_RESULT_VAR)
662   SET(need_getline "#define SIMGRID_NEED_GETLINE 1")
663   SET(SIMGRID_NEED_GETLINE 1)
664 else()
665   SET(need_getline "")
666   SET(SIMGRID_NEED_GETLINE 0)
667 endif()
668
669 ### check for a working snprintf
670 if(HAVE_SNPRINTF AND HAVE_VSNPRINTF OR WIN32)
671   if(WIN32)
672     #set(HAVE_SNPRINTF 1)
673     #set(HAVE_VSNPRINTF 1)
674   endif()
675
676   if(CMAKE_CROSSCOMPILING)
677     set(RUN_SNPRINTF_FUNC "cross")
678     #set(PREFER_PORTABLE_SNPRINTF 1)
679   else()
680     try_run(RUN_SNPRINTF_FUNC_VAR COMPILE_SNPRINTF_FUNC_VAR
681       ${CMAKE_BINARY_DIR}
682       ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_snprintf.c
683       )
684   endif()
685
686   if(CMAKE_CROSSCOMPILING)
687     set(RUN_VSNPRINTF_FUNC "cross")
688     set(PREFER_PORTABLE_VSNPRINTF 1)
689   else()
690     try_run(RUN_VSNPRINTF_FUNC_VAR COMPILE_VSNPRINTF_FUNC_VAR
691       ${CMAKE_BINARY_DIR}
692       ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_vsnprintf.c
693       )
694   endif()
695
696   set(PREFER_PORTABLE_SNPRINTF 0)
697   if(RUN_VSNPRINTF_FUNC_VAR MATCHES "FAILED_TO_RUN")
698     set(PREFER_PORTABLE_SNPRINTF 1)
699   endif()
700   if(RUN_SNPRINTF_FUNC_VAR MATCHES "FAILED_TO_RUN")
701     set(PREFER_PORTABLE_SNPRINTF 1)
702   endif()
703 endif()
704
705 ### check for asprintf function familly
706 if(HAVE_ASPRINTF)
707   SET(simgrid_need_asprintf "")
708   SET(NEED_ASPRINTF 0)
709 else()
710   SET(simgrid_need_asprintf "#define SIMGRID_NEED_ASPRINTF 1")
711   SET(NEED_ASPRINTF 1)
712 endif()
713
714 if(HAVE_VASPRINTF)
715   SET(simgrid_need_vasprintf "")
716   SET(NEED_VASPRINTF 0)
717 else()
718   SET(simgrid_need_vasprintf "#define SIMGRID_NEED_VASPRINTF 1")
719   SET(NEED_VASPRINTF 1)
720 endif()
721
722 ### check for addr2line
723
724 find_path(ADDR2LINE NAMES addr2line     PATHS NO_DEFAULT_PATHS  )
725 if(ADDR2LINE)
726   set(ADDR2LINE "${ADDR2LINE}/addr2line")
727 endif()
728
729 ### Check if OSX can compile with ucontext (with gcc 4.[1-5] it is broken)
730 if(APPLE)
731   if(APPLE_NEED_GCC_VERSION GREATER COMPILER_C_VERSION_MAJOR_MINOR)
732     message(STATUS "Ucontext can't be used with this version of gcc (must be greater than 4.5)")
733     set(HAVE_UCONTEXT_H 0)
734   endif()
735 endif()
736
737 ### File to create
738
739 configure_file("${CMAKE_HOME_DIRECTORY}/src/context_sysv_config.h.in"                   "${CMAKE_BINARY_DIR}/src/context_sysv_config.h" @ONLY IMMEDIATE)
740
741 SET( CMAKEDEFINE "#cmakedefine" )
742 configure_file("${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/src/internal_config.h.in"      "${CMAKE_BINARY_DIR}/src/internal_config.h" @ONLY IMMEDIATE)
743 configure_file("${CMAKE_BINARY_DIR}/src/internal_config.h"                      "${CMAKE_BINARY_DIR}/src/internal_config.h" @ONLY IMMEDIATE)
744 configure_file("${CMAKE_HOME_DIRECTORY}/include/simgrid_config.h.in"            "${CMAKE_BINARY_DIR}/include/simgrid_config.h" @ONLY IMMEDIATE)
745
746 set(top_srcdir "${CMAKE_HOME_DIRECTORY}")
747 set(srcdir "${CMAKE_HOME_DIRECTORY}/src")
748
749 ### Script used when simgrid is installed
750 set(exec_prefix ${CMAKE_INSTALL_PREFIX})
751 set(includeflag "-I${CMAKE_INSTALL_PREFIX}/include -I${CMAKE_INSTALL_PREFIX}/include/smpi")
752 set(includedir "${CMAKE_INSTALL_PREFIX}/include")
753 set(libdir ${exec_prefix}/lib)
754 set(CMAKE_SMPI_COMMAND "export LD_LIBRARY_PATH=${CMAKE_INSTALL_PREFIX}/lib:${GTNETS_LIB_PATH}:${HAVE_NS3_LIB}:$LD_LIBRARY_PATH")
755
756 configure_file(${CMAKE_HOME_DIRECTORY}/include/smpi/smpif.h.in ${CMAKE_BINARY_DIR}/include/smpi/smpif.h @ONLY)
757 configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpicc.in ${CMAKE_BINARY_DIR}/bin/smpicc @ONLY)
758 configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpif2c.in ${CMAKE_BINARY_DIR}/bin/smpif2c @ONLY)
759 configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpiff.in ${CMAKE_BINARY_DIR}/bin/smpiff @ONLY)
760 configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpirun.in ${CMAKE_BINARY_DIR}/bin/smpirun @ONLY)
761
762 ### Script used when simgrid is compiling
763 set(includeflag "-I${CMAKE_HOME_DIRECTORY}/include -I${CMAKE_HOME_DIRECTORY}/include/smpi")
764 set(includeflag "${includeflag} -I${CMAKE_BINARY_DIR}/include -I${CMAKE_BINARY_DIR}/include/smpi")
765 set(includedir "${CMAKE_HOME_DIRECTORY}/include")
766 set(exec_prefix "${CMAKE_BINARY_DIR}/smpi_script/")
767 set(CMAKE_SMPI_COMMAND "export LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/lib:${GTNETS_LIB_PATH}:${HAVE_NS3_LIB}:$LD_LIBRARY_PATH")
768 set(libdir "${CMAKE_BINARY_DIR}/lib")
769
770 configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpicc.in ${CMAKE_BINARY_DIR}/smpi_script/bin/smpicc @ONLY)
771 configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpif2c.in ${CMAKE_BINARY_DIR}/smpi_script/bin/smpif2c @ONLY)
772 configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpiff.in ${CMAKE_BINARY_DIR}/smpi_script/bin/smpiff @ONLY)
773 configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpirun.in ${CMAKE_BINARY_DIR}/smpi_script/bin/smpirun @ONLY)
774
775 set(top_builddir ${CMAKE_HOME_DIRECTORY})
776
777 if(NOT WIN32)
778   execute_process(COMMAND chmod a=rwx ${CMAKE_BINARY_DIR}/bin/smpicc)
779   execute_process(COMMAND chmod a=rwx ${CMAKE_BINARY_DIR}/bin/smpif2c)
780   execute_process(COMMAND chmod a=rwx ${CMAKE_BINARY_DIR}/bin/smpiff)
781   execute_process(COMMAND chmod a=rwx ${CMAKE_BINARY_DIR}/bin/smpirun)
782   execute_process(COMMAND chmod a=rwx ${CMAKE_BINARY_DIR}/smpi_script/bin/smpicc)
783   execute_process(COMMAND chmod a=rwx ${CMAKE_BINARY_DIR}/smpi_script/bin/smpif2c)
784   execute_process(COMMAND chmod a=rwx ${CMAKE_BINARY_DIR}/smpi_script/bin/smpiff)
785   execute_process(COMMAND chmod a=rwx ${CMAKE_BINARY_DIR}/smpi_script/bin/smpirun)
786 endif()
787
788 set(generated_headers_to_install
789   ${CMAKE_CURRENT_BINARY_DIR}/include/smpi/smpif.h
790   ${CMAKE_CURRENT_BINARY_DIR}/include/simgrid_config.h
791   )
792
793 set(generated_headers
794   ${CMAKE_CURRENT_BINARY_DIR}/src/context_sysv_config.h
795   ${CMAKE_CURRENT_BINARY_DIR}/src/internal_config.h
796   )
797
798 set(generated_files_to_clean
799   ${generated_headers}
800   ${generated_headers_to_install}
801   ${CMAKE_BINARY_DIR}/bin/smpicc
802   ${CMAKE_BINARY_DIR}/bin/smpif2c
803   ${CMAKE_BINARY_DIR}/bin/smpiff
804   ${CMAKE_BINARY_DIR}/bin/smpirun
805   ${CMAKE_BINARY_DIR}/bin/colorize
806   ${CMAKE_BINARY_DIR}/bin/simgrid_update_xml
807   ${CMAKE_BINARY_DIR}/examples/smpi/tracing/smpi_traced.trace
808   ${CMAKE_BINARY_DIR}/src/supernovae_sg.c
809   ${CMAKE_BINARY_DIR}/src/supernovae_smpi.c
810   )
811
812 if("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_HOME_DIRECTORY}")
813 else()
814   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/hostfile ${CMAKE_BINARY_DIR}/examples/smpi/hostfile COPYONLY)
815   configure_file(${CMAKE_HOME_DIRECTORY}/examples/msg/small_platform.xml ${CMAKE_BINARY_DIR}/examples/msg/small_platform.xml COPYONLY)
816   configure_file(${CMAKE_HOME_DIRECTORY}/examples/msg/small_platform_with_routers.xml ${CMAKE_BINARY_DIR}/examples/msg/small_platform_with_routers.xml COPYONLY)
817   configure_file(${CMAKE_HOME_DIRECTORY}/examples/msg/tracing/platform.xml ${CMAKE_BINARY_DIR}/examples/msg/tracing/platform.xml COPYONLY)
818   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay/actions0.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay/actions0.txt COPYONLY)
819   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay/actions1.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay/actions1.txt COPYONLY)
820   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay/actions_bcast.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay/actions_bcast.txt COPYONLY)
821   configure_file(${CMAKE_HOME_DIRECTORY}/teshsuite/smpi/hostfile ${CMAKE_BINARY_DIR}/teshsuite/smpi/hostfile COPYONLY)
822
823   set(generated_files_to_clean
824     ${generated_files_to_clean}
825     ${CMAKE_BINARY_DIR}/examples/smpi/hostfile
826     ${CMAKE_BINARY_DIR}/examples/msg/small_platform.xml
827     ${CMAKE_BINARY_DIR}/examples/msg/small_platform_with_routers.xml
828     ${CMAKE_BINARY_DIR}/examples/msg/tracing/platform.xml
829     ${CMAKE_BINARY_DIR}/examples/smpi/replay/actions0.txt
830     ${CMAKE_BINARY_DIR}/examples/smpi/replay/actions1.txt
831     ${CMAKE_BINARY_DIR}/examples/smpi/replay/actions_bcast.txt
832     ${CMAKE_BINARY_DIR}/teshsuite/smpi/hostfile
833     )
834 endif()
835
836 SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES
837   "${generated_files_to_clean}")
838
839 IF(${ARCH_32_BITS})
840   set(WIN_ARCH "32")
841 ELSE()
842   set(WIN_ARCH "64")
843 ENDIF()
844 configure_file("${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/src/simgrid.nsi.in"    "${CMAKE_BINARY_DIR}/simgrid.nsi" @ONLY IMMEDIATE)