Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Be generic with cgraph.c so now no path to set.
[simgrid.git] / buildtools / Cmake / CompleteInFiles.cmake
1 include(CheckFunctionExists)
2 include(CheckIncludeFile)
3 include(CheckIncludeFiles)
4 include(CheckLibraryExists)
5 include(TestBigEndian)
6
7 TEST_BIG_ENDIAN(BIGENDIAN)
8
9 # 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
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 cgraph
223
224 find_library(HAVE_CGRAPH_LIB cgraph)
225 find_file(HAVE_CGRAPH_H graphviz/cgraph.h)
226 mark_as_advanced(HAVE_CGRAPH_LIB)
227 mark_as_advanced(HAVE_CGRAPH_H)
228
229 if(HAVE_CGRAPH_LIB AND HAVE_CGRAPH_H)
230         string(REGEX REPLACE "libcgraph.*" "" lib_cgraph ${HAVE_CGRAPH_LIB})
231         string(REPLACE "graphviz/cgraph.h" "" file_cgraph_h ${HAVE_CGRAPH_H})
232         
233         string(REGEX MATCH "-L${lib_cgraph}" operation "${CMAKE_EXE_LINKER_FLAGS}")
234         if(NOT operation)
235                 SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}-L${lib_cgraph} ")
236         endif(NOT operation)
237         
238         string(REGEX MATCH "-I${file_cgraph_h}" operation "${CMAKE_C_FLAGS}")
239         if(NOT operation)
240                 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}-I${file_cgraph_h} ")
241         endif(NOT operation)
242         
243 endif(HAVE_CGRAPH_LIB AND HAVE_CGRAPH_H)
244
245 #--------------------------------------------------------------------------------------------------
246 ### Initialize of CONTEXT THREADS
247
248 if(pthread)
249         set(pthread 1)
250 elseif(pthread)
251         set(pthread 0)
252 endif(pthread)
253
254 if(pthread)
255         ### HAVE_SEM_INIT
256         
257         if(HAVE_SEM_INIT_LIB)
258                 exec_program("${CMAKE_C_COMPILER} -lpthread ${PROJECT_DIRECTORY}/buildtools/Cmake/test_prog/prog_sem_init.c" OUTPUT_VARIABLE HAVE_SEM_INIT_run)
259                 if(HAVE_SEM_INIT_run)
260                         set(HAVE_SEM_INIT 0)
261                 else(HAVE_SEM_INIT_run)
262                         set(HAVE_SEM_INIT 1)
263                 endif(HAVE_SEM_INIT_run)
264         endif(HAVE_SEM_INIT_LIB)
265
266         ### HAVE_SEM_TIMEDWAIT
267
268         if(HAVE_SEM_TIMEDWAIT_LIB)
269                 exec_program("${CMAKE_C_COMPILER} -lpthread ${PROJECT_DIRECTORY}/buildtools/Cmake/test_prog/prog_sem_timedwait.c" OUTPUT_VARIABLE HAVE_SEM_TIMEDWAIT_run)
270                 if(HAVE_SEM_TIMEDWAIT_run)
271                         set(HAVE_SEM_TIMEDWAIT 0)
272                 else(HAVE_SEM_TIMEDWAIT_run)
273                         set(HAVE_SEM_TIMEDWAIT 1)
274                 endif(HAVE_SEM_TIMEDWAIT_run)
275         endif(HAVE_SEM_TIMEDWAIT_LIB)
276
277         ### HAVE_MUTEX_TIMEDLOCK
278
279         if(HAVE_MUTEX_TIMEDLOCK_LIB)
280                 exec_program("${CMAKE_C_COMPILER} -lpthread ${PROJECT_DIRECTORY}/buildtools/Cmake/test_prog/prog_mutex_timedlock.c" OUTPUT_VARIABLE HAVE_SEM_TIMEDWAIT_run)
281                 if(HAVE_MUTEX_TIMEDLOCK_run)
282                         set(HAVE_MUTEX_TIMEDLOCK 0)
283                 else(HAVE_MUTEX_TIMEDLOCK_run)
284                         set(HAVE_MUTEX_TIMEDLOCK 1)
285                 endif(HAVE_MUTEX_TIMEDLOCK_run)
286         endif(HAVE_MUTEX_TIMEDLOCK_LIB)
287 endif(pthread)
288
289 # AC_CHECK_MCSC(mcsc=yes, mcsc=no) 
290 set(mcsc_flags "")
291 if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
292         set(mcsc_flags "-D_XOPEN_SOURCE")
293 endif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
294
295 try_run(RUN_mcsc_VAR COMPILE_mcsc_VAR
296         ${PROJECT_DIRECTORY}
297         ${PROJECT_DIRECTORY}/buildtools/Cmake/test_prog/prog_AC_CHECK_MCSC.c
298         COMPILE_DEFINITIONS "${mcsc_flags}"
299         )
300         
301 if(EXISTS "${simgrid_BINARY_DIR}/conftestval")
302         file(READ "${simgrid_BINARY_DIR}/conftestval" mcsc)
303         STRING(REPLACE "\n" "" mcsc "${mcsc}")
304         if(mcsc)
305                 set(mcsc "yes")
306         elseif(mcsc)
307                 set(mcsc "no")
308         endif(mcsc)
309 else(EXISTS "${simgrid_BINARY_DIR}/conftestval")
310         set(mcsc "no")
311 endif(EXISTS "${simgrid_BINARY_DIR}/conftestval")
312
313 if(mcsc MATCHES "no" AND pthread)
314         if(HAVE_WINDOWS_H)
315                 set(windows_context "yes")
316                 set(IS_WINDOWS 1)
317         elseif(HAVE_WINDOWS_H)
318                 message(FATAL_ERROR "no appropriate backend found")
319         endif(HAVE_WINDOWS_H)
320 endif(mcsc MATCHES "no" AND pthread)
321
322 if(with_context MATCHES "ucontext" AND mcsc MATCHES "no")
323         message(FATAL_ERROR "-Dwith-context=ucontext specified but ucontext unusable.")
324 endif(with_context MATCHES "ucontext" AND mcsc MATCHES "no")
325
326 set(with_context_ok 0)
327 if(with_context MATCHES "windows")
328         set(with_context_ok 1)
329         if(NOT HAVE_WINDOWS_H)
330                 message(FATAL_ERROR "no appropriate backend found windows")
331         endif(NOT HAVE_WINDOWS_H)
332 endif(with_context MATCHES "windows")
333
334 if(with_context MATCHES "pthreads")
335         set(with_context_ok 1)
336         set(with_context "pthread")
337 endif(with_context MATCHES "pthreads")
338
339 if(with_context MATCHES "auto")
340         set(with_context_ok 1)
341         set(with_context "ucontext")
342         message("with_context auto change to ucontext")
343 endif(with_context MATCHES "auto")
344
345 if(with_context MATCHES "ucontext")
346         set(with_context_ok 1)
347         if(mcsc)
348                 set(CONTEXT_UCONTEXT 1)
349         else(mcsc)
350                 if(windows_context MATCHES "yes")
351                         set(with_context "windows")
352                         message("with_context ucontext change to windows")
353                 else(windows_context MATCHES "yes")
354                         set(with_context "pthread")
355                         message("with_context ucontext change to pthread")
356                 endif(windows_context MATCHES "yes")
357         endif(mcsc)
358 endif(with_context MATCHES "ucontext")
359
360 if(with_context MATCHES "pthread")
361         set(with_context_ok 1)
362         if(NOT pthread)
363                 message(FATAL_ERROR "Cannot find pthreads (try -Dwith_context=ucontext if you haven't already tried).")
364         endif(NOT pthread)
365         SET(CONTEXT_THREADS 1)
366 endif(with_context MATCHES "pthread")
367
368 if(with_context MATCHES "ucontext")
369         SET(CONTEXT_THREADS 0)
370 endif(with_context MATCHES "ucontext")
371
372 if(NOT with_context_ok)
373         message(FATAL_ERROR "-Dwith-context must be either ucontext or pthread")
374 endif(NOT with_context_ok)
375
376 ###############
377 ## SVN version check
378 ##
379 if(IS_DIRECTORY ${PROJECT_DIRECTORY}/.svn)
380         find_file(SVN ".svn" ${PROJECT_DIRECTORY})
381         exec_program("svnversion ${PROJECT_DIRECTORY}" OUTPUT_VARIABLE "SVN_VERSION")
382         message("SVN_VERSION : ${SVN_VERSION}")
383 endif(IS_DIRECTORY ${PROJECT_DIRECTORY}/.svn)
384
385 if(IS_DIRECTORY ${PROJECT_DIRECTORY}/.git)
386
387         exec_program("git --git-dir=${PROJECT_DIRECTORY}/.git log --oneline -1" OUTPUT_VARIABLE "GIT_VERSION")
388         exec_program("git --git-dir=${PROJECT_DIRECTORY}/.git log -n 1 --format=%ai ." OUTPUT_VARIABLE "GIT_DATE")
389         exec_program("git svn info" ${PROJECT_DIRECTORY} OUTPUT_VARIABLE "GIT_SVN_VERSION")
390         
391         string(REGEX REPLACE " .*" "" GIT_VERSION "${GIT_VERSION}")
392         string(REPLACE "\n" ";" GIT_SVN_VERSION ${GIT_SVN_VERSION})
393         STRING(REPLACE " +0000" "" GIT_DATE ${GIT_DATE})
394         STRING(REPLACE " " "~" GIT_DATE ${GIT_DATE})
395         STRING(REPLACE ":" "-" GIT_DATE ${GIT_DATE})
396         foreach(line ${GIT_SVN_VERSION})
397                 string(REGEX MATCH "^Revision:.*" line_good ${line})
398                 if(line_good)
399                         string(REPLACE "Revision: " "" line_good ${line_good})
400                         set(SVN_VERSION ${line_good})
401                 endif(line_good)
402         endforeach(line ${GIT_SVN_VERSION})
403 endif(IS_DIRECTORY ${PROJECT_DIRECTORY}/.git)
404
405 ###################################
406 ## SimGrid and GRAS specific checks
407 ##
408
409 # Check architecture signature begin
410 try_run(RUN_GRAS_VAR COMPILE_GRAS_VAR
411         ${PROJECT_DIRECTORY}
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         ${PROJECT_DIRECTORY}
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         ${PROJECT_DIRECTORY}
495         ${PROJECT_DIRECTORY}/buildtools/Cmake/test_prog/prog_max_size.c
496         RUN_OUTPUT_VARIABLE var3
497         )
498 SET(SIZEOF_MAX ${var3})
499
500 #--------------------------------------------------------------------------------------------------
501
502 set(makecontext_CPPFLAGS_2 "")
503 if(HAVE_MAKECONTEXT OR WIN32)
504         set(makecontext_CPPFLAGS "-DTEST_makecontext")
505         if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
506                 set(makecontext_CPPFLAGS_2 "-DOSX")
507         endif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
508         
509         if(WIN32)
510             set(makecontext_CPPFLAGS_2 "-D_XBT_WIN32 ${INCLUDES}")
511         endif(WIN32)
512
513         try_run(RUN_makecontext_VAR COMPILE_makecontext_VAR
514                 ${PROJECT_DIRECTORY}
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
533         try_run(RUN_makecontext_VAR COMPILE_makecontext_VAR
534                 ${PROJECT_DIRECTORY}
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 ###############
546 ## System checks
547 ##
548
549 #SG_CONFIGURE_PART([System checks...])
550 #AC_PROG_CC(xlC gcc cc) -auto
551 #AM_SANITY_CHECK -auto
552
553 #AC_PROG_MAKE_SET
554
555
556 #AC_PRINTF_NULL
557 try_run(RUN_PRINTF_NULL_VAR COMPILE_PRINTF_NULL_VAR
558         ${PROJECT_DIRECTORY}
559         ${PROJECT_DIRECTORY}/buildtools/Cmake/test_prog/prog_printf_null.c
560         )
561
562 if(RUN_PRINTF_NULL_VAR MATCHES "FAILED_TO_RUN")
563 SET(PRINTF_NULL_WORKING "0")
564 else(RUN_PRINTF_NULL_VAR MATCHES "FAILED_TO_RUN")
565 SET(PRINTF_NULL_WORKING "1")
566 endif(RUN_PRINTF_NULL_VAR MATCHES "FAILED_TO_RUN")
567
568 #AC_CHECK_VA_COPY
569
570 set(diff_va "va_copy((d),(s))"
571 "VA_COPY((d),(s))"
572 "__va_copy((d),(s))"
573 "__builtin_va_copy((d),(s))"
574 "do { (d) = (s)\; } while (0)"
575 "do { *(d) = *(s)\; } while (0)"
576 "memcpy((void *)&(d), (void *)&(s)), sizeof((s))"
577 "memcpy((void *)(d), (void *)(s)), sizeof(*(s))"
578 )
579
580 foreach(fct ${diff_va})
581         write_file("${PROJECT_DIRECTORY}/buildtools/Cmake/test_prog/prog_va_copy.c" "#include <stdlib.h>
582         #include <stdarg.h>
583         #include <string.h>
584         #define DO_VA_COPY(d,s) ${fct}
585         void test(char *str, ...)
586         {
587             va_list ap, ap2;
588             int i;
589             va_start(ap, str);
590             DO_VA_COPY(ap2, ap);
591             for (i = 1; i <= 9; i++) {
592                 int k = (int)va_arg(ap, int);
593                 if (k != i)
594                     abort();
595             }
596             DO_VA_COPY(ap, ap2);
597             for (i = 1; i <= 9; i++) {
598                 int k = (int)va_arg(ap, int);
599                 if (k != i)
600                     abort();
601             }
602             va_end(ap);
603         }
604         int main(int argc, char *argv[])
605         {
606             test("test", 1, 2, 3, 4, 5, 6, 7, 8, 9);
607             exit(0);
608         }"
609         )
610         try_compile(COMPILE_VA_NULL_VAR
611         ${PROJECT_DIRECTORY}
612         ${PROJECT_DIRECTORY}/buildtools/Cmake/test_prog/prog_va_copy.c
613         )
614         if(COMPILE_VA_NULL_VAR)
615                 string(REGEX REPLACE "\;" "" fctbis ${fct})
616                 if(${fctbis} STREQUAL "va_copy((d),(s))")
617                         set(HAVE_VA_COPY 1)
618                         set(ac_cv_va_copy "C99")
619                         set(__VA_COPY_USE_C99 "va_copy((d),(s))")       
620                 endif(${fctbis} STREQUAL "va_copy((d),(s))")
621
622                 if(${fctbis} STREQUAL "VA_COPY((d),(s))")
623                         set(ac_cv_va_copy "GCM")
624                         set(__VA_COPY_USE_GCM "VA_COPY((d),(s))")
625                 endif(${fctbis} STREQUAL "VA_COPY((d),(s))")
626
627                 if(${fctbis} STREQUAL "__va_copy((d),(s))")
628                         set(ac_cv_va_copy "GCH")
629                         set(__VA_COPY_USE_GCH "__va_copy((d),(s))")
630                 endif(${fctbis} STREQUAL "__va_copy((d),(s))")
631
632                 if(${fctbis} STREQUAL "__builtin_va_copy((d),(s))")
633                         set(ac_cv_va_copy "GCB")
634                         set(__VA_COPY_USE_GCB "__builtin_va_copy((d),(s))")
635                 endif(${fctbis} STREQUAL "__builtin_va_copy((d),(s))")
636
637                 if(${fctbis} STREQUAL "do { (d) = (s) } while (0)")
638                         set(ac_cv_va_copy "ASS")
639                         set(__VA_COPY_USE_ASS "do { (d) = (s); } while (0)")
640                 endif(${fctbis} STREQUAL "do { (d) = (s) } while (0)")
641
642                 if(${fctbis} STREQUAL "do { *(d) = *(s) } while (0)")
643                         set(ac_cv_va_copy "ASP")
644                         set(__VA_COPY_USE_ASP "do { *(d) = *(s); } while (0)")
645                 endif(${fctbis} STREQUAL "do { *(d) = *(s) } while (0)")
646
647                 if(${fctbis} STREQUAL "memcpy((void *)&(d), (void *)&(s)), sizeof((s))")
648                         set(ac_cv_va_copy "CPS")
649                         set(__VA_COPY_USE_CPS "memcpy((void *)&(d), (void *)&(s)), sizeof((s))")
650                 endif(${fctbis} STREQUAL "memcpy((void *)&(d), (void *)&(s)), sizeof((s))")
651
652                 if(${fctbis} STREQUAL "memcpy((void *)(d), (void *)(s)), sizeof(*(s))")
653                         set(ac_cv_va_copy "CPP")
654                         set(__VA_COPY_USE_CPP "memcpy((void *)(d), (void *)(s)), sizeof(*(s))")
655                 endif(${fctbis} STREQUAL "memcpy((void *)(d), (void *)(s)), sizeof(*(s))")
656                                 
657                 if(NOT STATUS_OK)
658                 set(__VA_COPY_USE "__VA_COPY_USE_${ac_cv_va_copy}(d, s)")
659                 endif(NOT STATUS_OK)
660                 set(STATUS_OK "1")
661                 
662         endif(COMPILE_VA_NULL_VAR)
663         
664 endforeach(fct ${diff_va})
665
666 #--------------------------------------------------------------------------------------------------
667 ### Try execut getline command
668 try_run(RUN_RESULT_VAR COMPILE_RESULT_VAR
669         ${PROJECT_DIRECTORY}
670         ${PROJECT_DIRECTORY}/buildtools/Cmake/test_prog/prog_getline.c
671         OUTPUT_VARIABLE GETLINE_OUTPUT
672         )
673
674 if(NOT COMPILE_RESULT_VAR)
675 SET(need_getline "#define SIMGRID_NEED_GETLINE 1")
676 else(NOT COMPILE_RESULT_VAR)
677 SET(need_getline "")
678 endif(NOT COMPILE_RESULT_VAR)
679
680 ### check for a working snprintf
681 if(HAVE_SNPRINTF AND HAVE_VSNPRINTF)
682
683         try_run(RUN_SNPRINTF_FUNC_VAR COMPILE_SNPRINTF_FUNC_VAR
684                 ${PROJECT_DIRECTORY}
685                 ${PROJECT_DIRECTORY}/buildtools/Cmake/test_prog/prog_snprintf.c
686                 )
687         if(CMAKE_CROSSCOMPILING)
688                 set(RUN_SNPRINTF_FUNC "cross") 
689         endif(CMAKE_CROSSCOMPILING)
690
691         try_run(RUN_VSNPRINTF_FUNC_VAR COMPILE_VSNPRINTF_FUNC_VAR
692                 ${PROJECT_DIRECTORY}
693                 ${PROJECT_DIRECTORY}/buildtools/Cmake/test_prog/prog_vsnprintf.c
694                 )
695         if(CMAKE_CROSSCOMPILING)
696                 set(RUN_VSNPRINTF_FUNC "cross")
697         endif(CMAKE_CROSSCOMPILING)
698         set(PREFER_PORTABLE_SNPRINTF 0)
699         if(RUN_VSNPRINTF_FUNC_VAR MATCHES "FAILED_TO_RUN")
700                 set(PREFER_PORTABLE_SNPRINTF 1)
701         endif(RUN_VSNPRINTF_FUNC_VAR MATCHES "FAILED_TO_RUN")
702         if(RUN_SNPRINTF_FUNC_VAR MATCHES "FAILED_TO_RUN")
703                 set(PREFER_PORTABLE_SNPRINTF 1)
704         endif(RUN_SNPRINTF_FUNC_VAR MATCHES "FAILED_TO_RUN")
705 endif(HAVE_SNPRINTF AND HAVE_VSNPRINTF)
706
707 ### check for asprintf function familly
708 if(HAVE_ASPRINTF)
709         SET(need_asprintf "")
710 else(HAVE_ASPRINTF)
711         SET(need_asprintf "#define SIMGRID_NEED_ASPRINTF 1")
712 endif(HAVE_ASPRINTF)
713
714 if(HAVE_VASPRINTF)
715         SET(need_vasprintf "")
716 else(HAVE_VASPRINTF)
717         SET(need_vasprintf "#define SIMGRID_NEED_VASPRINTF 1")
718 endif(HAVE_VASPRINTF)
719
720 ### check for addr2line
721
722 find_path(ADDR2LINE NAMES addr2line     PATHS NO_DEFAULT_PATHS  )
723 if(ADDR2LINE)
724 set(ADDR2LINE "${ADDR2LINE}/addr2line")
725 endif(ADDR2LINE)
726
727 ### File to create
728
729 configure_file("${PROJECT_DIRECTORY}/src/context_sysv_config.h.in"                      "${PROJECT_DIRECTORY}/src/context_sysv_config.h" @ONLY IMMEDIATE)
730
731 SET( CMAKEDEFINE "#cmakedefine" )
732 configure_file("${PROJECT_DIRECTORY}/buildtools/Cmake/gras_config.h.in"         "${PROJECT_DIRECTORY}/src/gras_config.h" @ONLY IMMEDIATE)
733 configure_file("${PROJECT_DIRECTORY}/src/gras_config.h"                                 "${PROJECT_DIRECTORY}/src/gras_config.h" @ONLY IMMEDIATE)
734 configure_file("${PROJECT_DIRECTORY}/include/simgrid_config.h.in"                       "${PROJECT_DIRECTORY}/include/simgrid_config.h" @ONLY IMMEDIATE)
735 configure_file("${PROJECT_DIRECTORY}/buildtools/Cmake/tracing_config.h.in"      "${PROJECT_DIRECTORY}/include/instr/tracing_config.h" @ONLY IMMEDIATE)
736 configure_file("${PROJECT_DIRECTORY}/include/instr/tracing_config.h"            "${PROJECT_DIRECTORY}/include/instr/tracing_config.h" @ONLY IMMEDIATE)
737
738 set(top_srcdir "${PROJECT_DIRECTORY}")
739 set(srcdir "${PROJECT_DIRECTORY}/src")
740
741 set(exec_prefix ${prefix})
742 set(includedir ${prefix}/include)
743 set(top_builddir ${PROJECT_DIRECTORY})
744 set(libdir ${exec_prefix}/lib)
745 set(CMAKE_LINKARGS "${CMAKE_CURRENT_BINARY_DIR}/lib")
746
747 configure_file(${PROJECT_DIRECTORY}/src/smpi/smpicc.in ${CMAKE_CURRENT_BINARY_DIR}/bin/smpicc @ONLY)
748 configure_file(${PROJECT_DIRECTORY}/src/smpi/smpirun.in ${CMAKE_CURRENT_BINARY_DIR}/bin/smpirun @ONLY)
749
750 exec_program("chmod a=rwx ${CMAKE_CURRENT_BINARY_DIR}/bin/smpicc" OUTPUT_VARIABLE OKITOKI)
751 exec_program("chmod a=rwx ${CMAKE_CURRENT_BINARY_DIR}/bin/smpirun" OUTPUT_VARIABLE OKITOKI)