Logo AND Algorithmique Numérique Distribuée

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