Logo AND Algorithmique Numérique Distribuée

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