Logo AND Algorithmique Numérique Distribuée

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