Logo AND Algorithmique Numérique Distribuée

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