Logo AND Algorithmique Numérique Distribuée

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