Logo AND Algorithmique Numérique Distribuée

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