Logo AND Algorithmique Numérique Distribuée

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