Logo AND Algorithmique Numérique Distribuée

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