Logo AND Algorithmique Numérique Distribuée

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