Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
4f95937385066fc3c23c3b4eb9099f4f456ca029
[simgrid.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.8.8)
2 message(STATUS "Cmake version ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}")
3 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_HOME_DIRECTORY}/tools/cmake/Modules)
4
5 project(SimGrid C CXX)
6
7 #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
8 #     Check for the compiler        #
9 #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
10
11 ### Need to set rc ccompiler before enable language
12 if(WIN32)
13   SET(CMAKE_RC_COMPILER "windres")
14 endif()
15
16 ## 
17 ## Check the C/C++ standard that we need
18 ##   See also tools/cmake/GCCFlags.cmake that sets our paranoid warning flags
19 INCLUDE(CheckCCompilerFlag)
20 CHECK_C_COMPILER_FLAG(-fstack-cleaner HAVE_C_STACK_CLEANER)
21
22 ## Request full debugging flags
23 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g3")
24 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3")
25 set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -g")
26
27 if (CMAKE_COMPILER_IS_GNUCC)    
28   if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.7")
29     message(FATAL_ERROR
30             "SimGrid needs at least g++ version 4.7 to compile but you have ${CMAKE_CXX_COMPILER_VERSION}."
31             "You need a sufficient support of c++11 to compile SimGrid.")
32   endif()
33 endif()
34
35 ## We need a decent support of the c++11 standard
36 include(CheckCXXCompilerFlag)
37 CHECK_CXX_COMPILER_FLAG("-std=gnu++11" COMPILER_SUPPORTS_CXX11)
38 if(COMPILER_SUPPORTS_CXX11)
39   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
40 else() 
41   message(FATAL_ERROR 
42           "The compiler ${CMAKE_CXX_COMPILER} (v${CMAKE_CXX_COMPILER_VERSION}) has no C++11 support. "
43            "Please use a decent C++ compiler.")
44 endif()
45
46 ### And we need C11 standard, too
47 include(CheckCCompilerFlag)
48 CHECK_C_COMPILER_FLAG("-std=gnu11" COMPILER_SUPPORTS_C11)
49 if(COMPILER_SUPPORTS_C11)
50   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11")
51 else()
52   message(FATAL_ERROR 
53           "The compiler ${CMAKE_C_COMPILER} (v${CMAKE_C_COMPILER_VERSION}) has no C11 support. "
54           "Please use a decent C compiler "
55           "(note that c++11 support of ${CMAKE_CXX_COMPILER} seems ok).")
56 endif()
57 if(APPLE AND (CMAKE_C_COMPILER_VERSION VERSION_LESS "4.6"))
58   ### gcc 4.[1-5] cannot compile ucontext on OSX
59   message(STATUS "Ucontext can't be used with this version of gcc (must be greater than 4.5)")
60   set(HAVE_UCONTEXT_H 0)
61 endif()
62
63
64 ### Setup Options
65 include(${CMAKE_HOME_DIRECTORY}/tools/cmake/Option.cmake)
66
67 ### SMPI vs. Fortran
68 if ((NOT DEFINED enable_smpi) OR enable_smpi) 
69   # First unset the compiler in case we're re-running cmake over a previous
70   # configuration where it was saved as smpiff
71   unset(CMAKE_Fortran_COMPILER)
72   
73   SET(SMPI_FORTRAN 0)
74   if(enable_fortran)
75     enable_language(Fortran OPTIONAL)
76   endif()
77   
78   if(CMAKE_Fortran_COMPILER)
79     # Fortran compiler detected: save it, then replace by smpiff
80     set(SAVED_Fortran_COMPILER "${CMAKE_Fortran_COMPILER}" CACHE FILEPATH "The real Fortran compiler")
81     set(CMAKE_Fortran_COMPILER smpiff)
82     set(SMPI_FORTRAN 1)
83   endif(CMAKE_Fortran_COMPILER)
84
85 endif()
86
87 #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
88 #     Build the version number      #
89 #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
90
91 set(SIMGRID_VERSION_MAJOR "3")
92 set(SIMGRID_VERSION_MINOR "13")
93 set(SIMGRID_VERSION_PATCH "90")
94 set(SIMGRID_VERSION_EXTRA "-prealpha") # Extra words to add to version string (e.g. -rc1)
95
96 set(SIMGRID_VERSION_DATE  "2016") # Year for copyright information
97
98 if(${SIMGRID_VERSION_PATCH} EQUAL "0")
99   set(release_version "${SIMGRID_VERSION_MAJOR}.${SIMGRID_VERSION_MINOR}")
100 else()
101   set(release_version "${SIMGRID_VERSION_MAJOR}.${SIMGRID_VERSION_MINOR}.${SIMGRID_VERSION_PATCH}")
102 endif()
103
104 set(SIMGRID_VERSION_STRING "SimGrid version ${release_version}${SIMGRID_VERSION_EXTRA}")
105
106 set(libsimgrid_version "${release_version}")
107 set(libsimgrid-java_version "${release_version}")
108
109 ### SET THE LIBRARY EXTENSION 
110 if(APPLE)
111   set(LIB_EXE "dylib")
112 elseif(WIN32)
113   set(LIB_EXE "a")
114   set(BIN_EXE ".exe")
115 else()
116   set(LIB_EXE "so")
117 endif()
118
119 execute_process(COMMAND   ${CMAKE_LINKER}   -version    OUTPUT_VARIABLE LINKER_VERSION)
120 string(REGEX MATCH "[0-9].[0-9]*" LINKER_VERSION "${LINKER_VERSION}")
121
122 ### Set the library providing dlopen
123 if("${CMAKE_SYSTEM}" MATCHES "Linux")
124   find_library(DL_LIBRARY dl)
125 endif("${CMAKE_SYSTEM}" MATCHES "Linux")
126
127 ### Find programs and paths
128 FIND_PROGRAM(GCOV_PATH gcov)
129 include(FindPerl)
130 if(NOT PERL_FOUND)
131   message(FATAL_ERROR "Please install Perl to compile SimGrid.")
132 endif()
133
134 # tesh.py needs python 3 (or the module python-subprocess32 on python2.8+)
135 set(PythonInterp_FIND_VERSION 3)
136 set(PythonInterp_FIND_VERSION_COUNT 1)
137 set(PythonInterp_FIND_VERSION_MAJOR 3)
138 include(FindPythonInterp)
139 if(NOT PYTHONINTERP_FOUND)
140   message(FATAL_ERROR "Please install Python (version 3 or higher).")
141 endif()
142
143 if (APPLE)
144   set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
145   set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
146 endif()
147 SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
148
149 ### Compute the include paths
150 set(INCLUDES
151   ${CMAKE_HOME_DIRECTORY}
152   ${CMAKE_HOME_DIRECTORY}/include
153   ${CMAKE_HOME_DIRECTORY}/src/include
154   ${CMAKE_BINARY_DIR}
155   ${CMAKE_BINARY_DIR}/include
156   )
157
158 if(NOT CMAKE_CROSSCOMPILING AND EXISTS /usr/include/)
159   set(INCLUDES ${INCLUDES} /usr/include/)
160 endif()
161
162 if(WIN32)
163   set(CMAKE_INCLUDE_WIN "${CMAKE_C_COMPILER}")
164   set(CMAKE_LIB_WIN "${CMAKE_C_COMPILER}")
165   string(REGEX REPLACE "/bin/gcc.*" "/include"  CMAKE_INCLUDE_WIN "${CMAKE_INCLUDE_WIN}")
166   string(REGEX REPLACE "/bin/gcc.*" "/lib"  CMAKE_LIB_WIN "${CMAKE_LIB_WIN}")
167   set(INCLUDES ${INCLUDES} ${CMAKE_INCLUDE_WIN})
168   unset(CMAKE_INCLUDE_WIN)
169 endif()
170
171 include_directories(${INCLUDES})
172
173 # library dependency cannot start with a space (CMP0004), so initialize it with something that is never desactivated.
174 set(SIMGRID_DEP "-lm") 
175
176 ### Determine the assembly flavor that we need today
177 set(HAVE_RAW_CONTEXTS 0)
178 include(CMakeDetermineSystem)
179 IF(CMAKE_SYSTEM_PROCESSOR MATCHES ".86|AMD64|amd64")
180   IF(CMAKE_SIZEOF_VOID_P EQUAL 4) # 32 bits
181     message(STATUS "System processor: i686 (${CMAKE_SYSTEM_PROCESSOR}, 32 bits)")
182     set(PROCESSOR_i686 1)
183     set(PROCESSOR_x86_64 0)
184   ELSE()
185     message(STATUS "System processor: x86_64 (${CMAKE_SYSTEM_PROCESSOR}, 64 bits)")
186     set(PROCESSOR_i686 0)
187     set(PROCESSOR_x86_64 1)
188   ENDIF()
189   if (WIN32)
190     message(STATUS "Disable fast raw contexts on Windows.")
191   else()
192     set(HAVE_RAW_CONTEXTS 1)
193   endif()
194 ELSE()
195   set(PROCESSOR_i686 0)
196   set(PROCESSOR_x86_64 0)
197 ENDIF()
198
199 include(CheckFunctionExists)
200 include(CheckTypeSize)
201 include(CheckIncludeFile)
202 include(CheckIncludeFiles)
203 include(CheckLibraryExists)
204 include(CheckSymbolExists)
205
206 set(HAVE_GRAPHVIZ 0)
207 include(FindGraphviz)
208
209 set(HAVE_LUA 0)
210 if(enable_lua)
211   include(FindLuaSimgrid)
212 endif()
213
214 set(HAVE_NS3 0)
215 if(enable_ns3)
216   include(FindNS3)
217   if (NOT HAVE_NS3)
218     message(FATAL_ERROR "Cannot find NS3. Please install it (apt-get install ns3 libns3-dev) or disable that cmake option")
219   endif()
220 endif()
221
222 if(WIN32)
223   set(Boost_USE_STATIC_LIBS 1)
224 endif()
225 set(HAVE_PAPI 0)
226 if(enable_smpi_papi)
227   include(FindPAPI)
228   if (NOT HAVE_PAPI)
229     message(FATAL_ERROR "Cannot find PAPI. Please install it (apt-get install papi-tools libpapi-dev) or disable PAPI bindings.")
230   endif()
231 endif()
232
233 find_package(Boost 1.48 COMPONENTS unit_test_framework)
234 if(Boost_FOUND)
235   include_directories(${Boost_INCLUDE_DIRS})
236 else()
237   if(APPLE)
238     message(FATAL_ERROR "Boost libraries not found. Try to install them with 'sudo fink install boost1.53.nopython'")
239   else()
240     message(FATAL_ERROR "Boost libraries not found. Install libboost-dev libboost-test-dev (>= 1.48.0).")
241   endif()
242 endif()
243
244 #Boost context 1.61 will break compatibility with our implementation.
245 #Warn users about that
246 find_package(Boost 1.61 COMPONENTS context)
247
248 if(Boost_FOUND AND Boost_CONTEXT_FOUND)
249   message("WARNING : our implementation of Boost context factory is not compatible with Boost >=1.61 yet.")
250
251   set(Boost_FOUND 1)
252   set(HAVE_BOOST_CONTEXTS 0)
253 else()
254 # Try again to see if we have libboost-context
255   find_package(Boost 1.42 COMPONENTS context)
256   set(Boost_FOUND 1) # We don't care of whether this component is missing
257
258   if(Boost_FOUND AND Boost_CONTEXT_FOUND)
259     # We should use feature detection for this instead:
260     if (Boost_VERSION LESS 105600)
261       message("Found Boost.Context API v1")
262       set(HAVE_BOOST_CONTEXTS 1)
263     else()
264       message("Found Boost.Context API v2")
265       set(HAVE_BOOST_CONTEXTS 2)
266     endif()
267   else()
268     message ("   boost        : found.")
269     message ("   boost-context: missing. Install libboost-context-dev for this optional feature.")
270     set(HAVE_BOOST_CONTEXTS 0)
271   endif()
272 endif()
273
274 # Checks for header libraries functions.
275 CHECK_LIBRARY_EXISTS(rt      clock_gettime           "" HAVE_POSIX_GETTIME)
276
277 CHECK_LIBRARY_EXISTS(pthread pthread_create          "" HAVE_PTHREAD)
278 if(NOT APPLE) # OS X El Capitan deprecates this function
279   CHECK_LIBRARY_EXISTS(pthread sem_init                "" HAVE_SEM_INIT_LIB)
280 endif()
281 CHECK_LIBRARY_EXISTS(pthread sem_open                "" HAVE_SEM_OPEN_LIB)
282 set(HAVE_PTHREAD_SETAFFINITY 0)
283 CHECK_LIBRARY_EXISTS(pthread pthread_setaffinity_np  "" HAVE_PTHREAD_SETAFFINITY)
284
285 if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
286   set(CMAKE_REQUIRED_DEFINITIONS "-D_XOPEN_SOURCE=700 -D_DARWIN_C_SOURCE")
287 elseif(MINGW)
288   # Use the GNU version of unusual modifiers like PRIx64
289   add_definitions(-D__USE_MINGW_ANSI_STDIO=1)
290   set(CMAKE_REQUIRED_DEFINITIONS "-D__USE_MINGW_ANSI_STDIO=1")
291 else()
292   set(CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE")
293 endif()
294
295 CHECK_INCLUDE_FILE("valgrind/valgrind.h" HAVE_VALGRIND_H)
296 CHECK_INCLUDE_FILE("unistd.h" HAVE_UNISTD_H)
297 CHECK_INCLUDE_FILE("execinfo.h" HAVE_EXECINFO_H)
298 CHECK_INCLUDE_FILE("signal.h" HAVE_SIGNAL_H)
299 CHECK_INCLUDE_FILE("sys/param.h" HAVE_SYS_PARAM_H)
300 CHECK_INCLUDE_FILE("sys/sysctl.h" HAVE_SYS_SYSCTL_H)
301 CHECK_INCLUDE_FILE("ucontext.h" HAVE_UCONTEXT_H)
302 CHECK_INCLUDE_FILE("linux/futex.h" HAVE_FUTEX_H)
303
304 CHECK_FUNCTION_EXISTS(backtrace HAVE_BACKTRACE)
305 CHECK_FUNCTION_EXISTS(dlfunc HAVE_DLFUNC)
306 CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
307 CHECK_FUNCTION_EXISTS(nanosleep HAVE_NANOSLEEP)
308 CHECK_FUNCTION_EXISTS(getdtablesize HAVE_GETDTABLESIZE)
309 CHECK_FUNCTION_EXISTS(sysconf HAVE_SYSCONF)
310 CHECK_FUNCTION_EXISTS(popen HAVE_POPEN)
311 CHECK_FUNCTION_EXISTS(process_vm_readv HAVE_PROCESS_VM_READV)
312 CHECK_FUNCTION_EXISTS(mmap HAVE_MMAP)
313 CHECK_FUNCTION_EXISTS(mremap HAVE_MREMAP)
314
315 CHECK_SYMBOL_EXISTS(vasprintf stdio.h HAVE_VASPRINTF)
316 if(MINGW)
317   # The detection of vasprintf fails on MinGW, assumingly because it's
318   # defined as an inline function in stdio.h instead of a regular
319   # function. So force the result to be 1 despite of the test.
320   set(HAVE_VASPRINTF 1)
321 endif()
322
323 #Check if __thread is defined
324 execute_process(
325   COMMAND "${CMAKE_C_COMPILER} ${CMAKE_HOME_DIRECTORY}/tools/cmake/test_prog/prog_thread_storage.c -o testprog"
326   WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
327   RESULT_VARIABLE HAVE_thread_storage_run)
328 file(REMOVE testprog)
329 if(HAVE_thread_storage_run)
330   set(HAVE_THREAD_LOCAL_STORAGE 1)
331 else()
332   set(HAVE_THREAD_LOCAL_STORAGE 0)
333 endif()
334
335 if(enable_model-checking AND NOT "${CMAKE_SYSTEM}" MATCHES "Linux|FreeBSD")
336   message(WARNING "Support for model-checking has not been enabled on ${CMAKE_SYSTEM}: disabling it")
337   set(enable_model-checking FALSE)
338 endif()
339
340 if(HAVE_MMAP AND HAVE_THREAD_LOCAL_STORAGE)
341   SET(HAVE_MMALLOC 1)
342 else()
343   SET(HAVE_MMALLOC 0)
344   if(enable_model-checking)
345     message(STATUS "Warning: support for model-checking has been disabled because you are missing either mmap or __thread.")
346   endif()
347   SET(enable_model-checking 0)
348 endif()
349
350 if(enable_jedule)
351   set(HAVE_JEDULE 1)
352 else()
353   set(HAVE_JEDULE 0)
354 endif()
355
356 if(enable_mallocators)
357   SET(HAVE_MALLOCATOR 1)
358 else()
359   SET(HAVE_MALLOCATOR 0)
360 endif()
361
362 include(FindLibunwind)
363 if(HAVE_LIBUNWIND)
364   if(NOT APPLE)
365     SET(SIMGRID_DEP "${SIMGRID_DEP} -lunwind")
366   else()
367     # Apple forbids to link directly against its libunwind implementation
368     # So let's comply and link against the System framework
369     SET(SIMGRID_DEP "${SIMGRID_DEP} -lSystem")
370   endif()
371   if("${CMAKE_SYSTEM}" MATCHES "Linux|FreeBSD")
372     set(SIMGRID_DEP "${SIMGRID_DEP} -lunwind-ptrace")
373     # This supposes that the host machine is either an AMD or a X86.
374     # This is deeply wrong, and should be fixed by manually loading -lunwind-PLAT (FIXME)
375     if(PROCESSOR_x86_64)
376       SET(SIMGRID_DEP "${SIMGRID_DEP} -lunwind-x86_64")
377     else()
378       SET(SIMGRID_DEP "${SIMGRID_DEP} -lunwind-x86")
379     endif()
380   endif()
381 else()
382   if(enable_model-checking)
383     message(FATAL_ERROR "Please either install the libunwind7-dev package (or equivalent) or turn off the model-checking option of SimGrid.")
384   endif()
385 endif()
386
387 if(enable_model-checking)
388   find_package(Libdw REQUIRED)
389   find_package(Libevent REQUIRED)
390   include_directories(${LIBDW_INCLUDE_DIRS} ${LIBEVENT_INCLUDE_DIRS})
391   set(SIMGRID_DEP "${SIMGRID_DEP} ${LIBEVENT_LIBRARIES} ${LIBDW_LIBRARIES}")
392   set(HAVE_MC 1)
393   if("${CMAKE_SYSTEM}" MATCHES "FreeBSD" AND enable_java)
394     message(WARNING "FreeBSD + Model-Checking + Java = too much for now. Disabling java")
395     set(enable_java FALSE)
396   endif()
397 else()
398   SET(HAVE_MC 0)  
399   set(HAVE_MMALLOC 0)
400 endif()
401
402 if (enable_model-checking AND enable_ns3)
403   message(FATAL_ERROR "Cannot activate both model-checking and NS3 bindings: NS3 pull too much dependencies for the MC to work")
404 endif()
405
406 if(enable_smpi)
407   SET(HAVE_SMPI 1)
408   if("${CMAKE_SYSTEM}" MATCHES "Linux|FreeBSD")
409     SET(USE_LIBUTIL 0)
410     SET(HAVE_PRIVATIZATION 1)
411   else()
412     message (STATUS "Warning:  no support for SMPI automatic privatization on this platform")
413     SET(HAVE_PRIVATIZATION 0)
414   endif()
415 else()
416   SET(HAVE_SMPI 0)
417 endif()
418
419 #--------------------------------------------------------------------------------------------------
420 ### Check for GNU dynamic linker
421 CHECK_INCLUDE_FILE("dlfcn.h" HAVE_DLFCN_H)
422 if (HAVE_DLFCN_H)
423   execute_process(COMMAND ${CMAKE_C_COMPILER} ${CMAKE_HOME_DIRECTORY}/tools/cmake/test_prog/prog_gnu_dynlinker.c ${DL_LIBRARY} -o test_gnu_ld
424                   WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
425                   OUTPUT_VARIABLE HAVE_GNU_LD_compil
426   )
427   if(HAVE_GNU_LD_compil)
428     set(HAVE_GNU_LD 0)
429     message(STATUS "Warning: test program toward GNU ld failed to compile:")
430     message(STATUS "${HAVE_GNU_LD_comp_output}")
431   else()
432     execute_process(COMMAND ./test_gnu_ld
433                     WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
434                     RESULT_VARIABLE HAVE_GNU_LD_run
435                     OUTPUT_VARIABLE var_exec
436                    )
437
438     if(NOT HAVE_GNU_LD_run)
439       set(HAVE_GNU_LD 1)
440       message(STATUS "We are using GNU dynamic linker")
441     else()
442       set(HAVE_GNU_LD 0)
443       message(STATUS "Warning: error while checking for GNU ld:")
444       message(STATUS "Test output: '${var_exec}'")
445       message(STATUS "Exit status: ${HAVE_GNU_LD_run}")
446     endif()
447     file(REMOVE test_gnu_ld)
448   endif()
449 endif()
450
451 #--------------------------------------------------------------------------------------------------
452 ### Initialize of CONTEXT THREADS
453
454 set(HAVE_THREAD_CONTEXTS 0)
455 if(HAVE_PTHREAD)
456   ### Test that we have a way to create semaphores
457
458   if(HAVE_SEM_OPEN_LIB)
459     execute_process(COMMAND ${CMAKE_C_COMPILER} ${CMAKE_HOME_DIRECTORY}/tools/cmake/test_prog/prog_sem_open.c -lpthread -o sem_open
460       WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
461       OUTPUT_VARIABLE HAVE_SEM_OPEN_compil
462     )
463
464     # Test sem_open by compiling:
465     if(HAVE_SEM_OPEN_compil)
466       set(HAVE_SEM_OPEN 0)
467       message(STATUS "Warning: sem_open not compilable")
468       message(STATUS "HAVE_SEM_OPEN_comp_output: ${HAVE_SEM_OPEN_comp_output}")
469     else()
470       set(HAVE_SEM_OPEN 1)
471       message(STATUS "sem_open is compilable")
472     endif()
473
474     # If we're not crosscompiling, we check by executing the program:
475     if (HAVE_SEM_OPEN AND NOT CMAKE_CROSSCOMPILING)
476       execute_process(COMMAND ./sem_open
477         WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
478         RESULT_VARIABLE HAVE_SEM_OPEN_run
479         OUTPUT_VARIABLE var_compil
480       )
481       if (NOT HAVE_SEM_OPEN_run)
482         set(HAVE_SEM_OPEN 1)
483         message(STATUS "sem_open is executable")
484       else()
485         set(HAVE_SEM_OPEN 0)
486         if(EXISTS "${CMAKE_BINARY_DIR}/sem_open")
487           message(STATUS "Bin ${CMAKE_BINARY_DIR}/sem_open exists!")
488         else()
489           message(STATUS "Bin ${CMAKE_BINARY_DIR}/sem_open not exists!")
490         endif()
491         message(STATUS "Warning: sem_open not executable")
492         message(STATUS "Compilation output: '${var_compil}'")
493         message(STATUS "Exit result of sem_open: ${HAVE_SEM_OPEN_run}")
494       endif()
495     endif()
496     file(REMOVE sem_open)
497   else()
498     set(HAVE_SEM_OPEN 0)
499   endif()
500
501   if(HAVE_SEM_INIT_LIB)
502     execute_process(COMMAND ${CMAKE_C_COMPILER} ${CMAKE_HOME_DIRECTORY}/tools/cmake/test_prog/prog_sem_init.c -lpthread -o sem_init
503       WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
504       RESULT_VARIABLE HAVE_SEM_INIT_run 
505       OUTPUT_VARIABLE HAVE_SEM_INIT_compil)
506
507     # Test sem_init by compiling:
508     if(HAVE_SEM_INIT_compil)
509       set(HAVE_SEM_INIT 0)
510       message(STATUS "Warning: sem_init not compilable")
511       message(STATUS "HAVE_SEM_INIT_comp_output: ${HAVE_SEM_OPEN_comp_output}")
512     else()
513       set(HAVE_SEM_INIT 1)
514       message(STATUS "sem_init is compilable")
515     endif()
516
517     # If we're not crosscompiling, we check by executing the program:
518     if (HAVE_SEM_INIT AND NOT CMAKE_CROSSCOMPILING)
519       execute_process(COMMAND ./sem_init
520         WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
521         RESULT_VARIABLE HAVE_SEM_INIT_run
522         OUTPUT_VARIABLE var_compil
523       )
524       if (NOT HAVE_SEM_INIT_run)
525         set(HAVE_SEM_INIT 1)
526         message(STATUS "sem_init is executable")
527       else()
528         set(HAVE_SEM_INIT 0)
529         if(EXISTS "${CMAKE_BINARY_DIR}/sem_init")
530           message(STATUS "Bin ${CMAKE_BINARY_DIR}/sem_init exists!")
531         else()
532           message(STATUS "Bin ${CMAKE_BINARY_DIR}/sem_init not exists!")
533         endif()
534         message(STATUS "Warning: sem_init not executable")
535         message(STATUS "Compilation output: '${var_compil}'")
536         message(STATUS "Exit result of sem_init: ${HAVE_SEM_INIT_run}")
537       endif()
538     endif()
539     file(REMOVE sem_init)
540   else() 
541     set(HAVE_SEM_INIT 0)  
542   endif()
543
544   if(NOT HAVE_SEM_OPEN AND NOT HAVE_SEM_INIT)
545     message(FATAL_ERROR "Semaphores are not usable (neither sem_open nor sem_init is both compilable and executable), but they are mandatory to threads (you may need to mount /dev).")
546   endif()
547
548   set(HAVE_THREAD_CONTEXTS 1)
549   message("-- Support for thread context factory ok.")
550 endif()
551
552 set(HAVE_UCONTEXT_CONTEXTS 0)
553 if(NOT HAVE_UCONTEXT_H)
554   message("-- No ucontext factory: <ucontext.h> not found.")
555 elseif(APPLE)
556   message("-- No ucontext factory: Apple don't want us to use them.")
557   set(HAVE_UCONTEXT_H 0)
558 else()
559   try_compile(compile_makecontext ${CMAKE_BINARY_DIR} ${CMAKE_HOME_DIRECTORY}/tools/cmake/test_prog/prog_makecontext.c
560     OUTPUT_VARIABLE compile_makecontext_output)
561
562   #If can have both context
563   if(compile_makecontext)
564     set(HAVE_UCONTEXT_CONTEXTS 1)
565     message("-- Support for ucontext factory ok.")
566   else()
567     message("-- Error: <ucontext.h> exists, but makecontext is not compilable. Compilation output:\n ${compile_makecontext_output}")
568     message("-- No ucontext factory: makecontext() is not compilable.")
569   endif()
570
571   # Stack setup (size and address)
572   try_run(RUN_makecontext_VAR COMPILE_makecontext_VAR
573     ${CMAKE_BINARY_DIR} ${CMAKE_HOME_DIRECTORY}/tools/cmake/test_prog/prog_stacksetup.c
574     RUN_OUTPUT_VARIABLE stack_setup)
575
576   LIST(LENGTH stack_setup stack_setup_len)
577   if("${stack_setup_len}" STREQUAL "2")
578     LIST(GET stack_setup 0 makecontext_addr)
579     LIST(GET stack_setup 1 makecontext_size)
580     set(sg_makecontext_stack_addr "#define sg_makecontext_stack_addr(skaddr) (${makecontext_addr})")
581     set(sg_makecontext_stack_size "#define sg_makecontext_stack_size(sksize) (${makecontext_size})")
582   else()
583     message(FATAL_ERROR "Could not figure out the stack setup. Compil: ${RUN_makecontext_VAR}. Exec: ${COMPILE_makecontext_VAR}. Output: ${stack_setup}")
584   endif()
585 endif()
586
587 # Stack growth direction (upward or downward). Used for the following contexts: SysV, raw, Boost
588 try_run(RUN_stackgrowth_VAR COMPILE_stackgrowth_VAR
589   ${CMAKE_BINARY_DIR}
590   ${CMAKE_HOME_DIRECTORY}/tools/cmake/test_prog/prog_stackgrowth.c
591   RUN_OUTPUT_VARIABLE stack
592   COPY_FILE test_stackgrowth)
593
594 if("${stack}" STREQUAL "down")
595   set(PTH_STACKGROWTH "-1")
596 elseif("${stack}" STREQUAL "up")
597   set(PTH_STACKGROWTH "1")
598 else()
599   if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
600     set(PTH_STACKGROWTH "-1")
601   elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i686")
602     set(PTH_STACKGROWTH "-1")
603   else()
604     message(FATAL_ERROR "Could not figure out the stack direction. Test prog returned: ${stack}; CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}.")
605   endif()
606 endif()
607 # If the test ran well, remove the test binary
608 file(REMOVE test_stackgrowth)
609 #--------------------------------------------------------------------------------------------------
610
611 ### check for addr2line
612 find_path(ADDR2LINE NAMES addr2line     PATHS NO_DEFAULT_PATHS)
613 if(ADDR2LINE)
614   set(ADDR2LINE "${ADDR2LINE}/addr2line")
615 endif()
616
617 ###############
618 ## GIT version check
619 ##
620 if(EXISTS ${CMAKE_HOME_DIRECTORY}/.git/)
621   execute_process(
622      COMMAND git remote
623      COMMAND head -n 1
624      WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/.git/
625      OUTPUT_VARIABLE remote
626      OUTPUT_STRIP_TRAILING_WHITESPACE)
627   #message(STATUS "Git remote: ${remote}")
628   execute_process(COMMAND git config --get remote.${remote}.url
629      WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/.git/
630      OUTPUT_VARIABLE url
631      OUTPUT_STRIP_TRAILING_WHITESPACE)
632   #message(STATUS "Git url: ${url}")
633   if(url)
634     execute_process(COMMAND git --git-dir=${CMAKE_HOME_DIRECTORY}/.git log --pretty=oneline --abbrev-commit -1
635        WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/.git/
636        OUTPUT_VARIABLE GIT_VERSION
637        OUTPUT_STRIP_TRAILING_WHITESPACE)
638     message(STATUS "Git version: ${GIT_VERSION}")
639
640     execute_process(COMMAND git --git-dir=${CMAKE_HOME_DIRECTORY}/.git log -n 1 --pretty=format:%ai .
641        WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/.git/
642        OUTPUT_VARIABLE GIT_DATE 
643        OUTPUT_STRIP_TRAILING_WHITESPACE)
644     message(STATUS "Git date: ${GIT_DATE}")
645     string(REGEX REPLACE " .*" "" GIT_VERSION "${GIT_VERSION}")
646
647     execute_process(COMMAND git --git-dir=${CMAKE_HOME_DIRECTORY}/.git log --pretty=format:%H -1
648        WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/.git/
649        OUTPUT_VARIABLE SIMGRID_GITHASH
650        OUTPUT_STRIP_TRAILING_WHITESPACE)
651   endif()
652 elseif(EXISTS ${CMAKE_HOME_DIRECTORY}/.gitversion)
653   FILE(STRINGS ${CMAKE_HOME_DIRECTORY}/.gitversion GIT_VERSION)
654 endif()
655
656 ### Generate the required headers and scripts
657 #############################################
658
659 # gcc makes no difference between "#define HAVE_FOOBAR" and "#define HAVE_FOOBAR 0" by default, 
660 # but this too error prone. If you forget to include the config.h, you get weird segfaults.
661 # If you include it everywhere, everything gets recompiled everytime.
662 # So we include only where needed, and compile with -Wundef to notice the missing includes.
663 # But cmake sometimes defines to the empty definition (#define HAVE_VALGRIND_H).
664 # So we have to make sure that everything got a decent value before generating the files.
665 foreach(var HAVE_BACKTRACE HAVE_EXECINFO_H HAVE_FUTEX_H HAVE_GETDTABLESIZE HAVE_GETTIMEOFDAY HAVE_MMAP HAVE_NANOSLEEP HAVE_POPEN
666             HAVE_POSIX_GETTIME HAVE_PROCESS_VM_READV HAVE_SIGNAL_H HAVE_SYS_PARAM_H HAVE_SYS_SYSCTL_H HAVE_SYSCONF 
667             HAVE_UCONTEXT_H HAVE_UNISTD_H HAVE_VALGRIND_H HAVE_VASPRINTF HAVE_MREMAP HAVE_DLFUNC)
668   if(${var})
669     set(${var} 1)
670   else()
671     set(${var} 0)
672   endif()
673 endforeach()
674
675 # Avoid triggering a (full) rebuild by touching the files if they did not really change
676 configure_file("${CMAKE_HOME_DIRECTORY}/tools/cmake/src/internal_config.h.in" "${CMAKE_BINARY_DIR}/src/internal_config.h.generated"    @ONLY IMMEDIATE)
677 configure_file("${CMAKE_HOME_DIRECTORY}/include/simgrid_config.h.in"          "${CMAKE_BINARY_DIR}/include/simgrid_config.h.generated" @ONLY IMMEDIATE)
678 execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_BINARY_DIR}/src/internal_config.h.generated ${CMAKE_BINARY_DIR}/src/internal_config.h)
679 execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_BINARY_DIR}/include/simgrid_config.h.generated ${CMAKE_BINARY_DIR}/include/simgrid_config.h)
680 file(REMOVE ${CMAKE_BINARY_DIR}/src/internal_config.h.generated)
681 file(REMOVE ${CMAKE_BINARY_DIR}/include/simgrid_config.h.generated)
682
683 # We need two versions of the SMPI scripts because they contain the path to the library
684 # so, it depends of whether SimGrid is installed, or run from the sources (during the build)
685
686 file(READ ${CMAKE_HOME_DIRECTORY}/src/smpi/smpitools.sh SMPITOOLS_SH) # Definitions shared amongst all SMPI scripts, inlined in each of them
687
688 ### SMPI script used when simgrid is installed
689 set(exec_prefix ${CMAKE_INSTALL_PREFIX})
690 set(includeflag "-I${CMAKE_INSTALL_PREFIX}/include -I${CMAKE_INSTALL_PREFIX}/include/smpi")
691 set(includedir "${CMAKE_INSTALL_PREFIX}/include")
692 set(libdir ${exec_prefix}/lib)
693 set(CMAKE_SMPI_COMMAND "export LD_LIBRARY_PATH=\"${CMAKE_INSTALL_PREFIX}/lib")
694 if(NS3_LIBRARY_PATH)
695   set(CMAKE_SMPI_COMMAND "${CMAKE_SMPI_COMMAND}:${NS3_LIBRARY_PATH}")
696 endif()
697 set(CMAKE_SMPI_COMMAND "${CMAKE_SMPI_COMMAND}:\${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}\"")
698
699 configure_file(${CMAKE_HOME_DIRECTORY}/include/smpi/mpif.h.in ${CMAKE_BINARY_DIR}/include/smpi/mpif.h @ONLY)
700 foreach(script cc cxx ff f90 run)
701   configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpi${script}.in ${CMAKE_BINARY_DIR}/bin/smpi${script} @ONLY)
702 endforeach()
703
704 ### SMPI scripts used when compiling simgrid 
705 set(exec_prefix "${CMAKE_BINARY_DIR}/smpi_script/")
706 set(includeflag "-I${CMAKE_HOME_DIRECTORY}/include -I${CMAKE_HOME_DIRECTORY}/include/smpi")
707 set(includeflag "${includeflag} -I${CMAKE_BINARY_DIR}/include -I${CMAKE_BINARY_DIR}/include/smpi")
708 set(includedir "${CMAKE_HOME_DIRECTORY}/include")
709 set(libdir "${CMAKE_BINARY_DIR}/lib")
710 set(CMAKE_SMPI_COMMAND "export LD_LIBRARY_PATH=\"${CMAKE_BINARY_DIR}/lib")
711 if(NS3_LIBRARY_PATH)
712   set(CMAKE_SMPI_COMMAND "${CMAKE_SMPI_COMMAND}:${NS3_LIBRARY_PATH}")
713 endif()
714 set(CMAKE_SMPI_COMMAND "${CMAKE_SMPI_COMMAND}:\${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}\"")
715
716 foreach(script cc cxx ff f90 run)
717   configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpi${script}.in ${CMAKE_BINARY_DIR}/smpi_script/bin/smpi${script} @ONLY)
718 endforeach()
719
720 if(NOT WIN32)
721   foreach(script cc cxx ff f90 run)
722     execute_process(COMMAND chmod a=rwx ${CMAKE_BINARY_DIR}/bin/smpi${script})
723     execute_process(COMMAND chmod a=rwx ${CMAKE_BINARY_DIR}/smpi_script/bin/smpi${script})
724   endforeach()
725 endif()
726
727 set(generated_headers_to_install
728   ${CMAKE_CURRENT_BINARY_DIR}/include/smpi/mpif.h
729   ${CMAKE_CURRENT_BINARY_DIR}/include/simgrid_config.h
730   )
731
732 set(generated_headers  ${CMAKE_CURRENT_BINARY_DIR}/src/internal_config.h )
733
734 set(generated_files_to_clean
735   ${generated_headers}
736   ${generated_headers_to_install}
737   ${CMAKE_BINARY_DIR}/bin/smpicc
738   ${CMAKE_BINARY_DIR}/bin/smpicxx
739   ${CMAKE_BINARY_DIR}/bin/smpiff
740   ${CMAKE_BINARY_DIR}/bin/smpif90
741   ${CMAKE_BINARY_DIR}/bin/smpirun
742   ${CMAKE_BINARY_DIR}/bin/colorize
743   ${CMAKE_BINARY_DIR}/bin/simgrid_update_xml
744   ${CMAKE_BINARY_DIR}/examples/smpi/tracing/smpi_traced.trace
745   )
746
747 if(NOT "${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_HOME_DIRECTORY}")
748   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay/actions0.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay/actions0.txt COPYONLY)
749   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay/actions1.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay/actions1.txt COPYONLY)
750   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay/actions_allReduce.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay/actions_allReduce.txt COPYONLY)
751   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay/actions_barrier.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay/actions_barrier.txt COPYONLY)
752   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay/actions_bcast.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay/actions_bcast.txt COPYONLY)
753   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay/actions_with_isend.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay/actions_with_isend.txt COPYONLY)
754   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay/actions_alltoall.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay/actions_alltoall.txt COPYONLY)
755   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay/actions_alltoallv.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay/actions_alltoallv.txt COPYONLY)
756   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay/actions_waitall.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay/actions_waitall.txt COPYONLY)
757   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay/actions_reducescatter.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay/actions_reducescatter.txt COPYONLY)
758   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay/actions_gather.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay/actions_gather.txt COPYONLY)
759   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay/actions_allgatherv.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay/actions_allgatherv.txt COPYONLY)
760   configure_file(${CMAKE_HOME_DIRECTORY}/teshsuite/smpi/hostfile ${CMAKE_BINARY_DIR}/teshsuite/smpi/hostfile COPYONLY)
761
762   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay_multiple/description_file ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/description_file COPYONLY)
763   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay_multiple/README ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/README COPYONLY)
764   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay_multiple/smpi_replay.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/smpi_replay.txt COPYONLY)
765   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace0.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace0.txt COPYONLY)
766   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace1.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace1.txt COPYONLY)
767   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace2.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace2.txt COPYONLY)
768   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace3.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace3.txt COPYONLY)
769   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace4.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace4.txt COPYONLY)
770   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace5.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace5.txt COPYONLY)
771   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace6.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace6.txt COPYONLY)
772   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace7.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace7.txt COPYONLY)
773   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace8.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace8.txt COPYONLY)
774   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace9.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace9.txt COPYONLY)
775   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace10.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace10.txt COPYONLY)
776   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace11.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace11.txt COPYONLY)
777   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace12.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace12.txt COPYONLY)
778   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace13.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace13.txt COPYONLY)
779   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace14.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace14.txt COPYONLY)
780   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace15.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace15.txt COPYONLY)
781   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace16.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace16.txt COPYONLY)
782   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace17.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace17.txt COPYONLY)
783   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace18.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace18.txt COPYONLY)
784   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace19.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace19.txt COPYONLY)
785   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace20.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace20.txt COPYONLY)
786   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace21.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace21.txt COPYONLY)
787   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace22.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace22.txt COPYONLY)
788   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace23.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace23.txt COPYONLY)
789   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace24.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace24.txt COPYONLY)
790   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace25.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace25.txt COPYONLY)
791   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace26.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace26.txt COPYONLY)
792   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace27.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace27.txt COPYONLY)
793   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace28.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace28.txt COPYONLY)
794   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace29.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace29.txt COPYONLY)
795   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace30.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace30.txt COPYONLY)
796   configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace31.txt ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace31.txt COPYONLY)
797
798   set(generated_files_to_clean
799     ${generated_files_to_clean}
800     ${CMAKE_BINARY_DIR}/examples/smpi/replay/actions0.txt
801     ${CMAKE_BINARY_DIR}/examples/smpi/replay/actions1.txt
802     ${CMAKE_BINARY_DIR}/examples/smpi/replay/actions_allReduce.txt
803     ${CMAKE_BINARY_DIR}/examples/smpi/replay/actions_barrier.txt
804     ${CMAKE_BINARY_DIR}/examples/smpi/replay/actions_bcast.txt
805     ${CMAKE_BINARY_DIR}/examples/smpi/replay/actions_with_isend.txt
806     ${CMAKE_BINARY_DIR}/examples/smpi/replay/actions_alltoall.txt
807     ${CMAKE_BINARY_DIR}/examples/smpi/replay/actions_alltoallv.txt
808     ${CMAKE_BINARY_DIR}/examples/smpi/replay/actions_waitall.txt
809     ${CMAKE_BINARY_DIR}/examples/smpi/replay/actions_gather.txt
810     ${CMAKE_BINARY_DIR}/examples/smpi/replay/actions_allgatherv.txt
811     ${CMAKE_BINARY_DIR}/examples/smpi/replay/actions_reducescatter.txt
812     ${CMAKE_BINARY_DIR}/teshsuite/smpi/hostfile
813     ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/description_file
814     ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/README
815     ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/smpi_replay.txt
816     ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace0.txt
817     ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace1.txt
818     ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace2.txt
819     ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace3.txt
820     ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace4.txt
821     ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace5.txt
822     ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace6.txt
823     ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace7.txt
824     ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace8.txt
825     ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace9.txt
826     ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace10.txt
827     ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace11.txt
828     ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace12.txt
829     ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace13.txt
830     ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace14.txt
831     ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace15.txt
832     ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace16.txt
833     ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace17.txt
834     ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace18.txt
835     ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace19.txt
836     ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace20.txt
837     ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace21.txt
838     ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace22.txt
839     ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace23.txt
840     ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace24.txt
841     ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace25.txt
842     ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace26.txt
843     ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace27.txt
844     ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace28.txt
845     ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace29.txt
846     ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace30.txt
847     ${CMAKE_BINARY_DIR}/examples/smpi/replay_multiple/ti_traces_32_1/ti_trace31.txt
848     )
849 endif()
850
851 SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES
852   "${generated_files_to_clean}")
853
854 ### Define source packages for Libs
855 include(${CMAKE_HOME_DIRECTORY}/tools/cmake/DefinePackages.cmake)
856
857 ### Build some Maintainer files
858 include(${CMAKE_HOME_DIRECTORY}/tools/cmake/MaintainerMode.cmake)
859 include(${CMAKE_HOME_DIRECTORY}/tools/cmake/UnitTesting.cmake)
860
861 ### Setup gcc & clang flags
862 if (NOT MSVC)
863   include(${CMAKE_HOME_DIRECTORY}/tools/cmake/GCCFlags.cmake)
864 endif()
865
866 ### Make Libs
867 if(NOT WIN32)
868   include(${CMAKE_HOME_DIRECTORY}/tools/cmake/MakeLib.cmake)
869 else()
870   include(${CMAKE_HOME_DIRECTORY}/tools/cmake/MakeLibWin.cmake)
871 endif()
872
873 if(enable_java)
874   include(${CMAKE_HOME_DIRECTORY}/tools/cmake/Java.cmake)
875 endif()
876
877 ### Make tests
878 if(enable_memcheck_xml)
879   set(enable_memcheck true)
880 endif()
881
882 INCLUDE(CTest)
883 ENABLE_TESTING()
884 include(${CMAKE_HOME_DIRECTORY}/tools/cmake/Tests.cmake)
885 include(${CMAKE_HOME_DIRECTORY}/tools/cmake/CTestConfig.cmake)
886
887 ### Define subdirectories
888 foreach(cmakefile ${CMAKEFILES_TXT})
889   string(REPLACE "/CMakeLists.txt" "" repository ${cmakefile})
890   add_subdirectory("${CMAKE_HOME_DIRECTORY}/${repository}")
891 endforeach()
892
893 ### Setup the distrib
894 include(${CMAKE_HOME_DIRECTORY}/tools/cmake/Distrib.cmake)
895
896 ### Build the docs if asked to
897 include(${CMAKE_HOME_DIRECTORY}/tools/cmake/Documentation.cmake)
898
899 ### Print the result of configuration
900 message("")
901 message("##########################################")
902 message("#### Content of src/internal_config.h ####")
903 message("##########################################")
904 file(STRINGS ${CMAKE_CURRENT_BINARY_DIR}/src/internal_config.h config_output)
905 LIST(REMOVE_AT config_output 0 1 2 3 4 5 6 7 8 9 10) # Pass the file header
906 foreach(line ${config_output})
907   message("   ${line}")
908 endforeach()
909 message("##########################################")
910 message("####   Content of simgrid_config.h    ####")
911 message("##########################################")
912 file(STRINGS ${CMAKE_CURRENT_BINARY_DIR}/include/simgrid_config.h config_output)
913 LIST(REMOVE_AT config_output 0 1 2 3 4 5 6 7 8 9 -1) # Pass the file header
914 foreach(line ${config_output})
915   message("   ${line}")
916 endforeach()
917 message("##########################################")
918 message("####   End of configuration headers   ####")
919 message("##########################################")
920
921 message("\nConfiguration of package `simgrid':")
922 message("        Home directory ..............: ${CMAKE_HOME_DIRECTORY}")
923 message("        Build Name ..................: ${BUILDNAME}")
924 message("        Cmake Generator .............: ${CMAKE_GENERATOR}")
925 message("        Site ........................: ${SITE}")
926 message("        Install prefix ..............: ${CMAKE_INSTALL_PREFIX}")
927 if(release)
928   message("        Release .....................: simgrid-${release_version}${SIMGRID_VERSION_EXTRA} (release build)")
929 else()
930   message("        Release .....................: simgrid-${release_version}${SIMGRID_VERSION_EXTRA} (development build)")
931 endif()
932 message("")
933 message("        Compiler: C .................: ${CMAKE_C_COMPILER} (id: ${CMAKE_C_COMPILER_ID})")
934 message("                version .............: ${CMAKE_C_COMPILER_VERSION}")
935 message("                is gnu ..............: ${CMAKE_COMPILER_IS_GNUCC}")
936 message("        Compiler: C++ ...............: ${CMAKE_CXX_COMPILER} (id: ${CMAKE_CXX_COMPILER_ID})")
937 message("                version .............: ${CMAKE_CXX_COMPILER_VERSION}")
938 if(${Java_FOUND})
939   message("        Compiler: Javac .............: ${Java_JAVAC_EXECUTABLE}")
940   message("                version .............: ${Java_VERSION_STRING}")
941 if(${SWIG_FOUND})
942   message("                SWIG ................: Version ${SWIG_VERSION} found.")
943 else()
944   message("                SWIG ................: Missing.")
945 endif()
946 endif()
947 if(CMAKE_Fortran_COMPILER)
948   message("        Compiler: Fortran ...........: ${SAVED_Fortran_COMPILER} (id: ${CMAKE_Fortran_COMPILER_ID})")
949   message("                version .............: ${CMAKE_Fortran_COMPILER_VERSION}")
950 endif()
951 message("        Linker: .....................: ${CMAKE_LINKER}")
952 message("                version .............: ${LINKER_VERSION}")
953 message("        Make program: ...............: ${CMAKE_MAKE_PROGRAM}")
954 message("")
955 message("        CFlags ......................: ${CMAKE_C_FLAGS}")
956 message("        CXXFlags ....................: ${CMAKE_CXX_FLAGS}")
957 message("        LDFlags .....................: ${CMAKE_C_LINK_FLAGS}")
958 message("        with LTO ....................: ${enable_lto}")
959 message("")
960
961 if (HAVE_NS3)
962   message("        Compile NS-3 ................: yes (path: ${NS3_PATH})")
963 else()
964   message("        Compile NS-3 ................: NO  (hint: ${NS3_HINT})")
965 endif()
966
967 if (${Java_FOUND})
968   message("        Compile Java ................: yes")
969   message("          Native lib in jar .........: ${enable_lib_in_jar}")
970 else()
971   message("        Compile Java ................: NO")
972 endif()
973 message("        Compile Lua .................: ${HAVE_LUA}")
974 message("        Compile Smpi ................: ${HAVE_SMPI}")
975 message("          Smpi fortran ..............: ${SMPI_FORTRAN}")
976 message("          MPICH3 testsuite ..........: ${enable_smpi_MPICH3_testsuite}")
977 message("          Privatization .............: ${HAVE_PRIVATIZATION}")
978 message("          PAPI support...............: ${HAVE_PAPI}")
979 message("        Compile Boost.Context support: ${HAVE_BOOST_CONTEXTS}")
980 message("")
981 message("        Maintainer mode .............: ${enable_maintainer_mode}")
982 message("        Documentation................: ${enable_documentation}")
983 message("        Model checking ..............: ${HAVE_MC}")
984 message("        Jedule  mode ................: ${HAVE_JEDULE}")
985 message("        Graphviz mode ...............: ${HAVE_GRAPHVIZ}")
986 message("        Mallocators .................: ${enable_mallocators}")
987 message("")
988 message("        Simgrid dependencies ........: ${SIMGRID_DEP}")
989 message("")
990
991 execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_BINARY_DIR}/Testing/Notes/)
992 file(WRITE ${PROJECT_BINARY_DIR}/Testing/Notes/Build  "GIT version : ${GIT_VERSION}\n")
993 file(APPEND ${PROJECT_BINARY_DIR}/Testing/Notes/Build "Release     : simgrid-${release_version}\n")
994
995 INCLUDE(Dart)