Logo AND Algorithmique Numérique Distribuée

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