Logo AND Algorithmique Numérique Distribuée

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