Logo AND Algorithmique Numérique Distribuée

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