Logo AND Algorithmique Numérique Distribuée

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