Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Kill enable_graphviz cmake variable
[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("-- Smpi Need \"f2c.h\".")
153                 message("-- Please install f2c before use smpi or set LD_LIBRARY_PATH to \"f2c.h\".")
154                 message(FATAL_ERROR "SMPI DEPENDENCIES")
155         endif(HAVE_F2C_H)       
156 endif(enable_smpi)
157
158 #--------------------------------------------------------------------------------------------------
159 ### Initialize of CONTEXT JAVA
160
161 if(enable_java)
162         include(FindJava)
163         include(FindJNI)
164         if(JAVA_INCLUDE_PATH)
165                 set(HAVE_JNI_H 1)
166         endif(JAVA_INCLUDE_PATH)        
167         if(JAVA_COMPILE AND JAVA_INCLUDE_PATH AND JAVA_INCLUDE_PATH2)
168                 SET(HAVE_JAVA 1)
169                 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}-I${JAVA_INCLUDE_PATH} ")
170                 if(NOT JAVA_INCLUDE_PATH STREQUAL JAVA_INCLUDE_PATH2)
171                 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}-I${JAVA_INCLUDE_PATH2} ")                   
172                 endif(NOT JAVA_INCLUDE_PATH STREQUAL JAVA_INCLUDE_PATH2)
173         else(JAVA_COMPILE AND JAVA_INCLUDE_PATH AND JAVA_INCLUDE_PATH2) 
174                 SET(HAVE_JAVA 0)
175         endif(JAVA_COMPILE AND JAVA_INCLUDE_PATH AND JAVA_INCLUDE_PATH2)
176 endif(enable_java)
177
178 #--------------------------------------------------------------------------------------------------
179 ### Initialize of CONTEXT GTNETS
180 if(NOT enable_gtnets OR enable_supernovae)
181         SET(HAVE_GTNETS 0)
182 else(NOT enable_gtnets OR enable_supernovae)
183         set(GTNETS_LDFLAGS "-L${gtnets_path}/lib")
184         set(GTNETS_CPPFLAGS "-I${gtnets_path}/include/gtnets")
185         exec_program("${CMAKE_CXX_COMPILER} ${GTNETS_CPPFLAGS} -lgtnets ${GTNETS_LDFLAGS} ${PROJECT_DIRECTORY}/buildtools/Cmake/test_prog/prog_gtnets.cpp " OUTPUT_VARIABLE COMPILE_GTNETS_VAR) 
186         if(COMPILE_GTNETS_VAR)
187                 SET(HAVE_GTNETS 0)
188         else(COMPILE_GTNETS_VAR)
189                 SET(HAVE_GTNETS 1)
190                 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}${GTNETS_CPPFLAGS} ${GTNETS_LDFLAGS} ")
191                 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}${GTNETS_CPPFLAGS} ${GTNETS_LDFLAGS} ")
192                 string(REGEX MATCH "${gtnets_path}/lib" operation "$ENV{LD_LIBRARY_PATH}")
193                 if(NOT operation)
194                         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")
195                 endif(NOT operation)
196         endif(COMPILE_GTNETS_VAR)
197 endif(NOT enable_gtnets OR enable_supernovae)
198
199 #--------------------------------------------------------------------------------------------------
200 #--------------------------------------------------------------------------------------------------
201 ### Initialize of pcre
202 find_library(PATH_PCRE_LIB pcre)
203 find_file(PATH_PCRE_H "pcre.h")
204 set(HAVE_PCRE_LIB 0)
205 if(PATH_PCRE_LIB AND PATH_PCRE_H)
206        string(REGEX REPLACE "/libpcre.*[.]${LIB_EXE}$" "" PATHLIBPCRE "${PATH_PCRE_LIB}")
207        string(REGEX REPLACE "/pcre.h" "" PATH_PCRE_H "${PATH_PCRE_H}")
208        string(REGEX MATCH "-L${PATHLIBPCRE} " operation "${CMAKE_C_FLAGS}")
209            if(NOT operation)
210                         SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}-L${PATHLIBPCRE} ")
211            endif(NOT operation)
212            string(REGEX MATCH "-I${PATH_PCRE_H} " operation "${CMAKE_C_FLAGS}")
213            if(NOT operation)
214                         SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}-I${PATH_PCRE_H} ")
215            endif(NOT operation)    
216        set(HAVE_PCRE_LIB 1)
217 else(PATH_PCRE_LIB)
218                 message("You should install libpcre (please install the libpcre3-dev package or equivalent)")
219 endif(PATH_PCRE_LIB AND PATH_PCRE_H)
220
221 #--------------------------------------------------------------------------------------------------
222 ### Initialize of CONTEXT THREADS
223
224 if(pthread)
225         set(pthread 1)
226 elseif(pthread)
227         set(pthread 0)
228 endif(pthread)
229
230 if(pthread)
231         ### HAVE_SEM_INIT
232         
233         if(HAVE_SEM_INIT_LIB)
234                 exec_program("${CMAKE_C_COMPILER} -lpthread ${PROJECT_DIRECTORY}/buildtools/Cmake/test_prog/prog_sem_init.c" OUTPUT_VARIABLE HAVE_SEM_INIT_run)
235                 if(HAVE_SEM_INIT_run)
236                         set(HAVE_SEM_INIT 0)
237                 else(HAVE_SEM_INIT_run)
238                         set(HAVE_SEM_INIT 1)
239                 endif(HAVE_SEM_INIT_run)
240         endif(HAVE_SEM_INIT_LIB)
241
242         ### HAVE_SEM_TIMEDWAIT
243
244         if(HAVE_SEM_TIMEDWAIT_LIB)
245                 exec_program("${CMAKE_C_COMPILER} -lpthread ${PROJECT_DIRECTORY}/buildtools/Cmake/test_prog/prog_sem_timedwait.c" OUTPUT_VARIABLE HAVE_SEM_TIMEDWAIT_run)
246                 if(HAVE_SEM_TIMEDWAIT_run)
247                         set(HAVE_SEM_TIMEDWAIT 0)
248                 else(HAVE_SEM_TIMEDWAIT_run)
249                         set(HAVE_SEM_TIMEDWAIT 1)
250                 endif(HAVE_SEM_TIMEDWAIT_run)
251         endif(HAVE_SEM_TIMEDWAIT_LIB)
252
253         ### HAVE_MUTEX_TIMEDLOCK
254
255         if(HAVE_MUTEX_TIMEDLOCK_LIB)
256                 exec_program("${CMAKE_C_COMPILER} -lpthread ${PROJECT_DIRECTORY}/buildtools/Cmake/test_prog/prog_mutex_timedlock.c" OUTPUT_VARIABLE HAVE_SEM_TIMEDWAIT_run)
257                 if(HAVE_MUTEX_TIMEDLOCK_run)
258                         set(HAVE_MUTEX_TIMEDLOCK 0)
259                 else(HAVE_MUTEX_TIMEDLOCK_run)
260                         set(HAVE_MUTEX_TIMEDLOCK 1)
261                 endif(HAVE_MUTEX_TIMEDLOCK_run)
262         endif(HAVE_MUTEX_TIMEDLOCK_LIB)
263 endif(pthread)
264
265 # AC_CHECK_MCSC(mcsc=yes, mcsc=no) 
266 set(mcsc_flags "")
267 if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
268         set(mcsc_flags "-D_XOPEN_SOURCE")
269 endif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
270
271 if(WIN32)
272     if(__VISUALC__)
273         set(mcsc_flags "/D_XBT_WIN32 /I${PROJECT_DIRECTORY}/include/xbt /I${PROJECT_DIRECTORY}/src/xbt")
274         endif(__VISUALC__)
275         if(__GNUC__)
276                 set(mcsc_flags "-D_XBT_WIN32 -I${PROJECT_DIRECTORY}/include/xbt -I${PROJECT_DIRECTORY}/src/xbt")
277         endif(__GNUC__)
278 endif(WIN32)
279
280 IF(CMAKE_CROSSCOMPILING)
281         IF(WIN32)
282                 set(windows_context "yes")
283                 set(IS_WINDOWS 1)       
284         ENDIF(WIN32)
285 ELSE(CMAKE_CROSSCOMPILING)
286         try_run(RUN_mcsc_VAR COMPILE_mcsc_VAR
287                 ${simgrid_BINARY_DIR}
288                 ${PROJECT_DIRECTORY}/buildtools/Cmake/test_prog/prog_AC_CHECK_MCSC.c
289                 COMPILE_DEFINITIONS "${mcsc_flags}"
290                 OUTPUT_VARIABLE var_compil
291                 )
292                 
293                 if(EXISTS "${simgrid_BINARY_DIR}/conftestval" AND COMPILE_mcsc_VAR)
294                         file(READ "${simgrid_BINARY_DIR}/conftestval" mcsc)
295                         STRING(REPLACE "\n" "" mcsc "${mcsc}")
296                         if(mcsc)
297                                 set(mcsc "yes")
298                         elseif(mcsc)
299                                 set(mcsc "no")
300                         endif(mcsc)
301                 else(EXISTS "${simgrid_BINARY_DIR}/conftestval" AND COMPILE_mcsc_VAR)
302                         set(mcsc "no")
303                 endif(EXISTS "${simgrid_BINARY_DIR}/conftestval" AND COMPILE_mcsc_VAR)
304 ENDIF(CMAKE_CROSSCOMPILING)
305
306 if(mcsc MATCHES "no" AND pthread)
307         if(HAVE_WINDOWS_H)
308                 set(windows_context "yes")
309                 set(IS_WINDOWS 1)
310         elseif(HAVE_WINDOWS_H)
311                 message(FATAL_ERROR "no appropriate backend found")
312         endif(HAVE_WINDOWS_H)
313 endif(mcsc MATCHES "no" AND pthread)
314
315 if(with_context MATCHES "ucontext" AND mcsc MATCHES "no")
316         message(FATAL_ERROR "-Dwith-context=ucontext specified but ucontext unusable.")
317 endif(with_context MATCHES "ucontext" AND mcsc MATCHES "no")
318
319 set(with_context_ok 0)
320 if(with_context MATCHES "windows")
321         set(with_context_ok 1)
322         if(NOT HAVE_WINDOWS_H)
323                 message(FATAL_ERROR "no appropriate backend found windows")
324         endif(NOT HAVE_WINDOWS_H)
325 endif(with_context MATCHES "windows")
326
327 if(with_context MATCHES "pthreads")
328         set(with_context_ok 1)
329         set(with_context "pthread")
330 endif(with_context MATCHES "pthreads")
331
332 if(with_context MATCHES "auto")
333         set(with_context_ok 1)
334         set(with_context "ucontext")
335         message("with_context auto change to ucontext")
336 endif(with_context MATCHES "auto")
337
338 if(with_context MATCHES "ucontext")
339         set(with_context_ok 1)
340         if(mcsc)
341                 set(CONTEXT_UCONTEXT 1)
342         else(mcsc)
343                 if(windows_context MATCHES "yes")
344                         set(with_context "windows")
345                         message("with_context ucontext change to windows")
346                 else(windows_context MATCHES "yes")
347                         set(with_context "pthread")
348                         message("with_context ucontext change to pthread")
349                 endif(windows_context MATCHES "yes")
350         endif(mcsc)
351 endif(with_context MATCHES "ucontext")
352
353 if(with_context MATCHES "pthread")
354         set(with_context_ok 1)
355         if(NOT pthread)
356                 message(FATAL_ERROR "Cannot find pthreads (try -Dwith_context=ucontext if you haven't already tried).")
357         endif(NOT pthread)
358         SET(CONTEXT_THREADS 1)
359 endif(with_context MATCHES "pthread")
360
361 if(with_context MATCHES "ucontext")
362         SET(CONTEXT_THREADS 0)
363 endif(with_context MATCHES "ucontext")
364
365 if(NOT with_context_ok)
366         message(FATAL_ERROR "-Dwith-context must be either ucontext or pthread")
367 endif(NOT with_context_ok)
368
369 ###############
370 ## SVN version check
371 ##
372 if(IS_DIRECTORY ${PROJECT_DIRECTORY}/.svn)
373         find_file(SVN ".svn" ${PROJECT_DIRECTORY})
374         exec_program("svnversion ${PROJECT_DIRECTORY}" OUTPUT_VARIABLE "SVN_VERSION")
375         message("SVN_VERSION : ${SVN_VERSION}")
376 endif(IS_DIRECTORY ${PROJECT_DIRECTORY}/.svn)
377
378 if(IS_DIRECTORY ${PROJECT_DIRECTORY}/.git)
379
380         exec_program("git --git-dir=${PROJECT_DIRECTORY}/.git log --oneline -1" OUTPUT_VARIABLE "GIT_VERSION")
381         exec_program("git --git-dir=${PROJECT_DIRECTORY}/.git log -n 1 --format=%ai ." OUTPUT_VARIABLE "GIT_DATE")
382         exec_program("git svn info" ${PROJECT_DIRECTORY} OUTPUT_VARIABLE "GIT_SVN_VERSION")
383         
384         string(REGEX REPLACE " .*" "" GIT_VERSION "${GIT_VERSION}")
385         string(REPLACE "\n" ";" GIT_SVN_VERSION ${GIT_SVN_VERSION})
386         STRING(REPLACE " +0000" "" GIT_DATE ${GIT_DATE})
387         STRING(REPLACE " " "~" GIT_DATE ${GIT_DATE})
388         STRING(REPLACE ":" "-" GIT_DATE ${GIT_DATE})
389         foreach(line ${GIT_SVN_VERSION})
390                 string(REGEX MATCH "^Revision:.*" line_good ${line})
391                 if(line_good)
392                         string(REPLACE "Revision: " "" line_good ${line_good})
393                         set(SVN_VERSION ${line_good})
394                 endif(line_good)
395         endforeach(line ${GIT_SVN_VERSION})
396 endif(IS_DIRECTORY ${PROJECT_DIRECTORY}/.git)
397
398 ###################################
399 ## SimGrid and GRAS specific checks
400 ##
401
402 IF(NOT CMAKE_CROSSCOMPILING)
403 # Check architecture signature begin
404 try_run(RUN_GRAS_VAR COMPILE_GRAS_VAR
405         ${simgrid_BINARY_DIR}
406         ${PROJECT_DIRECTORY}/buildtools/Cmake/test_prog/prog_GRAS_ARCH.c
407         RUN_OUTPUT_VARIABLE var1
408         )
409 if(BIGENDIAN)
410   set(val_big "B${var1}")
411   set(GRAS_BIGENDIAN 1)
412 else(BIGENDIAN)
413   set(val_big "l${var1}")
414   set(GRAS_BIGENDIAN 0)
415 endif(BIGENDIAN)
416
417 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:")
418         #gras_arch=0; gras_size=32; gras_arch_name=little32_1;
419         SET(GRAS_ARCH_32_BITS 1)
420         SET(GRAS_THISARCH 0)
421 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:")
422 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:")
423         #gras_arch=1; gras_size=32; gras_arch_name=little32_2;
424         SET(GRAS_ARCH_32_BITS 1)
425         SET(GRAS_THISARCH 1)
426 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:")
427 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:") 
428         #gras_arch=2; gras_size=32; gras_arch_name=little32_4;
429         SET(GRAS_ARCH_32_BITS 1)
430         SET(GRAS_THISARCH 2)
431 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:")
432 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:") 
433         #gras_arch=3; gras_size=32; gras_arch_name=little32_8;
434         SET(GRAS_ARCH_32_BITS 1)
435         SET(GRAS_THISARCH 3)
436 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:") 
437 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:") 
438         #gras_arch=4; gras_size=64; gras_arch_name=little64;
439         SET(GRAS_ARCH_32_BITS 0)
440         SET(GRAS_THISARCH 4)
441 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:")
442
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/8:") 
444         #gras_arch=5; gras_size=32; gras_arch_name=big32;
445         SET(GRAS_ARCH_32_BITS 1)
446         SET(GRAS_THISARCH 5)
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/8:")
448 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:") 
449         #gras_arch=6; gras_size=32; gras_arch_name=big32_8_4;
450         SET(GRAS_ARCH_32_BITS 1)
451         SET(GRAS_THISARCH 6)
452 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:")
453 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:") 
454         #gras_arch=7; gras_size=32; gras_arch_name=big32_4;
455         SET(GRAS_ARCH_32_BITS 1)
456         SET(GRAS_THISARCH 7)
457 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:")
458 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:") 
459         #gras_arch=8; gras_size=32; gras_arch_name=big32_2;
460         SET(GRAS_ARCH_32_BITS 1)
461         SET(GRAS_THISARCH 8)
462 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:") 
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/8:") 
464         #gras_arch=9; gras_size=64; gras_arch_name=big64;
465         SET(GRAS_ARCH_32_BITS 0)
466         SET(GRAS_THISARCH 9)
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/8:")
468 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:") 
469         #gras_arch=10;gras_size=64; gras_arch_name=big64_8_4;
470         SET(GRAS_ARCH_32_BITS 0)
471         SET(GRAS_THISARCH 10)
472 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:") 
473
474
475 # Check architecture signature end
476 try_run(RUN_GRAS_VAR COMPILE_GRAS_VAR
477         ${simgrid_BINARY_DIR}
478         ${PROJECT_DIRECTORY}/buildtools/Cmake/test_prog/prog_GRAS_CHECK_STRUCT_COMPACTION.c
479         RUN_OUTPUT_VARIABLE var2
480         )
481 separate_arguments(var2)
482 foreach(var_tmp ${var2})
483         set(${var_tmp} 1)
484 endforeach(var_tmp ${var2})
485
486 # Check for [SIZEOF_MAX]
487 try_run(RUN_SM_VAR COMPILE_SM_VAR
488         ${simgrid_BINARY_DIR}
489         ${PROJECT_DIRECTORY}/buildtools/Cmake/test_prog/prog_max_size.c
490         RUN_OUTPUT_VARIABLE var3
491         )
492 SET(SIZEOF_MAX ${var3})
493 ENDIF(NOT CMAKE_CROSSCOMPILING)
494
495 #--------------------------------------------------------------------------------------------------
496
497 set(makecontext_CPPFLAGS_2 "")
498 if(HAVE_MAKECONTEXT OR WIN32)
499         set(makecontext_CPPFLAGS "-DTEST_makecontext")
500         if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
501                 set(makecontext_CPPFLAGS_2 "-DOSX")
502         endif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
503         
504     if(WIN32 AND __VISUALC__)
505         set(makecontext_CPPFLAGS "/DTEST_makecontext")
506             set(makecontext_CPPFLAGS_2 "/D_XBT_WIN32 /I${PROJECT_DIRECTORY}/include/xbt /I${PROJECT_DIRECTORY}/src/xbt")
507         endif(WIN32 AND __VISUALC__)
508         if(WIN32 AND __GNUC__)
509             set(makecontext_CPPFLAGS "-DTEST_makecontext")
510             set(makecontext_CPPFLAGS_2 "-D_XBT_WIN32 -I${PROJECT_DIRECTORY}/include/xbt -I${PROJECT_DIRECTORY}/src/xbt")
511         endif(WIN32 AND __GNUC__)
512         
513         try_run(RUN_makecontext_VAR COMPILE_makecontext_VAR
514                 ${simgrid_BINARY_DIR}
515                 ${PROJECT_DIRECTORY}/buildtools/Cmake/test_prog/prog_stacksetup.c
516                 COMPILE_DEFINITIONS "${makecontext_CPPFLAGS} ${makecontext_CPPFLAGS_2}"
517                 )
518         file(READ ${simgrid_BINARY_DIR}/conftestval MAKECONTEXT_ADDR_SIZE)
519         string(REPLACE "\n" "" MAKECONTEXT_ADDR_SIZE "${MAKECONTEXT_ADDR_SIZE}")
520         string(REGEX MATCH ;^.*,;MAKECONTEXT_ADDR "${MAKECONTEXT_ADDR_SIZE}")
521         string(REGEX MATCH ;,.*$; MAKECONTEXT_SIZE "${MAKECONTEXT_ADDR_SIZE}")
522         string(REPLACE "," "" makecontext_addr "${MAKECONTEXT_ADDR}")
523         string(REPLACE "," "" makecontext_size "${MAKECONTEXT_SIZE}")   
524         set(pth_skaddr_makecontext "#define pth_skaddr_makecontext(skaddr,sksize) (${makecontext_addr})")
525         set(pth_sksize_makecontext "#define pth_sksize_makecontext(skaddr,sksize) (${makecontext_size})")
526         
527 endif(HAVE_MAKECONTEXT OR WIN32)
528
529 #--------------------------------------------------------------------------------------------------
530
531 ### check for stackgrowth
532 if (NOT CMAKE_CROSSCOMPILING)
533         try_run(RUN_makecontext_VAR COMPILE_makecontext_VAR
534                 ${simgrid_BINARY_DIR}
535                 ${PROJECT_DIRECTORY}/buildtools/Cmake/test_prog/prog_stackgrowth.c
536                 )
537 file(READ "${simgrid_BINARY_DIR}/conftestval" stack)
538 if(stack MATCHES "down")
539         set(PTH_STACKGROWTH "-1")
540 endif(stack MATCHES "down")
541 if(stack MATCHES "up")
542         set(PTH_STACKGROWTH "1")
543 endif(stack MATCHES "up")
544
545 endif(NOT CMAKE_CROSSCOMPILING)
546 ###############
547 ## System checks
548 ##
549
550 #SG_CONFIGURE_PART([System checks...])
551 #AC_PROG_CC(xlC gcc cc) -auto
552 #AM_SANITY_CHECK -auto
553
554 #AC_PROG_MAKE_SET
555
556
557 #AC_PRINTF_NULL
558 try_run(RUN_PRINTF_NULL_VAR COMPILE_PRINTF_NULL_VAR
559         ${simgrid_BINARY_DIR}
560         ${PROJECT_DIRECTORY}/buildtools/Cmake/test_prog/prog_printf_null.c
561         )
562
563 if(RUN_PRINTF_NULL_VAR MATCHES "FAILED_TO_RUN")
564 SET(PRINTF_NULL_WORKING "0")
565 else(RUN_PRINTF_NULL_VAR MATCHES "FAILED_TO_RUN")
566 SET(PRINTF_NULL_WORKING "1")
567 endif(RUN_PRINTF_NULL_VAR MATCHES "FAILED_TO_RUN")
568
569 #AC_CHECK_VA_COPY
570
571 set(diff_va "va_copy((d),(s))"
572 "VA_COPY((d),(s))"
573 "__va_copy((d),(s))"
574 "__builtin_va_copy((d),(s))"
575 "do { (d) = (s)\; } while (0)"
576 "do { *(d) = *(s)\; } while (0)"
577 "memcpy((void *)&(d), (void *)&(s), sizeof(s))"
578 "memcpy((void *)(d), (void *)(s), sizeof(*(s)))"
579 )
580
581 foreach(fct ${diff_va})
582         write_file("${PROJECT_DIRECTORY}/buildtools/Cmake/test_prog/prog_va_copy.c" "#include <stdlib.h>
583         #include <stdarg.h>
584         #include <string.h>
585         #define DO_VA_COPY(d,s) ${fct}
586         void test(char *str, ...)
587         {
588             va_list ap, ap2;
589             int i;
590             va_start(ap, str);
591             DO_VA_COPY(ap2, ap);
592             for (i = 1; i <= 9; i++) {
593                 int k = (int)va_arg(ap, int);
594                 if (k != i)
595                     abort();
596             }
597             DO_VA_COPY(ap, ap2);
598             for (i = 1; i <= 9; i++) {
599                 int k = (int)va_arg(ap, int);
600                 if (k != i)
601                     abort();
602             }
603             va_end(ap);
604         }
605         int main(int argc, char *argv[])
606         {
607             test("test", 1, 2, 3, 4, 5, 6, 7, 8, 9);
608             exit(0);
609         }"
610         )
611         try_compile(COMPILE_VA_NULL_VAR
612         ${simgrid_BINARY_DIR}
613         ${PROJECT_DIRECTORY}/buildtools/Cmake/test_prog/prog_va_copy.c
614         )
615         if(COMPILE_VA_NULL_VAR)
616                 string(REGEX REPLACE "\;" "" fctbis ${fct})
617                 if(${fctbis} STREQUAL "va_copy((d),(s))")
618                         set(HAVE_VA_COPY 1)
619                         set(ac_cv_va_copy "C99")
620                         set(__VA_COPY_USE_C99 "va_copy((d),(s))")       
621                 endif(${fctbis} STREQUAL "va_copy((d),(s))")
622
623                 if(${fctbis} STREQUAL "VA_COPY((d),(s))")
624                         set(ac_cv_va_copy "GCM")
625                         set(__VA_COPY_USE_GCM "VA_COPY((d),(s))")
626                 endif(${fctbis} STREQUAL "VA_COPY((d),(s))")
627
628                 if(${fctbis} STREQUAL "__va_copy((d),(s))")
629                         set(ac_cv_va_copy "GCH")
630                         set(__VA_COPY_USE_GCH "__va_copy((d),(s))")
631                 endif(${fctbis} STREQUAL "__va_copy((d),(s))")
632
633                 if(${fctbis} STREQUAL "__builtin_va_copy((d),(s))")
634                         set(ac_cv_va_copy "GCB")
635                         set(__VA_COPY_USE_GCB "__builtin_va_copy((d),(s))")
636                 endif(${fctbis} STREQUAL "__builtin_va_copy((d),(s))")
637
638                 if(${fctbis} STREQUAL "do { (d) = (s) } while (0)")
639                         set(ac_cv_va_copy "ASS")
640                         set(__VA_COPY_USE_ASS "do { (d) = (s); } while (0)")
641                 endif(${fctbis} STREQUAL "do { (d) = (s) } while (0)")
642
643                 if(${fctbis} STREQUAL "do { *(d) = *(s) } while (0)")
644                         set(ac_cv_va_copy "ASP")
645                         set(__VA_COPY_USE_ASP "do { *(d) = *(s); } while (0)")
646                 endif(${fctbis} STREQUAL "do { *(d) = *(s) } while (0)")
647
648                 if(${fctbis} STREQUAL "memcpy((void *)&(d), (void *)&(s), sizeof(s))")
649                         set(ac_cv_va_copy "CPS")
650                         set(__VA_COPY_USE_CPS "memcpy((void *)&(d), (void *)&(s), sizeof(s))")
651                 endif(${fctbis} STREQUAL "memcpy((void *)&(d), (void *)&(s), sizeof(s))")
652
653                 if(${fctbis} STREQUAL "memcpy((void *)(d), (void *)(s), sizeof(*(s)))")
654                         set(ac_cv_va_copy "CPP")
655                         set(__VA_COPY_USE_CPP "memcpy((void *)(d), (void *)(s), sizeof(*(s)))")
656                 endif(${fctbis} STREQUAL "memcpy((void *)(d), (void *)(s), sizeof(*(s)))")
657                                 
658                 if(NOT STATUS_OK)
659                 set(__VA_COPY_USE "__VA_COPY_USE_${ac_cv_va_copy}(d, s)")
660                 endif(NOT STATUS_OK)
661                 set(STATUS_OK "1")
662                 
663         endif(COMPILE_VA_NULL_VAR)
664         
665 endforeach(fct ${diff_va})
666
667 #--------------------------------------------------------------------------------------------------
668 ### check for getline
669 try_compile(COMPILE_RESULT_VAR
670         ${simgrid_BINARY_DIR}
671         ${PROJECT_DIRECTORY}/buildtools/Cmake/test_prog/prog_getline.c
672         )
673
674 if(NOT COMPILE_RESULT_VAR)
675 SET(need_getline "#define SIMGRID_NEED_GETLINE 1")
676 SET(SIMGRID_NEED_GETLINE 1)
677 else(NOT COMPILE_RESULT_VAR)
678 SET(need_getline "")
679 SET(SIMGRID_NEED_GETLINE 0)
680 endif(NOT COMPILE_RESULT_VAR)
681
682 ### check for a working snprintf
683 if(HAVE_SNPRINTF AND HAVE_VSNPRINTF OR WIN32)
684     if(WIN32)
685         #set(HAVE_SNPRINTF 1)
686         #set(HAVE_VSNPRINTF 1)
687     endif(WIN32)
688     
689         if(CMAKE_CROSSCOMPILING)
690                 set(RUN_SNPRINTF_FUNC "cross")
691                 #set(PREFER_PORTABLE_SNPRINTF 1)
692         else(CMAKE_CROSSCOMPILING)
693             try_run(RUN_SNPRINTF_FUNC_VAR COMPILE_SNPRINTF_FUNC_VAR
694                 ${simgrid_BINARY_DIR}
695                 ${PROJECT_DIRECTORY}/buildtools/Cmake/test_prog/prog_snprintf.c
696             )   
697         endif(CMAKE_CROSSCOMPILING)
698
699         if(CMAKE_CROSSCOMPILING)
700                 set(RUN_VSNPRINTF_FUNC "cross")
701                 set(PREFER_PORTABLE_VSNPRINTF 1)
702         else(CMAKE_CROSSCOMPILING)
703            try_run(RUN_VSNPRINTF_FUNC_VAR COMPILE_VSNPRINTF_FUNC_VAR
704                 ${simgrid_BINARY_DIR}
705                 ${PROJECT_DIRECTORY}/buildtools/Cmake/test_prog/prog_vsnprintf.c
706            )
707         endif(CMAKE_CROSSCOMPILING)
708         
709         set(PREFER_PORTABLE_SNPRINTF 0)
710         if(RUN_VSNPRINTF_FUNC_VAR MATCHES "FAILED_TO_RUN")
711                 set(PREFER_PORTABLE_SNPRINTF 1)
712         endif(RUN_VSNPRINTF_FUNC_VAR MATCHES "FAILED_TO_RUN")
713         if(RUN_SNPRINTF_FUNC_VAR MATCHES "FAILED_TO_RUN")
714                 set(PREFER_PORTABLE_SNPRINTF 1)
715         endif(RUN_SNPRINTF_FUNC_VAR MATCHES "FAILED_TO_RUN")
716 endif(HAVE_SNPRINTF AND HAVE_VSNPRINTF OR WIN32)
717
718 ### check for asprintf function familly
719 if(HAVE_ASPRINTF)
720         SET(simgrid_need_asprintf "")
721         SET(NEED_ASPRINTF 0)
722 else(HAVE_ASPRINTF)
723         SET(simgrid_need_asprintf "#define SIMGRID_NEED_ASPRINTF 1")
724         SET(NEED_ASPRINTF 1)
725 endif(HAVE_ASPRINTF)
726
727 if(HAVE_VASPRINTF)
728         SET(simgrid_need_vasprintf "")
729         SET(NEED_VASPRINTF 0)
730 else(HAVE_VASPRINTF)
731         SET(simgrid_need_vasprintf "#define SIMGRID_NEED_VASPRINTF 1")
732         SET(NEED_VASPRINTF 1)
733 endif(HAVE_VASPRINTF)
734
735 ### check for addr2line
736
737 find_path(ADDR2LINE NAMES addr2line     PATHS NO_DEFAULT_PATHS  )
738 if(ADDR2LINE)
739 set(ADDR2LINE "${ADDR2LINE}/addr2line")
740 endif(ADDR2LINE)
741
742 ### File to create
743
744 configure_file("${PROJECT_DIRECTORY}/src/context_sysv_config.h.in"                      "${CMAKE_CURRENT_BINARY_DIR}/src/context_sysv_config.h" @ONLY IMMEDIATE)
745
746 SET( CMAKEDEFINE "#cmakedefine" )
747 configure_file("${PROJECT_DIRECTORY}/buildtools/Cmake/gras_config.h.in"         "${CMAKE_CURRENT_BINARY_DIR}/src/gras_config.h" @ONLY IMMEDIATE)
748 configure_file("${CMAKE_CURRENT_BINARY_DIR}/src/gras_config.h"                  "${CMAKE_CURRENT_BINARY_DIR}/src/gras_config.h" @ONLY IMMEDIATE)
749 configure_file("${PROJECT_DIRECTORY}/include/simgrid_config.h.in"               "${CMAKE_CURRENT_BINARY_DIR}/include/simgrid_config.h" @ONLY IMMEDIATE)
750
751 set(top_srcdir "${PROJECT_DIRECTORY}")
752 set(srcdir "${PROJECT_DIRECTORY}/src")
753
754 set(exec_prefix ${CMAKE_INSTALL_PREFIX})
755 set(includedir ${CMAKE_INSTALL_PREFIX}/include)
756 set(top_builddir ${PROJECT_DIRECTORY})
757 set(libdir ${exec_prefix}/lib)
758 set(CMAKE_LINKARGS "${CMAKE_CURRENT_BINARY_DIR}/lib")
759 set(CMAKE_SMPI_COMMAND "export LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/lib:${gtnets_path}/lib:$LD_LIBRARY_PATH")
760
761 configure_file(${PROJECT_DIRECTORY}/src/smpi/smpicc.in ${CMAKE_CURRENT_BINARY_DIR}/bin/smpicc @ONLY)
762 configure_file(${PROJECT_DIRECTORY}/src/smpi/smpif2c.in ${CMAKE_CURRENT_BINARY_DIR}/bin/smpif2c @ONLY)
763 configure_file(${PROJECT_DIRECTORY}/src/smpi/smpiff.in ${CMAKE_CURRENT_BINARY_DIR}/bin/smpiff @ONLY)
764 configure_file(${PROJECT_DIRECTORY}/src/smpi/smpirun.in ${CMAKE_CURRENT_BINARY_DIR}/bin/smpirun @ONLY)
765 configure_file(${PROJECT_DIRECTORY}/examples/smpi/hostfile ${CMAKE_CURRENT_BINARY_DIR}/examples/smpi/hostfile COPYONLY)
766 configure_file(${PROJECT_DIRECTORY}/examples/msg/small_platform.xml ${CMAKE_CURRENT_BINARY_DIR}/examples/msg/small_platform.xml COPYONLY)
767 configure_file(${PROJECT_DIRECTORY}/examples/msg/small_platform_with_routers.xml ${CMAKE_CURRENT_BINARY_DIR}/examples/msg/small_platform_with_routers.xml COPYONLY)
768
769 exec_program("chmod a=rwx ${CMAKE_CURRENT_BINARY_DIR}/bin/smpicc" OUTPUT_VARIABLE OKITOKI)
770 exec_program("chmod a=rwx ${CMAKE_CURRENT_BINARY_DIR}/bin/smpif2c" OUTPUT_VARIABLE OKITOKI)
771 exec_program("chmod a=rwx ${CMAKE_CURRENT_BINARY_DIR}/bin/smpiff" OUTPUT_VARIABLE OKITOKI)
772 exec_program("chmod a=rwx ${CMAKE_CURRENT_BINARY_DIR}/bin/smpirun" OUTPUT_VARIABLE OKITOKI)