Logo AND Algorithmique Numérique Distribuée

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