Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
8fe7fcf7b6f0c945861821509bc98cd0df32498d
[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 if(NOT disable_lua)
202         if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
203                 CHECK_INCLUDE_FILE(lualib.h HAVE_LUA5_1_LUALIB_H)
204         elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
205                 CHECK_INCLUDE_FILE(lua5.1/lualib.h HAVE_LUA5_1_LUALIB_H)
206         endif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
207         #message("HAVE_LUA5_1_LUALIB_H ${HAVE_LUA5_1_LUALIB_H}")
208         if(HAVE_LUA5_1_LUALIB_H)
209                 set(HAVE_LUA 1)
210         endif(HAVE_LUA5_1_LUALIB_H)
211 endif(NOT disable_lua)
212 #message("HAVE_LUA ${HAVE_LUA}")
213
214 #message("______END_CONTEXT______")
215
216 ###############
217 ## SVN version check
218 ##
219 #message("\n__________SVN__________")
220 if(IS_DIRECTORY ${PROJECT_DIRECTORY}/.svn)
221         #exec_program("svn up ${PROJECT_DIRECTORY}")
222         find_file(SVN ".svn" ${PROJECT_DIRECTORY})
223         exec_program("svnversion ${PROJECT_DIRECTORY}" OUTPUT_VARIABLE "SVN_VERSION")
224         #message("SVN_VERSION ${SVN_VERSION}")
225 endif(IS_DIRECTORY ${PROJECT_DIRECTORY}/.svn)
226
227 if(IS_DIRECTORY ${PROJECT_DIRECTORY}/.git)
228         find_file(GIT ".git" ${PROJECT_DIRECTORY})
229         exec_program("git --git-dir=${PROJECT_DIRECTORY} log --oneline -1 | sed 's| .*||'" OUTPUT_VARIABLE "GIT_VERSION")
230         #message("GIT_VERSION ${GIT_VERSION}")
231 endif(IS_DIRECTORY ${PROJECT_DIRECTORY}/.git)
232 #message("________END_SVN________\n")
233
234 #message("\n_____GRAS_&_SIMGRID____")
235 ###################################
236 ## SimGrid and GRAS specific checks
237 ##
238 include(TestBigEndian)
239 TEST_BIG_ENDIAN(BIGENDIAN)
240 # Check architecture signature begin
241 try_run(RUN_GRAS_VAR COMPILE_GRAS_VAR
242         ${PROJECT_DIRECTORY}
243         ${PROJECT_DIRECTORY}/buildtools/Cmake/prog_test/prog_GRAS_ARCH.c
244         RUN_OUTPUT_VARIABLE var1
245         )
246 if(BIGENDIAN)
247 set(val_big "B${var1}")
248 set(GRAS_BIGENDIAN 1)
249 else(BIGENDIAN)
250 set(val_big "l${var1}")
251 set(GRAS_BIGENDIAN 0)
252 endif(BIGENDIAN)
253 #message("GRAS_BIGENDIAN ${GRAS_BIGENDIAN}")
254 #message("${val_big}")
255
256 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:")
257         #message("gras_arch=0; gras_size=32; gras_arch_name=little32_1;")
258         SET(GRAS_ARCH_32_BITS 1)
259         SET(GRAS_THISARCH 0)
260 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:")
261 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:")
262         #message("gras_arch=1; gras_size=32; gras_arch_name=little32_2;")
263         SET(GRAS_ARCH_32_BITS 1)
264         SET(GRAS_THISARCH 1)
265 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:")
266 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:") 
267         #message("gras_arch=2; gras_size=32; gras_arch_name=little32_4;")
268         SET(GRAS_ARCH_32_BITS 1)
269         SET(GRAS_THISARCH 2)
270 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:")
271 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:") 
272         #message("gras_arch=3; gras_size=32; gras_arch_name=little32_8;")
273         SET(GRAS_ARCH_32_BITS 1)
274         SET(GRAS_THISARCH 3)
275 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:") 
276 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:") 
277         #message("gras_arch=4; gras_size=64; gras_arch_name=little64;")
278         SET(GRAS_ARCH_32_BITS 0)
279         SET(GRAS_THISARCH 4)
280 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:")
281
282 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:") 
283         #message("gras_arch=5; gras_size=32; gras_arch_name=big32;")
284         SET(GRAS_ARCH_32_BITS 1)
285         SET(GRAS_THISARCH 5)
286 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:")
287 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:") 
288         #message("gras_arch=6; gras_size=32; gras_arch_name=big32_8_4;")
289         SET(GRAS_ARCH_32_BITS 1)
290         SET(GRAS_THISARCH 6)
291 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:")
292 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:") 
293         #message("gras_arch=7; gras_size=32; gras_arch_name=big32_4;")
294         SET(GRAS_ARCH_32_BITS 1)
295         SET(GRAS_THISARCH 7)
296 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:")
297 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:") 
298         #message("gras_arch=8; gras_size=32; gras_arch_name=big32_2;")
299         SET(GRAS_ARCH_32_BITS 1)
300         SET(GRAS_THISARCH 8)
301 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:") 
302 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:") 
303         #message("gras_arch=9; gras_size=64; gras_arch_name=big64;")
304         SET(GRAS_ARCH_32_BITS 0)
305         SET(GRAS_THISARCH 9)
306 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:")
307 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:") 
308         #message("gras_arch=10;gras_size=64; gras_arch_name=big64_8_4;")
309         SET(GRAS_ARCH_32_BITS 0)
310         SET(GRAS_THISARCH 10)
311 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:") 
312         #message("GRAS_ARCH_32_BITS ${GRAS_ARCH_32_BITS}")
313
314
315 # Check architecture signature end
316 try_run(RUN_GRAS_VAR COMPILE_GRAS_VAR
317         ${PROJECT_DIRECTORY}
318         ${PROJECT_DIRECTORY}/buildtools/Cmake/prog_test/prog_GRAS_CHECK_STRUCT_COMPACTION.c
319         RUN_OUTPUT_VARIABLE var2
320         )
321 separate_arguments(var2)
322 foreach(var_tmp ${var2})
323         set(${var_tmp} 1)
324         #message("${var_tmp} ${${var_tmp}}")
325 endforeach(var_tmp ${var2})
326
327 # Check for [SIZEOF_MAX]
328 try_run(RUN_SM_VAR COMPILE_SM_VAR
329         ${PROJECT_DIRECTORY}
330         ${PROJECT_DIRECTORY}/buildtools/Cmake/prog_test/prog_max_size.c
331         RUN_OUTPUT_VARIABLE var3
332         )
333 SET(SIZEOF_MAX ${var3})
334 #message("SIZEOF_MAX ${SIZEOF_MAX}")
335
336
337 #--------------------------------------------------------------------------------------------------
338
339
340 CHECK_FUNCTION_EXISTS(makecontext HAVE_MAKECONTEXT)
341 #message("HAVE_MAKECONTEXT ${HAVE_MAKECONTEXT}")
342 set(makecontext_CPPFLAGS_2 "")
343 if(HAVE_MAKECONTEXT)
344         set(makecontext_CPPFLAGS "-DTEST_makecontext")
345         if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
346                 set(makecontext_CPPFLAGS_2 "-DOSX")
347                 #message("SYSTEM OSX")
348         endif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
349
350         try_run(RUN_makecontext_VAR COMPILE_makecontext_VAR
351                 ${PROJECT_DIRECTORY}
352                 ${PROJECT_DIRECTORY}/buildtools/Cmake/prog_test/prog_stacksetup.c
353                 COMPILE_DEFINITIONS "${makecontext_CPPFLAGS} ${makecontext_CPPFLAGS_2}"
354                 )
355         
356
357         exec_program("${SED_EXE}" ARGS "-e 's;,.*$;;' ${PROJECT_DIRECTORY}/conftestval" OUTPUT_VARIABLE "makecontext_addr")
358         exec_program("${SED_EXE}" ARGS "-e 's;^.*,;;' ${PROJECT_DIRECTORY}/conftestval" OUTPUT_VARIABLE "makecontext_size")
359         message("${makecontext_addr}")
360         message("${makecontext_size}")
361         set(pth_skaddr_makecontext "#define pth_skaddr_makecontext(skaddr,sksize) (${makecontext_addr})")
362         set(pth_sksize_makecontext "#define pth_sksize_makecontext(skaddr,sksize) (${makecontext_size})")
363
364 endif(HAVE_MAKECONTEXT)
365
366 #--------------------------------------------------------------------------------------------------
367
368 ### check for stackgrowth
369
370         try_run(RUN_makecontext_VAR COMPILE_makecontext_VAR
371                 ${PROJECT_DIRECTORY}
372                 ${PROJECT_DIRECTORY}/buildtools/Cmake/prog_test/prog_stackgrowth.c
373                 )
374 file(READ "${PROJECT_DIRECTORY}/conftestval" stack)
375 if(stack MATCHES "down")
376         set(PTH_STACKGROWTH "-1")
377 endif(stack MATCHES "down")
378 if(stack MATCHES "up")
379         set(PTH_STACKGROWTH "1")
380 endif(stack MATCHES "up")
381 #message("PTH_STACKGROWTH ${PTH_STACKGROWTH}")
382
383
384 ###############
385 ## System checks
386 ##
387
388 #SG_CONFIGURE_PART([System checks...])
389 #AC_PROG_CC(xlC gcc cc) -auto
390 #AM_SANITY_CHECK -auto
391
392 #AC_PROG_MAKE_SET
393
394
395 #AC_PRINTF_NULL
396 try_run(RUN_PRINTF_NULL_VAR COMPILE_PRINTF_NULL_VAR
397         ${PROJECT_DIRECTORY}
398         ${PROJECT_DIRECTORY}/buildtools/Cmake/prog_test/prog_printf_null.c
399         )
400
401 if(RUN_PRINTF_NULL_VAR MATCHES "FAILED_TO_RUN")
402 SET(PRINTF_NULL_WORKING "0")
403 else(RUN_PRINTF_NULL_VAR MATCHES "FAILED_TO_RUN")
404 SET(PRINTF_NULL_WORKING "1")
405 endif(RUN_PRINTF_NULL_VAR MATCHES "FAILED_TO_RUN")
406 #message("PRINTF_NULL_WORKING ${PRINTF_NULL_WORKING}")
407
408 #AC_CHECK_VA_COPY
409
410 set(diff_va "va_copy((d),(s))"
411 "VA_COPY((d),(s))"
412 "__va_copy((d),(s))"
413 "__builtin_va_copy((d),(s))"
414 "do { (d) = (s)\; } while (0)"
415 "do { *(d) = *(s)\; } while (0)"
416 "memcpy((void *)&(d), (void *)&(s)), sizeof((s))"
417 "memcpy((void *)(d), (void *)(s)), sizeof(*(s))"
418 )
419
420 foreach(fct ${diff_va})
421         write_file("${PROJECT_DIRECTORY}/buildtools/Cmake/prog_test/prog_va_copy.c" "#include <stdlib.h>
422         #include <stdarg.h>
423         #include <string.h>
424         #define DO_VA_COPY(d,s) ${fct}
425         void test(char *str, ...)
426         {
427             va_list ap, ap2;
428             int i;
429             va_start(ap, str);
430             DO_VA_COPY(ap2, ap);
431             for (i = 1; i <= 9; i++) {
432                 int k = (int)va_arg(ap, int);
433                 if (k != i)
434                     abort();
435             }
436             DO_VA_COPY(ap, ap2);
437             for (i = 1; i <= 9; i++) {
438                 int k = (int)va_arg(ap, int);
439                 if (k != i)
440                     abort();
441             }
442             va_end(ap);
443         }
444         int main(int argc, char *argv[])
445         {
446             test("test", 1, 2, 3, 4, 5, 6, 7, 8, 9);
447             exit(0);
448         }"
449         )
450         try_run(RUN_VA_NULL_VAR COMPILE_VA_NULL_VAR
451         ${PROJECT_DIRECTORY}
452         ${PROJECT_DIRECTORY}/buildtools/Cmake/prog_test/prog_va_copy.c
453         )
454         if(RUN_VA_NULL_VAR MATCHES "FAILED_TO_RUN")
455         else(RUN_VA_NULL_VAR MATCHES "FAILED_TO_RUN")   
456
457                 string(REGEX REPLACE "\;" "" fctbis ${fct})
458
459                 if(${fctbis} STREQUAL "va_copy((d),(s))")
460                         set(HAVE_VA_COPY 1)
461                         #message("HAVE_VA_COPY ${HAVE_VA_COPY}")
462                         set(ac_cv_va_copy "C99")
463                         set(__VA_COPY_USE_C99 "va_copy((d),(s))")       
464                 endif(${fctbis} STREQUAL "va_copy((d),(s))")
465
466                 if(${fctbis} STREQUAL "VA_COPY((d),(s))")
467                         set(ac_cv_va_copy "GCM")
468                         set(__VA_COPY_USE_GCM "VA_COPY((d),(s))")
469                 endif(${fctbis} STREQUAL "VA_COPY((d),(s))")
470
471                 if(${fctbis} STREQUAL "__va_copy((d),(s))")
472                         set(ac_cv_va_copy "GCH")
473                         set(__VA_COPY_USE_GCH "__va_copy((d),(s))")
474                 endif(${fctbis} STREQUAL "__va_copy((d),(s))")
475
476                 if(${fctbis} STREQUAL "__builtin_va_copy((d),(s))")
477                         set(ac_cv_va_copy "GCB")
478                         set(__VA_COPY_USE_GCB "__builtin_va_copy((d),(s))")
479                 endif(${fctbis} STREQUAL "__builtin_va_copy((d),(s))")
480
481                 if(${fctbis} STREQUAL "do { (d) = (s) } while (0)")
482                         set(ac_cv_va_copy "ASS")
483                         set(__VA_COPY_USE_ASS "do { (d) = (s); } while (0)")
484                 endif(${fctbis} STREQUAL "do { (d) = (s) } while (0)")
485
486                 if(${fctbis} STREQUAL "do { *(d) = *(s) } while (0)")
487                         set(ac_cv_va_copy "ASP")
488                         set(__VA_COPY_USE_ASP "do { *(d) = *(s); } while (0)")
489                 endif(${fctbis} STREQUAL "do { *(d) = *(s) } while (0)")
490
491                 if(${fctbis} STREQUAL "memcpy((void *)&(d), (void *)&(s)), sizeof((s))")
492                         set(ac_cv_va_copy "CPS")
493                         set(__VA_COPY_USE_CPS "memcpy((void *)&(d), (void *)&(s)), sizeof((s))")
494                 endif(${fctbis} STREQUAL "memcpy((void *)&(d), (void *)&(s)), sizeof((s))")
495
496                 if(${fctbis} STREQUAL "memcpy((void *)(d), (void *)(s)), sizeof(*(s))")
497                         set(ac_cv_va_copy "CPP")
498                         set(__VA_COPY_USE_CPP "memcpy((void *)(d), (void *)(s)), sizeof(*(s))")
499                 endif(${fctbis} STREQUAL "memcpy((void *)(d), (void *)(s)), sizeof(*(s))")
500                                 
501                 if(NOT STATUS_OK)
502                 set(__VA_COPY_USE "__VA_COPY_USE_${ac_cv_va_copy}")
503                 #message("__VA_COPY_USE VA_COPY_USE_${ac_cv_va_copy}")
504                 endif(NOT STATUS_OK)
505                 #message("__VA_COPY_USE_${ac_cv_va_copy} ${fctbis}")
506                 set(STATUS_OK "1")
507
508         endif(RUN_VA_NULL_VAR MATCHES "FAILED_TO_RUN")
509 endforeach(fct ${diff_va})
510
511 # Checks for header files.
512
513 CHECK_INCLUDE_FILES("stdlib.h;stdarg.h;string.h;float.h" STDC_HEADERS)
514 #message("STDC_HEADERS ${STDC_HEADERS}")
515 CHECK_INCLUDE_FILES("time.h;sys/time.h" TIME_WITH_SYS_TIME)
516 #message("TIME_WITH_SYS_TIME ${TIME_WITH_SYS_TIME}")
517
518 CHECK_INCLUDE_FILE(sys/socket.h HAVE_SYS_SOCKET_H)
519 #message("HAVE_SOCKET_H ${HAVE_SOCKET_H}")
520 CHECK_INCLUDE_FILE(sys/stat.h HAVE_SYS_STAT_H)
521 #message("HAVE_STAT_H ${HAVE_STAT_H}")
522 CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H)
523 #message("HAVE_WINDOWS_H ${HAVE_WINDOWS_H}")
524 CHECK_INCLUDE_FILE(winsock.h HAVE_WINSOCK_H)
525 #message("HAVE_WINSOCK_H ${HAVE_WINSOCK_H}")
526 CHECK_INCLUDE_FILE(winsock2.h HAVE_WINSOCK2_H)
527 #message("HAVE_WINSOCK2_H ${HAVE_WINSOCK2_H}")
528 CHECK_INCLUDE_FILE(sys/time.h HAVE_SYS_TIME_H)
529 #message("HAVE_TIME_H ${HAVE_TIME_H}")
530 CHECK_INCLUDE_FILE(errno.h HAVE_ERRNO_H)
531 #message("HAVE_ERRNO_H ${HAVE_ERRNO_H}")
532 CHECK_INCLUDE_FILE(unistd.h HAVE_UNISTD_H)
533 #message("HAVE_UNISTD_H ${HAVE_UNISTD_H}")
534 CHECK_INCLUDE_FILE(execinfo.h HAVE_EXECINFO_H)
535 #message("HAVE_EXECINFO_H ${HAVE_EXECINFO_H}")
536 CHECK_INCLUDE_FILE(signal.h HAVE_SIGNAL_H)
537 #message("HAVE_SIGNAL_H ${HAVE_SIGNAL_H}")
538
539 CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
540 #message("HAVE_GETTIMEOFDAY ${HAVE_GETTIMEOFDAY}")
541 CHECK_FUNCTION_EXISTS(usleep HAVE_USLEEP)
542 #message("HAVE_USLEEP ${HAVE_USLEEP}")
543 CHECK_FUNCTION_EXISTS(getdtablesize HAVE_GETDTABLESIZE)
544 #message("HAVE_GETDTABLESIZE ${HAVE_GETDTABLESIZE}")
545 CHECK_FUNCTION_EXISTS(sysconf HAVE_SYSCONF)
546 #message("HAVE_SYSCONF ${HAVE_SYSCONF}")
547 CHECK_FUNCTION_EXISTS(readv HAVE_READV)
548 #message("HAVE_READV ${HAVE_READV}")
549 CHECK_FUNCTION_EXISTS(popen HAVE_POPEN)
550 #message("HAVE_POPEN ${HAVE_POPEN}")
551 CHECK_FUNCTION_EXISTS(signal HAVE_SIGNAL)
552 #message("HAVE_SIGNAL ${HAVE_SIGNAL}")
553
554 #--------------------------------------------------------------------------------------------------
555 ### Try execut getline command
556 try_run(RUN_RESULT_VAR COMPILE_RESULT_VAR
557         ${PROJECT_DIRECTORY}
558         ${PROJECT_DIRECTORY}/buildtools/Cmake/prog_test/prog_getline.c
559         OUTPUT_VARIABLE GETLINE_OUTPUT
560         )
561
562 if(NOT COMPILE_RESULT_VAR)
563 SET(need_getline "#define SIMGRID_NEED_GETLINE 1")
564 else(NOT COMPILE_RESULT_VAR)
565 SET(need_getline "")
566 endif(NOT COMPILE_RESULT_VAR)
567
568 ### check for a working snprintf
569 CHECK_FUNCTION_EXISTS(snprintf HAVE_SNPRINTF)
570 CHECK_FUNCTION_EXISTS(vsnprintf HAVE_VSNPRINTF)
571 if(HAVE_SNPRINTF AND HAVE_VSNPRINTF)
572
573         try_run(RUN_SNPRINTF_FUNC_VAR COMPILE_SNPRINTF_FUNC_VAR
574                 ${PROJECT_DIRECTORY}
575                 ${PROJECT_DIRECTORY}/buildtools/Cmake/prog_test/prog_snprintf.c
576                 )
577         if(CMAKE_CROSSCOMPILING)
578                 #message("SNPRINTF_FUNC CROSSCOMPILING")
579                 set(RUN_SNPRINTF_FUNC "cross") 
580         endif(CMAKE_CROSSCOMPILING)
581
582         try_run(RUN_VSNPRINTF_FUNC_VAR COMPILE_VSNPRINTF_FUNC_VAR
583                 ${PROJECT_DIRECTORY}
584                 ${PROJECT_DIRECTORY}/buildtools/Cmake/prog_test/prog_vsnprintf.c
585                 )
586         if(CMAKE_CROSSCOMPILING)
587                 #message("VSNPRINTF_FUNC CROSSCOMPILING")
588                 set(RUN_VSNPRINTF_FUNC "cross")
589         endif(CMAKE_CROSSCOMPILING)
590         set(PREFER_PORTABLE_SNPRINTF 0)
591         if(RUN_VSNPRINTF_FUNC_VAR MATCHES "FAILED_TO_RUN")
592                 set(PREFER_PORTABLE_SNPRINTF 1)
593         endif(RUN_VSNPRINTF_FUNC_VAR MATCHES "FAILED_TO_RUN")
594         if(RUN_SNPRINTF_FUNC_VAR MATCHES "FAILED_TO_RUN")
595                 set(PREFER_PORTABLE_SNPRINTF 1)
596         endif(RUN_SNPRINTF_FUNC_VAR MATCHES "FAILED_TO_RUN")
597         #message("PREFER_PORTABLE_SNPRINTF ${PREFER_PORTABLE_SNPRINTF}")
598 endif(HAVE_SNPRINTF AND HAVE_VSNPRINTF)
599
600 ### check for asprintf function familly
601 CHECK_FUNCTION_EXISTS(asprintf HAVE_ASPRINTF)
602 if(HAVE_ASPRINTF)
603         SET(need_asprintf "")
604 else(HAVE_ASPRINTF)
605         SET(need_asprintf "#define SIMGRID_NEED_ASPRINTF 1")
606 endif(HAVE_ASPRINTF)
607 CHECK_FUNCTION_EXISTS(vasprintf HAVE_VASPRINTF)
608 if(HAVE_VASPRINTF)
609         SET(need_vasprintf "")
610 else(HAVE_VASPRINTF)
611         SET(need_vasprintf "#define SIMGRID_NEED_VASPRINTF 1")
612 endif(HAVE_VASPRINTF)
613
614 ### check for addr2line
615
616 find_path(ADDR2LINE NAMES addr2line     PATHS NO_DEFAULT_PATHS  )
617 if(ADDR2LINE)
618 set(ADDR2LINE "${ADDR2LINE}/addr2line")
619 endif(ADDR2LINE)
620
621 ### check for include files and fct
622 CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
623 CHECK_INCLUDE_FILE(inttypes.h HAVE_INTTYPES_H)
624 CHECK_INCLUDE_FILE(memory.h HAVE_MEMORY_H)
625 CHECK_INCLUDE_FILE(stdlib.h HAVE_STDLIB_H)
626 CHECK_INCLUDE_FILE(strings.h HAVE_STRINGS_H)
627 CHECK_INCLUDE_FILE(string.h HAVE_STRING_H)
628
629 ### File to create
630
631 configure_file(${PROJECT_DIRECTORY}/src/context_sysv_config.h.in ${PROJECT_DIRECTORY}/src/context_sysv_config.h)
632
633 SET( CMAKEDEFINE "#cmakedefine" )
634 configure_file("${PROJECT_DIRECTORY}/buildtools/Cmake/src/gras_config.h.in" "${PROJECT_DIRECTORY}/buildtools/Cmake/src/tmp_gras_config.h.in" @ONLY IMMEDIATE)
635 configure_file("${PROJECT_DIRECTORY}/buildtools/Cmake/src/tmp_gras_config.h.in" "${PROJECT_DIRECTORY}/src/gras_config.h" @ONLY IMMEDIATE)
636 configure_file(${PROJECT_DIRECTORY}/include/simgrid_config.h.in ${PROJECT_DIRECTORY}/include/simgrid_config.h)
637
638 if(NOT prefix)
639         set(prefix /usr/local)
640 endif(NOT prefix)
641 set(exec_prefix ${prefix})
642 set(top_srcdir ${PROJECT_DIRECTORY})
643 set(includedir ${prefix}/include)
644 set(top_builddir ${PROJECT_DIRECTORY})
645 set(libdir ${exec_prefix}/lib)
646 configure_file(${PROJECT_DIRECTORY}/buildtools/Cmake/src/smpicc.in ${PROJECT_DIRECTORY}/src/smpi/smpicc @ONLY)
647 configure_file(${PROJECT_DIRECTORY}/buildtools/Cmake/src/smpirun.in ${PROJECT_DIRECTORY}/src/smpi/smpirun @ONLY)
648
649
650 #message("__END_GRAS_&_SIMGRID____\n")