Logo AND Algorithmique Numérique Distribuée

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