Logo AND Algorithmique Numérique Distribuée

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