Logo AND Algorithmique Numérique Distribuée

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