Logo AND Algorithmique Numérique Distribuée

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