Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
bc08f0106f49a4016fdb27d59d7a123a00993453
[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(enable_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(enable_ruby)
85
86 if(enable_tracing)
87         SET(HAVE_TRACING 1)
88 endif(enable_tracing)
89
90 #--------------------------------------------------------------------------------------------------
91 ### Initialize of CONTEXT JAVA
92 if(NOT enable_java)
93         SET(HAVE_JAVA 0)
94 else(NOT enable_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(NOT enable_java)
110
111 #--------------------------------------------------------------------------------------------------
112 ### Initialize of CONTEXT GTNETS
113 if(NOT enable_gtnets)
114         SET(HAVE_GTNETS 0)
115 else(NOT enable_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         else(COMPILE_GTNETS_VAR)
122                 SET(HAVE_GTNETS 1)
123                 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GTNETS_LDFLAGS} ${GTNETS_CPPFLAGS} ")
124                 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GTNETS_LDFLAGS} ${GTNETS_CPPFLAGS} ")
125         endif(COMPILE_GTNETS_VAR)
126 endif(NOT enable_gtnets)
127
128 #--------------------------------------------------------------------------------------------------
129 ### Initialize of CONTEXT THREADS
130
131 if(pthread)
132 set(pthread 1)
133 elseif(pthread)
134 set(pthread 0)
135 endif(pthread)
136
137 if(pthread)
138         ### HAVE_SEM_INIT
139         
140         if(HAVE_SEM_INIT_LIB)
141                 exec_program("${CMAKE_C_COMPILER} -lpthread ${PROJECT_DIRECTORY}/buildtools/Cmake/prog_test/prog_sem_init.c" OUTPUT_VARIABLE HAVE_SEM_INIT_run)
142                 if(HAVE_SEM_INIT_run)
143                         set(HAVE_SEM_INIT 0)
144                 else(HAVE_SEM_INIT_run)
145                         set(HAVE_SEM_INIT 1)
146                 endif(HAVE_SEM_INIT_run)
147         endif(HAVE_SEM_INIT_LIB)
148
149         ### HAVE_SEM_TIMEDWAIT
150
151         if(HAVE_SEM_TIMEDWAIT_LIB)
152                 exec_program("${CMAKE_C_COMPILER} -lpthread ${PROJECT_DIRECTORY}/buildtools/Cmake/prog_test/prog_sem_timedwait.c" OUTPUT_VARIABLE HAVE_SEM_TIMEDWAIT_run)
153                 if(HAVE_SEM_TIMEDWAIT_run)
154                         set(HAVE_SEM_TIMEDWAIT 0)
155                 else(HAVE_SEM_TIMEDWAIT_run)
156                         set(HAVE_SEM_TIMEDWAIT 1)
157                 endif(HAVE_SEM_TIMEDWAIT_run)
158         endif(HAVE_SEM_TIMEDWAIT_LIB)
159
160         ### HAVE_MUTEX_TIMEDLOCK
161
162         if(HAVE_MUTEX_TIMEDLOCK_LIB)
163                 exec_program("${CMAKE_C_COMPILER} -lpthread ${PROJECT_DIRECTORY}/buildtools/Cmake/prog_test/prog_mutex_timedlock.c" OUTPUT_VARIABLE HAVE_SEM_TIMEDWAIT_run)
164                 if(HAVE_MUTEX_TIMEDLOCK_run)
165                         set(HAVE_MUTEX_TIMEDLOCK 0)
166                 else(HAVE_MUTEX_TIMEDLOCK_run)
167                         set(HAVE_MUTEX_TIMEDLOCK 1)
168                 endif(HAVE_MUTEX_TIMEDLOCK_run)
169         endif(HAVE_MUTEX_TIMEDLOCK_LIB)
170 endif(pthread)
171
172 # AC_CHECK_MCSC(mcsc=yes, mcsc=no) 
173 set(mcsc_flags "")
174 if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
175         set(mcsc_flags "-D_XOPEN_SOURCE")
176 endif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
177
178 try_run(RUN_mcsc_VAR COMPILE_mcsc_VAR
179         ${PROJECT_DIRECTORY}
180         ${PROJECT_DIRECTORY}/buildtools/Cmake/prog_test/prog_AC_CHECK_MCSC.c
181         COMPILE_DEFINITIONS "${mcsc_flags}"
182         )
183 file(READ "${Project_BINARY_DIR}/conftestval" mcsc)
184 STRING(REPLACE "\n" "" mcsc ${mcsc})
185 if(mcsc)
186         set(mcsc "yes")
187 elseif(mcsc)
188         set(mcsc "no")
189 endif(mcsc)
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)
226                 set(CONTEXT_UCONTEXT 1)
227         else(mcsc)
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)
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(enable_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(enable_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         message("SVN_VERSION : ${SVN_VERSION}")
317 endif(IS_DIRECTORY ${PROJECT_DIRECTORY}/.svn)
318
319 if(IS_DIRECTORY ${PROJECT_DIRECTORY}/.git)
320         find_file(GIT ".git" ${PROJECT_DIRECTORY})
321         exec_program("git --git-dir=${PROJECT_DIRECTORY}/.git log --oneline -1 | sed 's| .*||'" OUTPUT_VARIABLE "GIT_VERSION")
322         exec_program("git --git-dir=${PROJECT_DIRECTORY}/.git log -n 1 --format=%ai ." OUTPUT_VARIABLE "GIT_DATE")
323         exec_program("git svn info" ${PROJECT_DIRECTORY} OUTPUT_VARIABLE "GIT_SVN_VERSION")
324         string(REPLACE "\n" ";" GIT_SVN_VERSION ${GIT_SVN_VERSION})
325         STRING(REPLACE " +0000" "" GIT_DATE ${GIT_DATE})
326         STRING(REPLACE " " "~" GIT_DATE ${GIT_DATE})
327         STRING(REPLACE ":" "-" GIT_DATE ${GIT_DATE})
328         message("GIT_DATE       : ${GIT_DATE}")
329         message("GIT_VERSION    : ${GIT_VERSION}")
330         foreach(line ${GIT_SVN_VERSION})
331                 string(REGEX MATCH "^Revision:.*" line_good ${line})
332                 if(line_good)
333                         string(REPLACE "Revision: " "" line_good ${line_good})
334                         set(SVN_VERSION ${line_good})
335                 endif(line_good)
336         endforeach(line ${GIT_SVN_VERSION})
337         message("GIT_SVN_VERSION : ${SVN_VERSION}")
338 endif(IS_DIRECTORY ${PROJECT_DIRECTORY}/.git)
339
340 ###################################
341 ## SimGrid and GRAS specific checks
342 ##
343 include(TestBigEndian)
344 TEST_BIG_ENDIAN(BIGENDIAN)
345 # Check architecture signature begin
346 try_run(RUN_GRAS_VAR COMPILE_GRAS_VAR
347         ${PROJECT_DIRECTORY}
348         ${PROJECT_DIRECTORY}/buildtools/Cmake/prog_test/prog_GRAS_ARCH.c
349         RUN_OUTPUT_VARIABLE var1
350         )
351 if(BIGENDIAN)
352 set(val_big "B${var1}")
353 set(GRAS_BIGENDIAN 1)
354 else(BIGENDIAN)
355 set(val_big "l${var1}")
356 set(GRAS_BIGENDIAN 0)
357 endif(BIGENDIAN)
358
359 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:")
360         #gras_arch=0; gras_size=32; gras_arch_name=little32_1;
361         SET(GRAS_ARCH_32_BITS 1)
362         SET(GRAS_THISARCH 0)
363 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:")
364 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:")
365         #gras_arch=1; gras_size=32; gras_arch_name=little32_2;
366         SET(GRAS_ARCH_32_BITS 1)
367         SET(GRAS_THISARCH 1)
368 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:")
369 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:") 
370         #gras_arch=2; gras_size=32; gras_arch_name=little32_4;
371         SET(GRAS_ARCH_32_BITS 1)
372         SET(GRAS_THISARCH 2)
373 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:")
374 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:") 
375         #gras_arch=3; gras_size=32; gras_arch_name=little32_8;
376         SET(GRAS_ARCH_32_BITS 1)
377         SET(GRAS_THISARCH 3)
378 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:") 
379 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:") 
380         #gras_arch=4; gras_size=64; gras_arch_name=little64;
381         SET(GRAS_ARCH_32_BITS 0)
382         SET(GRAS_THISARCH 4)
383 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:")
384
385 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:") 
386         #gras_arch=5; gras_size=32; gras_arch_name=big32;
387         SET(GRAS_ARCH_32_BITS 1)
388         SET(GRAS_THISARCH 5)
389 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:")
390 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:") 
391         #gras_arch=6; gras_size=32; gras_arch_name=big32_8_4;
392         SET(GRAS_ARCH_32_BITS 1)
393         SET(GRAS_THISARCH 6)
394 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:")
395 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:") 
396         #gras_arch=7; gras_size=32; gras_arch_name=big32_4;
397         SET(GRAS_ARCH_32_BITS 1)
398         SET(GRAS_THISARCH 7)
399 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:")
400 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:") 
401         #gras_arch=8; gras_size=32; gras_arch_name=big32_2;
402         SET(GRAS_ARCH_32_BITS 1)
403         SET(GRAS_THISARCH 8)
404 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:") 
405 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:") 
406         #gras_arch=9; gras_size=64; gras_arch_name=big64;
407         SET(GRAS_ARCH_32_BITS 0)
408         SET(GRAS_THISARCH 9)
409 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:")
410 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:") 
411         #gras_arch=10;gras_size=64; gras_arch_name=big64_8_4;
412         SET(GRAS_ARCH_32_BITS 0)
413         SET(GRAS_THISARCH 10)
414 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:") 
415
416
417 # Check architecture signature end
418 try_run(RUN_GRAS_VAR COMPILE_GRAS_VAR
419         ${PROJECT_DIRECTORY}
420         ${PROJECT_DIRECTORY}/buildtools/Cmake/prog_test/prog_GRAS_CHECK_STRUCT_COMPACTION.c
421         RUN_OUTPUT_VARIABLE var2
422         )
423 separate_arguments(var2)
424 foreach(var_tmp ${var2})
425         set(${var_tmp} 1)
426 endforeach(var_tmp ${var2})
427
428 # Check for [SIZEOF_MAX]
429 try_run(RUN_SM_VAR COMPILE_SM_VAR
430         ${PROJECT_DIRECTORY}
431         ${PROJECT_DIRECTORY}/buildtools/Cmake/prog_test/prog_max_size.c
432         RUN_OUTPUT_VARIABLE var3
433         )
434 SET(SIZEOF_MAX ${var3})
435
436 #--------------------------------------------------------------------------------------------------
437
438 set(makecontext_CPPFLAGS_2 "")
439 if(HAVE_MAKECONTEXT)
440         set(makecontext_CPPFLAGS "-DTEST_makecontext")
441         if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
442                 set(makecontext_CPPFLAGS_2 "-DOSX")
443         endif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
444
445         try_run(RUN_makecontext_VAR COMPILE_makecontext_VAR
446                 ${PROJECT_DIRECTORY}
447                 ${PROJECT_DIRECTORY}/buildtools/Cmake/prog_test/prog_stacksetup.c
448                 COMPILE_DEFINITIONS "${makecontext_CPPFLAGS} ${makecontext_CPPFLAGS_2}"
449                 )
450         
451         file(READ ${Project_BINARY_DIR}/conftestval MAKECONTEXT_ADDR_SIZE)
452         string(REPLACE "\n" "" MAKECONTEXT_ADDR_SIZE "${MAKECONTEXT_ADDR_SIZE}")
453         string(REGEX MATCH ;^.*,;MAKECONTEXT_ADDR "${MAKECONTEXT_ADDR_SIZE}")
454         string(REGEX MATCH ;,.*$; MAKECONTEXT_SIZE "${MAKECONTEXT_ADDR_SIZE}")
455         string(REPLACE "," "" makecontext_addr "${MAKECONTEXT_ADDR}")
456         string(REPLACE "," "" makecontext_size "${MAKECONTEXT_SIZE}")   
457         set(pth_skaddr_makecontext "#define pth_skaddr_makecontext(skaddr,sksize) (${makecontext_addr})")
458         set(pth_sksize_makecontext "#define pth_sksize_makecontext(skaddr,sksize) (${makecontext_size})")
459
460 endif(HAVE_MAKECONTEXT)
461
462 #--------------------------------------------------------------------------------------------------
463
464 ### check for stackgrowth
465
466         try_run(RUN_makecontext_VAR COMPILE_makecontext_VAR
467                 ${PROJECT_DIRECTORY}
468                 ${PROJECT_DIRECTORY}/buildtools/Cmake/prog_test/prog_stackgrowth.c
469                 )
470 file(READ "${Project_BINARY_DIR}/conftestval" stack)
471 if(stack MATCHES "down")
472         set(PTH_STACKGROWTH "-1")
473 endif(stack MATCHES "down")
474 if(stack MATCHES "up")
475         set(PTH_STACKGROWTH "1")
476 endif(stack MATCHES "up")
477
478 ###############
479 ## System checks
480 ##
481
482 #SG_CONFIGURE_PART([System checks...])
483 #AC_PROG_CC(xlC gcc cc) -auto
484 #AM_SANITY_CHECK -auto
485
486 #AC_PROG_MAKE_SET
487
488
489 #AC_PRINTF_NULL
490 try_run(RUN_PRINTF_NULL_VAR COMPILE_PRINTF_NULL_VAR
491         ${PROJECT_DIRECTORY}
492         ${PROJECT_DIRECTORY}/buildtools/Cmake/prog_test/prog_printf_null.c
493         )
494
495 if(RUN_PRINTF_NULL_VAR MATCHES "FAILED_TO_RUN")
496 SET(PRINTF_NULL_WORKING "0")
497 else(RUN_PRINTF_NULL_VAR MATCHES "FAILED_TO_RUN")
498 SET(PRINTF_NULL_WORKING "1")
499 endif(RUN_PRINTF_NULL_VAR MATCHES "FAILED_TO_RUN")
500
501 #AC_CHECK_VA_COPY
502
503 set(diff_va "va_copy((d),(s))"
504 "VA_COPY((d),(s))"
505 "__va_copy((d),(s))"
506 "__builtin_va_copy((d),(s))"
507 "do { (d) = (s)\; } while (0)"
508 "do { *(d) = *(s)\; } while (0)"
509 "memcpy((void *)&(d), (void *)&(s)), sizeof((s))"
510 "memcpy((void *)(d), (void *)(s)), sizeof(*(s))"
511 )
512
513 foreach(fct ${diff_va})
514         write_file("${PROJECT_DIRECTORY}/buildtools/Cmake/prog_test/prog_va_copy.c" "#include <stdlib.h>
515         #include <stdarg.h>
516         #include <string.h>
517         #define DO_VA_COPY(d,s) ${fct}
518         void test(char *str, ...)
519         {
520             va_list ap, ap2;
521             int i;
522             va_start(ap, str);
523             DO_VA_COPY(ap2, ap);
524             for (i = 1; i <= 9; i++) {
525                 int k = (int)va_arg(ap, int);
526                 if (k != i)
527                     abort();
528             }
529             DO_VA_COPY(ap, ap2);
530             for (i = 1; i <= 9; i++) {
531                 int k = (int)va_arg(ap, int);
532                 if (k != i)
533                     abort();
534             }
535             va_end(ap);
536         }
537         int main(int argc, char *argv[])
538         {
539             test("test", 1, 2, 3, 4, 5, 6, 7, 8, 9);
540             exit(0);
541         }"
542         )
543         try_run(RUN_VA_NULL_VAR COMPILE_VA_NULL_VAR
544         ${PROJECT_DIRECTORY}
545         ${PROJECT_DIRECTORY}/buildtools/Cmake/prog_test/prog_va_copy.c
546         )
547         if(RUN_VA_NULL_VAR MATCHES "FAILED_TO_RUN")
548         else(RUN_VA_NULL_VAR MATCHES "FAILED_TO_RUN")   
549
550                 string(REGEX REPLACE "\;" "" fctbis ${fct})
551
552                 if(${fctbis} STREQUAL "va_copy((d),(s))")
553                         set(HAVE_VA_COPY 1)
554                         set(ac_cv_va_copy "C99")
555                         set(__VA_COPY_USE_C99 "va_copy((d),(s))")       
556                 endif(${fctbis} STREQUAL "va_copy((d),(s))")
557
558                 if(${fctbis} STREQUAL "VA_COPY((d),(s))")
559                         set(ac_cv_va_copy "GCM")
560                         set(__VA_COPY_USE_GCM "VA_COPY((d),(s))")
561                 endif(${fctbis} STREQUAL "VA_COPY((d),(s))")
562
563                 if(${fctbis} STREQUAL "__va_copy((d),(s))")
564                         set(ac_cv_va_copy "GCH")
565                         set(__VA_COPY_USE_GCH "__va_copy((d),(s))")
566                 endif(${fctbis} STREQUAL "__va_copy((d),(s))")
567
568                 if(${fctbis} STREQUAL "__builtin_va_copy((d),(s))")
569                         set(ac_cv_va_copy "GCB")
570                         set(__VA_COPY_USE_GCB "__builtin_va_copy((d),(s))")
571                 endif(${fctbis} STREQUAL "__builtin_va_copy((d),(s))")
572
573                 if(${fctbis} STREQUAL "do { (d) = (s) } while (0)")
574                         set(ac_cv_va_copy "ASS")
575                         set(__VA_COPY_USE_ASS "do { (d) = (s); } while (0)")
576                 endif(${fctbis} STREQUAL "do { (d) = (s) } while (0)")
577
578                 if(${fctbis} STREQUAL "do { *(d) = *(s) } while (0)")
579                         set(ac_cv_va_copy "ASP")
580                         set(__VA_COPY_USE_ASP "do { *(d) = *(s); } while (0)")
581                 endif(${fctbis} STREQUAL "do { *(d) = *(s) } while (0)")
582
583                 if(${fctbis} STREQUAL "memcpy((void *)&(d), (void *)&(s)), sizeof((s))")
584                         set(ac_cv_va_copy "CPS")
585                         set(__VA_COPY_USE_CPS "memcpy((void *)&(d), (void *)&(s)), sizeof((s))")
586                 endif(${fctbis} STREQUAL "memcpy((void *)&(d), (void *)&(s)), sizeof((s))")
587
588                 if(${fctbis} STREQUAL "memcpy((void *)(d), (void *)(s)), sizeof(*(s))")
589                         set(ac_cv_va_copy "CPP")
590                         set(__VA_COPY_USE_CPP "memcpy((void *)(d), (void *)(s)), sizeof(*(s))")
591                 endif(${fctbis} STREQUAL "memcpy((void *)(d), (void *)(s)), sizeof(*(s))")
592                                 
593                 if(NOT STATUS_OK)
594                 set(__VA_COPY_USE "__VA_COPY_USE_${ac_cv_va_copy}")
595                 endif(NOT STATUS_OK)
596                 set(STATUS_OK "1")
597
598         endif(RUN_VA_NULL_VAR MATCHES "FAILED_TO_RUN")
599 endforeach(fct ${diff_va})
600
601 #--------------------------------------------------------------------------------------------------
602 ### Try execut getline command
603 try_run(RUN_RESULT_VAR COMPILE_RESULT_VAR
604         ${PROJECT_DIRECTORY}
605         ${PROJECT_DIRECTORY}/buildtools/Cmake/prog_test/prog_getline.c
606         OUTPUT_VARIABLE GETLINE_OUTPUT
607         )
608
609 if(NOT COMPILE_RESULT_VAR)
610 SET(need_getline "#define SIMGRID_NEED_GETLINE 1")
611 else(NOT COMPILE_RESULT_VAR)
612 SET(need_getline "")
613 endif(NOT COMPILE_RESULT_VAR)
614
615 ### check for a working snprintf
616 if(HAVE_SNPRINTF AND HAVE_VSNPRINTF)
617
618         try_run(RUN_SNPRINTF_FUNC_VAR COMPILE_SNPRINTF_FUNC_VAR
619                 ${PROJECT_DIRECTORY}
620                 ${PROJECT_DIRECTORY}/buildtools/Cmake/prog_test/prog_snprintf.c
621                 )
622         if(CMAKE_CROSSCOMPILING)
623                 set(RUN_SNPRINTF_FUNC "cross") 
624         endif(CMAKE_CROSSCOMPILING)
625
626         try_run(RUN_VSNPRINTF_FUNC_VAR COMPILE_VSNPRINTF_FUNC_VAR
627                 ${PROJECT_DIRECTORY}
628                 ${PROJECT_DIRECTORY}/buildtools/Cmake/prog_test/prog_vsnprintf.c
629                 )
630         if(CMAKE_CROSSCOMPILING)
631                 set(RUN_VSNPRINTF_FUNC "cross")
632         endif(CMAKE_CROSSCOMPILING)
633         set(PREFER_PORTABLE_SNPRINTF 0)
634         if(RUN_VSNPRINTF_FUNC_VAR MATCHES "FAILED_TO_RUN")
635                 set(PREFER_PORTABLE_SNPRINTF 1)
636         endif(RUN_VSNPRINTF_FUNC_VAR MATCHES "FAILED_TO_RUN")
637         if(RUN_SNPRINTF_FUNC_VAR MATCHES "FAILED_TO_RUN")
638                 set(PREFER_PORTABLE_SNPRINTF 1)
639         endif(RUN_SNPRINTF_FUNC_VAR MATCHES "FAILED_TO_RUN")
640 endif(HAVE_SNPRINTF AND HAVE_VSNPRINTF)
641
642 ### check for asprintf function familly
643 if(HAVE_ASPRINTF)
644         SET(need_asprintf "")
645 else(HAVE_ASPRINTF)
646         SET(need_asprintf "#define SIMGRID_NEED_ASPRINTF 1")
647 endif(HAVE_ASPRINTF)
648
649 if(HAVE_VASPRINTF)
650         SET(need_vasprintf "")
651 else(HAVE_VASPRINTF)
652         SET(need_vasprintf "#define SIMGRID_NEED_VASPRINTF 1")
653 endif(HAVE_VASPRINTF)
654
655 ### check for addr2line
656
657 find_path(ADDR2LINE NAMES addr2line     PATHS NO_DEFAULT_PATHS  )
658 if(ADDR2LINE)
659 set(ADDR2LINE "${ADDR2LINE}/addr2line")
660 endif(ADDR2LINE)
661
662 ### File to create
663
664 configure_file(${PROJECT_DIRECTORY}/src/context_sysv_config.h.in ${PROJECT_DIRECTORY}/src/context_sysv_config.h)
665
666 SET( CMAKEDEFINE "#cmakedefine" )
667 configure_file("${PROJECT_DIRECTORY}/buildtools/Cmake/src/c_gras_config.h.in" "${PROJECT_DIRECTORY}/buildtools/Cmake/src/tmp_gras_config.h.in" @ONLY IMMEDIATE)
668 configure_file("${PROJECT_DIRECTORY}/buildtools/Cmake/src/tmp_gras_config.h.in" "${PROJECT_DIRECTORY}/src/gras_config.h" @ONLY IMMEDIATE)
669 configure_file(${PROJECT_DIRECTORY}/include/simgrid_config.h.in ${PROJECT_DIRECTORY}/include/simgrid_config.h)
670 configure_file("${PROJECT_DIRECTORY}/buildtools/Cmake/src/tracing_config.h.in" "${PROJECT_DIRECTORY}/buildtools/Cmake/src/tmp_tracing_config.h.in" @ONLY IMMEDIATE)
671 configure_file("${PROJECT_DIRECTORY}/buildtools/Cmake/src/tmp_tracing_config.h.in" "${PROJECT_DIRECTORY}/include/instr/tracing_config.h" @ONLY IMMEDIATE)
672
673 if(NOT prefix)
674         set(prefix /usr/local)
675 endif(NOT prefix)
676
677 set(top_srcdir "${PROJECT_DIRECTORY}")
678 set(srcdir "${PROJECT_DIRECTORY}/src")
679
680 set(exec_prefix ${prefix})
681 set(includedir ${prefix}/include)
682 set(top_builddir ${PROJECT_DIRECTORY})
683 set(libdir ${exec_prefix}/lib)
684
685 configure_file(${PROJECT_DIRECTORY}/src/smpi/smpicc.in  ${PROJECT_DIRECTORY}/src/smpi/smpicc @ONLY)
686 configure_file(${PROJECT_DIRECTORY}/src/smpi/smpirun.in ${PROJECT_DIRECTORY}/src/smpi/smpirun @ONLY)
687
688 exec_program("chmod a=rwx ${PROJECT_DIRECTORY}/src/smpi/smpicc" OUTPUT_VARIABLE OKITOKI)
689 exec_program("chmod a=rwx ${PROJECT_DIRECTORY}/src/smpi/smpirun" OUTPUT_VARIABLE OKITOKI)