Logo AND Algorithmique Numérique Distribuée

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