Logo AND Algorithmique Numérique Distribuée

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