Logo AND Algorithmique Numérique Distribuée

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