Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Forgot smthing...
[simgrid.git] / buildtools / CPACK / src / CMakeCompleteInFiles.txt
1 include(CheckFunctionExists)
2 include(CheckIncludeFile)
3 include(CheckIncludeFiles)
4 include(CheckLibraryExists)
5 set(CONTEXT_UCONTEXT 0)
6 SET(CONTEXT_THREADS 0)
7
8 #--------------------------------------------------------------------------------------------------
9 ### Initialize of CONTEXT JAVA
10 if(disable_java)
11         SET(HAVE_JAVA 0)
12 else(disable_java)
13         include(FindJava)
14         include(FindJNI)
15         if(JAVA_INCLUDE_PATH)
16                 set(HAVE_JNI_H 1)
17         endif(JAVA_INCLUDE_PATH)        
18         if(JAVA_RUNTIME AND JAVA_COMPILE AND JAVA_INCLUDE_PATH)
19                 SET(HAVE_JAVA 1)
20         else(JAVA_RUNTIME AND JAVA_COMPILE AND JAVA_INCLUDE_PATH) 
21                 SET(HAVE_JAVA 0)
22         endif(JAVA_RUNTIME AND JAVA_COMPILE AND JAVA_INCLUDE_PATH)
23 endif(disable_java)
24 #message("HAVE_JAVA ${HAVE_JAVA}")
25
26 #--------------------------------------------------------------------------------------------------
27 ### Initialize of CONTEXT GTNETS
28 if(disable_gtnets)
29         SET(HAVE_GTNETS 0)
30 else(disable_gtnets)
31         set(GTNETS_LDFLAGS "-lgtnets -L${gtnets_path}/lib")
32         set(GTNETS_CPPFLAGS "-I${gtnets_path}/include -I${gtnets_path}/include/gtnets")
33         exec_program("${CMAKE_CXX_COMPILER} ${GTNETS_CPPFLAGS} ${GTNETS_LDFLAGS} ${PROJECT_DIRECTORY}/CPACK/prog_test/prog_gtnets.cpp" OUTPUT_VARIABLE COMPILE_GTNETS_VAR)      
34         if(COMPILE_GTNETS_VAR)
35                 SET(HAVE_GTNETS 0)
36         else(COMPILE_GTNETS_VAR)
37                 SET(HAVE_GTNETS 1)
38                 set(INCLUDES
39                         ${INCLUDES}
40                         ${GTNETS_CPPFLAGS}
41                 )
42                 add_definitions(${GTNETS_LDFLAGS})
43         endif(COMPILE_GTNETS_VAR)
44 endif(disable_gtnets)
45 #message("HAVE_GTNETS ${HAVE_GTNETS}")
46
47 #--------------------------------------------------------------------------------------------------
48 ### Initialize of CONTEXT THREADS
49
50 CHECK_INCLUDE_FILE(pthread.h HAVE_PTHREAD_H)
51 CHECK_LIBRARY_EXISTS(pthread pthread_create NO_DEFAULT_PATHS pthread)
52 if(pthread)
53 set(pthread "yes")
54 elseif(pthread)
55 set(pthread "no")
56 endif(pthread)
57
58 if(pthread MATCHES "yes")
59         ### HAVE_SEM_INIT
60         CHECK_LIBRARY_EXISTS(pthread sem_init NO_DEFAULT_PATHS HAVE_SEM_INIT_LIB)
61         if(HAVE_SEM_INIT_LIB)
62                 exec_program("${CMAKE_C_COMPILER} -lpthread ${PROJECT_DIRECTORY}/CPACK/prog_test/prog_sem_init.c" OUTPUT_VARIABLE HAVE_SEM_INIT_run)
63                 if(HAVE_SEM_INIT_run)
64                         set(HAVE_SEM_INIT 0)
65                 else(HAVE_SEM_INIT_run)
66                         set(HAVE_SEM_INIT 1)
67                 endif(HAVE_SEM_INIT_run)
68                 #message("HAVE_SEM_INIT ${HAVE_SEM_INIT}")
69         endif(HAVE_SEM_INIT_LIB)
70
71         ### HAVE_SEM_TIMEDWAIT
72         CHECK_LIBRARY_EXISTS(pthread sem_timedwait NO_DEFAULT_PATHS HAVE_SEM_TIMEDWAIT_LIB)
73         if(HAVE_SEM_TIMEDWAIT_LIB)
74                 exec_program("${CMAKE_C_COMPILER} -lpthread ${PROJECT_DIRECTORY}/CPACK/prog_test/prog_sem_timedwait.c" OUTPUT_VARIABLE HAVE_SEM_TIMEDWAIT_run)
75                 if(HAVE_SEM_TIMEDWAIT_run)
76                         set(HAVE_SEM_TIMEDWAIT 0)
77                 else(HAVE_SEM_TIMEDWAIT_run)
78                         set(HAVE_SEM_TIMEDWAIT 1)
79                 endif(HAVE_SEM_TIMEDWAIT_run)
80                 #message("HAVE_SEM_TIMEDWAIT ${HAVE_SEM_TIMEDWAIT}")
81         endif(HAVE_SEM_TIMEDWAIT_LIB)
82
83         ### HAVE_MUTEX_TIMEDLOCK
84         CHECK_LIBRARY_EXISTS(pthread pthread_mutex_timedlock NO_DEFAULT_PATHS HAVE_MUTEX_TIMEDLOCK_LIB)
85         if(HAVE_MUTEX_TIMEDLOCK_LIB)
86                 exec_program("${CMAKE_C_COMPILER} -lpthread ${PROJECT_DIRECTORY}/CPACK/prog_test/prog_mutex_timedlock.c" OUTPUT_VARIABLE HAVE_SEM_TIMEDWAIT_run)
87                 if(HAVE_MUTEX_TIMEDLOCK_run)
88                         set(HAVE_MUTEX_TIMEDLOCK 0)
89                 else(HAVE_MUTEX_TIMEDLOCK_run)
90                         set(HAVE_MUTEX_TIMEDLOCK 1)
91                 endif(HAVE_MUTEX_TIMEDLOCK_run)
92                 #message("HAVE_MUTEX_TIMEDLOCK ${HAVE_MUTEX_TIMEDLOCK}")
93         endif(HAVE_MUTEX_TIMEDLOCK_LIB)
94 endif(pthread MATCHES "yes")
95
96 # AC_CHECK_MCSC(mcsc=yes, mcsc=no) 
97 try_run(RUN_mcsc_VAR COMPILE_mcsc_VAR
98         ${PROJECT_DIRECTORY}
99         ${PROJECT_DIRECTORY}/CPACK/prog_test/prog_AC_CHECK_MCSC.c
100         )
101 file(READ "${PROJECT_DIRECTORY}/conftestval" mcsc)
102 if(mcsc MATCHES "yes")
103         set(mcsc "yes")
104 elseif(mcsc MATCHES "yes")
105         set(mcsc "no")
106 endif(mcsc MATCHES "yes")
107 CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H)
108 if(mcsc MATCHES "no" AND pthread MATCHES "no")
109         if(HAVE_WINDOWS_H)
110                 set(windows_context "yes")
111                 set(IS_WINDOWS 1)
112         elseif(HAVE_WINDOWS_H)
113                 message(FATAL_ERROR "no appropriate backend found")
114         endif(HAVE_WINDOWS_H)
115 endif(mcsc MATCHES "no" AND pthread MATCHES "no")
116
117 if(with_context MATCHES "ucontext" AND mcsc MATCHES "no")
118         message(FATAL_ERROR "-Dwith-context=ucontext specified but ucontext unusable.")
119 endif(with_context MATCHES "ucontext" AND mcsc MATCHES "no")
120
121 set(with_context_ok 0)
122 if(with_context MATCHES "windows")
123         set(with_context_ok 1)
124         if(NOT HAVE_WINDOWS_H)
125                 message(FATAL_ERROR "no appropriate backend found windows")
126         endif(NOT HAVE_WINDOWS_H)
127 endif(with_context MATCHES "windows")
128
129 if(with_context MATCHES "pthreads")
130         set(with_context_ok 1)
131         set(with_context "pthread")
132 endif(with_context MATCHES "pthreads")
133
134 if(with_context MATCHES "auto")
135         set(with_context_ok 1)
136         set(with_context "ucontext")
137         message("with_context auto change to ucontext")
138 endif(with_context MATCHES "auto")
139
140 if(with_context MATCHES "ucontext")
141         set(with_context_ok 1)
142         if(mcsc MATCHES "yes")
143                 set(CONTEXT_UCONTEXT 1)
144                 CHECK_INCLUDE_FILE(valgrind/valgrind.h HAVE_VALGRIND_VALGRIND_H)
145         else(mcsc MATCHES "yes")
146                 if(windows_context MATCHES "yes")
147                         set(with_context "windows")
148                 else(windows_context MATCHES "yes")
149                         set(with_context "pthread")
150                 endif(windows_context MATCHES "yes")
151         endif(mcsc MATCHES "yes")
152 endif(with_context MATCHES "ucontext")
153
154 if(with_context MATCHES "pthread")
155         set(with_context_ok 1)
156         if(pthread MATCHES "no")
157                 message(FATAL_ERROR "Cannot find pthreads (try -Dwith_context=ucontext if you haven't already tried).")
158         endif(pthread MATCHES "no")
159         SET(CONTEXT_THREADS 1)
160 endif(with_context MATCHES "pthread")
161
162 if(with_context MATCHES "ucontext")
163         SET(CONTEXT_THREADS 0)
164 endif(with_context MATCHES "ucontext")
165
166 if(NOT with_context_ok)
167         message(FATAL_ERROR "-Dwith-context must be either ucontext or pthread")
168 endif(NOT with_context_ok)
169
170
171 #message("CONTEXT_THREADS ${CONTEXT_THREADS}")
172 #message("CONTEXT_UCONTEXT ${CONTEXT_UCONTEXT}")
173 set(HAVE_LUA 0)
174 if(NOT disable_lua)
175         CHECK_INCLUDE_FILE(lua5.1/lualib.h HAVE_LUA5_1_LUALIB_H)
176         #message("HAVE_LUA5_1_LUALIB_H ${HAVE_LUA5_1_LUALIB_H}")
177         if(HAVE_LUA5_1_LUALIB_H)
178                 set(HAVE_LUA 1)
179         endif(HAVE_LUA5_1_LUALIB_H)
180 endif(NOT disable_lua)
181 #message("HAVE_LUA ${HAVE_LUA}")
182
183 #message("______END_CONTEXT______")
184
185 ###############
186 ## SVN version check
187 ##
188 #message("\n__________SVN__________")
189 if(IS_DIRECTORY ${PROJECT_DIRECTORY}/.svn)
190         #exec_program("svn up ${PROJECT_DIRECTORY}")
191         find_file(SVN ".svn" ${PROJECT_DIRECTORY})
192         exec_program("svnversion ${PROJECT_DIRECTORY}" OUTPUT_VARIABLE "SVN_VERSION")
193         #message("SVN_VERSION ${SVN_VERSION}")
194 endif(IS_DIRECTORY ${PROJECT_DIRECTORY}/.svn)
195
196 if(IS_DIRECTORY ${PROJECT_DIRECTORY}/.git)
197         find_file(GIT ".git" ${PROJECT_DIRECTORY})
198         exec_program("git --git-dir=${PROJECT_DIRECTORY} log --oneline -1 | sed 's| .*||'" OUTPUT_VARIABLE "GIT_VERSION")
199         #message("GIT_VERSION ${GIT_VERSION}")
200 endif(IS_DIRECTORY ${PROJECT_DIRECTORY}/.git)
201 #message("________END_SVN________\n")
202
203 #message("\n_____GRAS_&_SIMGRID____")
204 ###################################
205 ## SimGrid and GRAS specific checks
206 ##
207 include(TestBigEndian)
208 TEST_BIG_ENDIAN(BIGENDIAN)
209 # Check architecture signature begin
210 try_run(RUN_GRAS_VAR COMPILE_GRAS_VAR
211         ${PROJECT_DIRECTORY}
212         ${PROJECT_DIRECTORY}/CPACK/prog_test/prog_GRAS_ARCH.c
213         RUN_OUTPUT_VARIABLE var1
214         )
215 if(BIGENDIAN)
216 set(val_big "B${var1}")
217 set(GRAS_BIGENDIAN 1)
218 else(BIGENDIAN)
219 set(val_big "l${var1}")
220 set(GRAS_BIGENDIAN 0)
221 endif(BIGENDIAN)
222 #message("GRAS_BIGENDIAN ${GRAS_BIGENDIAN}")
223 #message("${val_big}")
224
225 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:")
226         #message("gras_arch=0; gras_size=32; gras_arch_name=little32_1;")
227         SET(GRAS_ARCH_32_BITS 1)
228         SET(GRAS_THISARCH 0)
229 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:")
230 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:")
231         #message("gras_arch=1; gras_size=32; gras_arch_name=little32_2;")
232         SET(GRAS_ARCH_32_BITS 1)
233         SET(GRAS_THISARCH 1)
234 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:")
235 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:") 
236         #message("gras_arch=2; gras_size=32; gras_arch_name=little32_4;")
237         SET(GRAS_ARCH_32_BITS 1)
238         SET(GRAS_THISARCH 2)
239 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:")
240 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:") 
241         #message("gras_arch=3; gras_size=32; gras_arch_name=little32_8;")
242         SET(GRAS_ARCH_32_BITS 1)
243         SET(GRAS_THISARCH 3)
244 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:") 
245 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:") 
246         #message("gras_arch=4; gras_size=64; gras_arch_name=little64;")
247         SET(GRAS_ARCH_32_BITS 0)
248         SET(GRAS_THISARCH 4)
249 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:")
250
251 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:") 
252         #message("gras_arch=5; gras_size=32; gras_arch_name=big32;")
253         SET(GRAS_ARCH_32_BITS 1)
254         SET(GRAS_THISARCH 5)
255 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:")
256 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:") 
257         #message("gras_arch=6; gras_size=32; gras_arch_name=big32_8_4;")
258         SET(GRAS_ARCH_32_BITS 1)
259         SET(GRAS_THISARCH 6)
260 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:")
261 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:") 
262         #message("gras_arch=7; gras_size=32; gras_arch_name=big32_4;")
263         SET(GRAS_ARCH_32_BITS 1)
264         SET(GRAS_THISARCH 7)
265 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:")
266 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:") 
267         #message("gras_arch=8; gras_size=32; gras_arch_name=big32_2;")
268         SET(GRAS_ARCH_32_BITS 1)
269         SET(GRAS_THISARCH 8)
270 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:") 
271 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:") 
272         #message("gras_arch=9; gras_size=64; gras_arch_name=big64;")
273         SET(GRAS_ARCH_32_BITS 0)
274         SET(GRAS_THISARCH 9)
275 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:")
276 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:") 
277         #message("gras_arch=10;gras_size=64; gras_arch_name=big64_8_4;")
278         SET(GRAS_ARCH_32_BITS 0)
279         SET(GRAS_THISARCH 10)
280 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:") 
281         #message("GRAS_ARCH_32_BITS ${GRAS_ARCH_32_BITS}")
282
283
284 # Check architecture signature end
285 try_run(RUN_GRAS_VAR COMPILE_GRAS_VAR
286         ${PROJECT_DIRECTORY}
287         ${PROJECT_DIRECTORY}/CPACK/prog_test/prog_GRAS_CHECK_STRUCT_COMPACTION.c
288         RUN_OUTPUT_VARIABLE var2
289         )
290 separate_arguments(var2)
291 foreach(var_tmp ${var2})
292         set(${var_tmp} 1)
293         #message("${var_tmp} ${${var_tmp}}")
294 endforeach(var_tmp ${var2})
295
296 # Check for [SIZEOF_MAX]
297 try_run(RUN_SM_VAR COMPILE_SM_VAR
298         ${PROJECT_DIRECTORY}
299         ${PROJECT_DIRECTORY}/CPACK/prog_test/prog_max_size.c
300         RUN_OUTPUT_VARIABLE var3
301         )
302 SET(SIZEOF_MAX ${var3})
303 #message("SIZEOF_MAX ${SIZEOF_MAX}")
304
305
306 #--------------------------------------------------------------------------------------------------
307
308
309 CHECK_FUNCTION_EXISTS(makecontext HAVE_MAKECONTEXT)
310 #message("HAVE_MAKECONTEXT ${HAVE_MAKECONTEXT}")
311
312 if(HAVE_MAKECONTEXT)
313         set(makecontext_CPPFLAGS "-DTEST_makecontext")
314         if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
315                 set(makecontext_CPPFLAGS_2 "-DOSX")
316                 #message("SYSTEM OSX")
317         endif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
318
319         exec_program("${CMAKE_C_COMPILER} ${PROJECT_DIRECTORY}/CPACK/prog_test/prog_stacksetup.c ${makecontext_CPPFLAGS} ${makecontext_CPPFLAGS_2}" OUTPUT_VARIABLE COMPILE_makecontext_VAR)
320         exec_program("${PROJECT_DIRECTORY}/CPACK/prog_test/a.out" OUTPUT_VARIABLE COMPILE_makecontext_VAR)
321
322         find_program(CAT_EXE NAMES cat)
323
324         exec_program("${SED_EXE}" ARGS "-e 's;,.*$;;' ${PROJECT_DIRECTORY}/CPACK/prog_test/conftestval" OUTPUT_VARIABLE "makecontext_addr")
325         exec_program("${SED_EXE}" ARGS "-e 's;^.*,;;' ${PROJECT_DIRECTORY}/CPACK/prog_test/conftestval" OUTPUT_VARIABLE "makecontext_size")
326         #message("${makecontext_addr}")
327         #message("${makecontext_size}")
328         set(pth_skaddr_makecontext "#define pth_skaddr_makecontext(skaddr,sksize) (${makecontext_addr})")
329         set(pth_sksize_makecontext "#define pth_sksize_makecontext(skaddr,sksize) (${makecontext_size})")
330
331 endif(HAVE_MAKECONTEXT)
332
333 #--------------------------------------------------------------------------------------------------
334
335 ### check for stackgrowth
336
337         try_run(RUN_makecontext_VAR COMPILE_makecontext_VAR
338                 ${PROJECT_DIRECTORY}
339                 ${PROJECT_DIRECTORY}/CPACK/prog_test/prog_stackgrowth.c
340                 )
341 file(READ "${PROJECT_DIRECTORY}/conftestval" stack)
342 if(stack MATCHES "down")
343         set(PTH_STACKGROWTH "-1")
344 endif(stack MATCHES "down")
345 if(stack MATCHES "up")
346         set(PTH_STACKGROWTH "1")
347 endif(stack MATCHES "up")
348 #message("PTH_STACKGROWTH ${PTH_STACKGROWTH}")
349
350
351 ###############
352 ## System checks
353 ##
354
355 #SG_CONFIGURE_PART([System checks...])
356 #AC_PROG_CC(xlC gcc cc) -auto
357 #AM_SANITY_CHECK -auto
358
359 #AC_PROG_MAKE_SET
360 find_program(SET_MAKE NAMES make)
361
362 #AC_PRINTF_NULL
363 try_run(RUN_PRINTF_NULL_VAR COMPILE_PRINTF_NULL_VAR
364         ${PROJECT_DIRECTORY}
365         ${PROJECT_DIRECTORY}/CPACK/prog_test/prog_printf_null.c
366         )
367
368 if(RUN_PRINTF_NULL_VAR MATCHES "FAILED_TO_RUN")
369 SET(PRINTF_NULL_WORKING "0")
370 else(RUN_PRINTF_NULL_VAR MATCHES "FAILED_TO_RUN")
371 SET(PRINTF_NULL_WORKING "1")
372 endif(RUN_PRINTF_NULL_VAR MATCHES "FAILED_TO_RUN")
373 #message("PRINTF_NULL_WORKING ${PRINTF_NULL_WORKING}")
374
375 #AC_CHECK_VA_COPY
376
377 set(diff_va "va_copy((d),(s))"
378 "VA_COPY((d),(s))"
379 "__va_copy((d),(s))"
380 "__builtin_va_copy((d),(s))"
381 "do { (d) = (s)\; } while (0)"
382 "do { *(d) = *(s)\; } while (0)"
383 "memcpy((void *)&(d), (void *)&(s)), sizeof((s))"
384 "memcpy((void *)(d), (void *)(s)), sizeof(*(s))"
385 )
386
387 foreach(fct ${diff_va})
388         write_file("${PROJECT_DIRECTORY}/CPACK/prog_test/prog_va_copy.c" "#include <stdlib.h>
389         #include <stdarg.h>
390         #include <string.h>
391         #define DO_VA_COPY(d,s) ${fct}
392         void test(char *str, ...)
393         {
394             va_list ap, ap2;
395             int i;
396             va_start(ap, str);
397             DO_VA_COPY(ap2, ap);
398             for (i = 1; i <= 9; i++) {
399                 int k = (int)va_arg(ap, int);
400                 if (k != i)
401                     abort();
402             }
403             DO_VA_COPY(ap, ap2);
404             for (i = 1; i <= 9; i++) {
405                 int k = (int)va_arg(ap, int);
406                 if (k != i)
407                     abort();
408             }
409             va_end(ap);
410         }
411         int main(int argc, char *argv[])
412         {
413             test("test", 1, 2, 3, 4, 5, 6, 7, 8, 9);
414             exit(0);
415         }"
416         )
417         try_run(RUN_VA_NULL_VAR COMPILE_VA_NULL_VAR
418         ${PROJECT_DIRECTORY}
419         ${PROJECT_DIRECTORY}/CPACK/prog_test/prog_va_copy.c
420         )
421         if(RUN_VA_NULL_VAR MATCHES "FAILED_TO_RUN")
422         else(RUN_VA_NULL_VAR MATCHES "FAILED_TO_RUN")   
423
424                 string(REGEX REPLACE "\;" "" fctbis ${fct})
425
426                 if(${fctbis} STREQUAL "va_copy((d),(s))")
427                         set(HAVE_VA_COPY 1)
428                         #message("HAVE_VA_COPY ${HAVE_VA_COPY}")
429                         set(ac_cv_va_copy "C99")
430                         set(__VA_COPY_USE_C99 "va_copy((d),(s))")       
431                 endif(${fctbis} STREQUAL "va_copy((d),(s))")
432
433                 if(${fctbis} STREQUAL "VA_COPY((d),(s))")
434                         set(ac_cv_va_copy "GCM")
435                         set(__VA_COPY_USE_GCM "VA_COPY((d),(s))")
436                 endif(${fctbis} STREQUAL "VA_COPY((d),(s))")
437
438                 if(${fctbis} STREQUAL "__va_copy((d),(s))")
439                         set(ac_cv_va_copy "GCH")
440                         set(__VA_COPY_USE_GCH "__va_copy((d),(s))")
441                 endif(${fctbis} STREQUAL "__va_copy((d),(s))")
442
443                 if(${fctbis} STREQUAL "__builtin_va_copy((d),(s))")
444                         set(ac_cv_va_copy "GCB")
445                         set(__VA_COPY_USE_GCB "__builtin_va_copy((d),(s))")
446                 endif(${fctbis} STREQUAL "__builtin_va_copy((d),(s))")
447
448                 if(${fctbis} STREQUAL "do { (d) = (s) } while (0)")
449                         set(ac_cv_va_copy "ASS")
450                         set(__VA_COPY_USE_ASS "do { (d) = (s); } while (0)")
451                 endif(${fctbis} STREQUAL "do { (d) = (s) } while (0)")
452
453                 if(${fctbis} STREQUAL "do { *(d) = *(s) } while (0)")
454                         set(ac_cv_va_copy "ASP")
455                         set(__VA_COPY_USE_ASP "do { *(d) = *(s); } while (0)")
456                 endif(${fctbis} STREQUAL "do { *(d) = *(s) } while (0)")
457
458                 if(${fctbis} STREQUAL "memcpy((void *)&(d), (void *)&(s)), sizeof((s))")
459                         set(ac_cv_va_copy "CPS")
460                         set(__VA_COPY_USE_CPS "memcpy((void *)&(d), (void *)&(s)), sizeof((s))")
461                 endif(${fctbis} STREQUAL "memcpy((void *)&(d), (void *)&(s)), sizeof((s))")
462
463                 if(${fctbis} STREQUAL "memcpy((void *)(d), (void *)(s)), sizeof(*(s))")
464                         set(ac_cv_va_copy "CPP")
465                         set(__VA_COPY_USE_CPP "memcpy((void *)(d), (void *)(s)), sizeof(*(s))")
466                 endif(${fctbis} STREQUAL "memcpy((void *)(d), (void *)(s)), sizeof(*(s))")
467                                 
468                 if(NOT STATUS_OK)
469                 set(__VA_COPY_USE "__VA_COPY_USE_${ac_cv_va_copy}")
470                 #message("__VA_COPY_USE VA_COPY_USE_${ac_cv_va_copy}")
471                 endif(NOT STATUS_OK)
472                 #message("__VA_COPY_USE_${ac_cv_va_copy} ${fctbis}")
473                 set(STATUS_OK "1")
474
475         endif(RUN_VA_NULL_VAR MATCHES "FAILED_TO_RUN")
476 endforeach(fct ${diff_va})
477
478 # Checks for header files.
479
480 CHECK_INCLUDE_FILES("stdlib.h;stdarg.h;string.h;float.h" STDC_HEADERS)
481 #message("STDC_HEADERS ${STDC_HEADERS}")
482 CHECK_INCLUDE_FILES("time.h;sys/time.h" TIME_WITH_SYS_TIME)
483 #message("TIME_WITH_SYS_TIME ${TIME_WITH_SYS_TIME}")
484
485 CHECK_INCLUDE_FILE(sys/socket.h HAVE_SYS_SOCKET_H)
486 #message("HAVE_SOCKET_H ${HAVE_SOCKET_H}")
487 CHECK_INCLUDE_FILE(sys/stat.h HAVE_SYS_STAT_H)
488 #message("HAVE_STAT_H ${HAVE_STAT_H}")
489 CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H)
490 #message("HAVE_WINDOWS_H ${HAVE_WINDOWS_H}")
491 CHECK_INCLUDE_FILE(winsock.h HAVE_WINSOCK_H)
492 #message("HAVE_WINSOCK_H ${HAVE_WINSOCK_H}")
493 CHECK_INCLUDE_FILE(winsock2.h HAVE_WINSOCK2_H)
494 #message("HAVE_WINSOCK2_H ${HAVE_WINSOCK2_H}")
495 CHECK_INCLUDE_FILE(sys/time.h HAVE_SYS_TIME_H)
496 #message("HAVE_TIME_H ${HAVE_TIME_H}")
497 CHECK_INCLUDE_FILE(errno.h HAVE_ERRNO_H)
498 #message("HAVE_ERRNO_H ${HAVE_ERRNO_H}")
499 CHECK_INCLUDE_FILE(unistd.h HAVE_UNISTD_H)
500 #message("HAVE_UNISTD_H ${HAVE_UNISTD_H}")
501 CHECK_INCLUDE_FILE(execinfo.h HAVE_EXECINFO_H)
502 #message("HAVE_EXECINFO_H ${HAVE_EXECINFO_H}")
503 CHECK_INCLUDE_FILE(signal.h HAVE_SIGNAL_H)
504 #message("HAVE_SIGNAL_H ${HAVE_SIGNAL_H}")
505
506 CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
507 #message("HAVE_GETTIMEOFDAY ${HAVE_GETTIMEOFDAY}")
508 CHECK_FUNCTION_EXISTS(usleep HAVE_USLEEP)
509 #message("HAVE_USLEEP ${HAVE_USLEEP}")
510 CHECK_FUNCTION_EXISTS(getdtablesize HAVE_GETDTABLESIZE)
511 #message("HAVE_GETDTABLESIZE ${HAVE_GETDTABLESIZE}")
512 CHECK_FUNCTION_EXISTS(sysconf HAVE_SYSCONF)
513 #message("HAVE_SYSCONF ${HAVE_SYSCONF}")
514 CHECK_FUNCTION_EXISTS(readv HAVE_READV)
515 #message("HAVE_READV ${HAVE_READV}")
516 CHECK_FUNCTION_EXISTS(popen HAVE_POPEN)
517 #message("HAVE_POPEN ${HAVE_POPEN}")
518 CHECK_FUNCTION_EXISTS(signal HAVE_SIGNAL)
519 #message("HAVE_SIGNAL ${HAVE_SIGNAL}")
520
521 #--------------------------------------------------------------------------------------------------
522 ### Try execut getline command
523 try_run(RUN_RESULT_VAR COMPILE_RESULT_VAR
524         ${PROJECT_DIRECTORY}
525         ${PROJECT_DIRECTORY}/CPACK/prog_test/prog_getline.c
526         OUTPUT_VARIABLE GETLINE_OUTPUT
527         )
528
529 if(RUN_RESULT_VAR MATCHES "FAILED_TO_RUN")
530 SET(need_getline "")
531 else(RUN_RESULT_VAR MATCHES "FAILED_TO_RUN")
532 SET(need_getline "#define SIMGRID_NEED_GETLINE 1")
533 endif(RUN_RESULT_VAR MATCHES "FAILED_TO_RUN")
534
535 ### check for a working snprintf
536 CHECK_FUNCTION_EXISTS(snprintf HAVE_SNPRINTF)
537 CHECK_FUNCTION_EXISTS(vsnprintf HAVE_VSNPRINTF)
538 if(HAVE_SNPRINTF AND HAVE_VSNPRINTF)
539
540         try_run(RUN_SNPRINTF_FUNC_VAR COMPILE_SNPRINTF_FUNC_VAR
541                 ${PROJECT_DIRECTORY}
542                 ${PROJECT_DIRECTORY}/CPACK/prog_test/prog_snprintf.c
543                 )
544         if(CMAKE_CROSSCOMPILING)
545                 #message("SNPRINTF_FUNC CROSSCOMPILING")
546                 set(RUN_SNPRINTF_FUNC "cross") 
547         endif(CMAKE_CROSSCOMPILING)
548
549         try_run(RUN_VSNPRINTF_FUNC_VAR COMPILE_VSNPRINTF_FUNC_VAR
550                 ${PROJECT_DIRECTORY}
551                 ${PROJECT_DIRECTORY}/CPACK/prog_test/prog_vsnprintf.c
552                 )
553         if(CMAKE_CROSSCOMPILING)
554                 #message("VSNPRINTF_FUNC CROSSCOMPILING")
555                 set(RUN_VSNPRINTF_FUNC "cross")
556         endif(CMAKE_CROSSCOMPILING)
557         set(PREFER_PORTABLE_SNPRINTF 0)
558         if(RUN_VSNPRINTF_FUNC_VAR MATCHES "FAILED_TO_RUN")
559                 set(PREFER_PORTABLE_SNPRINTF 1)
560         endif(RUN_VSNPRINTF_FUNC_VAR MATCHES "FAILED_TO_RUN")
561         if(RUN_SNPRINTF_FUNC_VAR MATCHES "FAILED_TO_RUN")
562                 set(PREFER_PORTABLE_SNPRINTF 1)
563         endif(RUN_SNPRINTF_FUNC_VAR MATCHES "FAILED_TO_RUN")
564         #message("PREFER_PORTABLE_SNPRINTF ${PREFER_PORTABLE_SNPRINTF}")
565 endif(HAVE_SNPRINTF AND HAVE_VSNPRINTF)
566
567 ### check for asprintf function familly
568 CHECK_FUNCTION_EXISTS(asprintf HAVE_ASPRINTF)
569 if(HAVE_ASPRINTF)
570         SET(need_asprintf "")
571 else(HAVE_ASPRINTF)
572         SET(need_asprintf "#define SIMGRID_NEED_ASPRINTF 1")
573 endif(HAVE_ASPRINTF)
574 CHECK_FUNCTION_EXISTS(vasprintf HAVE_VASPRINTF)
575 if(HAVE_VASPRINTF)
576         SET(need_vasprintf "")
577 else(HAVE_VASPRINTF)
578         SET(need_vasprintf "#define SIMGRID_NEED_VASPRINTF 1")
579 endif(HAVE_VASPRINTF)
580
581 ### check for addr2line
582
583 find_path(ADDR2LINE NAMES addr2line     PATHS NO_DEFAULT_PATHS  )
584 if(ADDR2LINE)
585 set(ADDR2LINE "${ADDR2LINE}/addr2line")
586 endif(ADDR2LINE)
587 find_program(ADDR2LINE NAMES addr2line)
588
589 ### check for include files and fct
590 CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
591 CHECK_INCLUDE_FILE(inttypes.h HAVE_INTTYPES_H)
592 CHECK_INCLUDE_FILE(memory.h HAVE_MEMORY_H)
593 CHECK_INCLUDE_FILE(stdlib.h HAVE_STDLIB_H)
594 CHECK_INCLUDE_FILE(strings.h HAVE_STRINGS_H)
595 CHECK_INCLUDE_FILE(string.h HAVE_STRING_H)
596
597 ### File to create
598
599 configure_file(${PROJECT_DIRECTORY}/src/context_sysv_config.h.in ${PROJECT_DIRECTORY}/src/context_sysv_config.h)
600
601 SET( CMAKEDEFINE "#cmakedefine" )
602 configure_file("${PROJECT_DIRECTORY}/CPACK/src/gras_config.h.in" "${PROJECT_DIRECTORY}/CPACK/src/tmp_gras_config.h.in" @ONLY IMMEDIATE)
603 configure_file("${PROJECT_DIRECTORY}/CPACK/src/tmp_gras_config.h.in" "${PROJECT_DIRECTORY}/src/gras_config.h" @ONLY IMMEDIATE)
604 configure_file(${PROJECT_DIRECTORY}/include/simgrid_config.h.in ${PROJECT_DIRECTORY}/include/simgrid_config.h)
605
606 if(NOT prefix)
607         set(prefix /usr/local)
608 endif(NOT prefix)
609 set(exec_prefix ${prefix})
610 set(top_srcdir ${PROJECT_DIRECTORY})
611 set(includedir ${prefix}/include)
612 set(top_builddir ${PROJECT_DIRECTORY})
613 set(libdir ${exec_prefix}/lib)
614 configure_file(${PROJECT_DIRECTORY}/CPACK/src/smpicc.in ${PROJECT_DIRECTORY}/src/smpi/smpicc @ONLY)
615 configure_file(${PROJECT_DIRECTORY}/CPACK/src/smpirun.in ${PROJECT_DIRECTORY}/src/smpi/smpirun @ONLY)
616
617
618 #message("__END_GRAS_&_SIMGRID____\n")