Logo AND Algorithmique Numérique Distribuée

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