Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add a message to the user to specify our requirement for Boost version
[simgrid.git] / CMakeLists.txt
index a659417..8992f7f 100644 (file)
@@ -110,12 +110,6 @@ else()
 endif()
 
 set(SIMGRID_VERSION_STRING "SimGrid version ${release_version}${SIMGRID_VERSION_EXTRA}")
-set(SIMGRID_VERSION_BANNER "SIMGRID_VERSION_STRING\\nCopyright (c) 2004-${SIMGRID_VERSION_DATE}. The Simgrid Team.")
-if(release)
-  set(SIMGRID_VERSION_BANNER "${SIMGRID_VERSION_BANNER}\\nRelease build")
-else()
-  set(SIMGRID_VERSION_BANNER "${SIMGRID_VERSION_BANNER}\\nDevelopment build")
-endif()
 
 set(libsimgrid_version "${release_version}")
 set(libsimgrid-java_version "${release_version}")
@@ -132,7 +126,8 @@ else()
   endif()
 endif()
 
-exec_program("${CMAKE_LINKER} --version" OUTPUT_VARIABLE "LINKER_VERSION")
+execute_process(COMMAND         ${CMAKE_LINKER} --version
+                OUTPUT_VARIABLE LINKER_VERSION)
 string(REGEX MATCH "[0-9].[0-9]*" LINKER_VERSION "${LINKER_VERSION}")
 
 ### Find programs and paths
@@ -185,21 +180,26 @@ include_directories(${INCLUDES})
 include(${CMAKE_HOME_DIRECTORY}/tools/cmake/Option.cmake)
 
 ### Determine the assembly flavor that we need today
+set(HAVE_RAW_CONTEXTS 0)
 include(CMakeDetermineSystem)
 IF(CMAKE_SYSTEM_PROCESSOR MATCHES ".86|AMD64|amd64")
   IF(${ARCH_32_BITS})
     message(STATUS "System processor: i686 (${CMAKE_SYSTEM_PROCESSOR}, 32 bits)")
     set(PROCESSOR_i686 1)
+    set(PROCESSOR_x86_64 0)
   ELSE()
     message(STATUS "System processor: x86_64 (${CMAKE_SYSTEM_PROCESSOR}, 64 bits)")
+    set(PROCESSOR_i686 0)
     set(PROCESSOR_x86_64 1)
   ENDIF()
-  if (MSVC)
-    message(STATUS "Disable fast raw contextes on Microsoft Visual.")
+  if (WIN32)
+    message(STATUS "Disable fast raw contexts on Windows.")
   else()
     set(HAVE_RAW_CONTEXTS 1)
   endif()
-
+ELSE()
+  set(PROCESSOR_i686 0)
+  set(PROCESSOR_x86_64 0)
 ENDIF()
 
 include(CheckFunctionExists)
@@ -226,6 +226,10 @@ if(enable_ns3)
   endif()
 endif()
 
+if(WIN32)
+  set(Boost_USE_STATIC_LIBS 1)
+endif()
+
 find_package(Boost 1.48)
 if(Boost_FOUND)
   include_directories(${Boost_INCLUDE_DIRS})
@@ -235,7 +239,8 @@ else()
   else()
     message(FATAL_ERROR "Failed to find Boost libraries."
                         "Did you install libboost-dev and libboost-context-dev?"
-                        "(libboost-context-dev is optional)")
+                        "(libboost-context-dev is optional)"
+                        "SimGrid requires Boost >= 1.48.0")
   endif()
 endif()
 
@@ -265,6 +270,7 @@ CHECK_LIBRARY_EXISTS(rt      clock_gettime           "" HAVE_POSIX_GETTIME)
 CHECK_LIBRARY_EXISTS(pthread pthread_create          "" HAVE_PTHREAD)
 CHECK_LIBRARY_EXISTS(pthread sem_init                "" HAVE_SEM_INIT_LIB)
 CHECK_LIBRARY_EXISTS(pthread sem_open                "" HAVE_SEM_OPEN_LIB)
+set(HAVE_PTHREAD_SETAFFINITY 0)
 CHECK_LIBRARY_EXISTS(pthread pthread_setaffinity_np  "" HAVE_PTHREAD_SETAFFINITY)
 
 if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
@@ -277,7 +283,7 @@ else()
   set(CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE")
 endif()
 
-CHECK_INCLUDE_FILE("valgrind/valgrind.h" HAVE_VALGRIND_VALGRIND_H)
+CHECK_INCLUDE_FILE("valgrind/valgrind.h" HAVE_VALGRIND_H)
 CHECK_INCLUDE_FILE("unistd.h" HAVE_UNISTD_H)
 CHECK_INCLUDE_FILE("execinfo.h" HAVE_EXECINFO_H)
 CHECK_INCLUDE_FILE("signal.h" HAVE_SIGNAL_H)
@@ -291,25 +297,23 @@ CHECK_FUNCTION_EXISTS(nanosleep HAVE_NANOSLEEP)
 CHECK_FUNCTION_EXISTS(getdtablesize HAVE_GETDTABLESIZE)
 CHECK_FUNCTION_EXISTS(sysconf HAVE_SYSCONF)
 CHECK_FUNCTION_EXISTS(popen HAVE_POPEN)
+CHECK_FUNCTION_EXISTS(process_vm_readv HAVE_PROCESS_VM_READV)
+CHECK_FUNCTION_EXISTS(mmap HAVE_MMAP)
 
 CHECK_SYMBOL_EXISTS(vasprintf stdio.h HAVE_VASPRINTF)
-if(MINGW) 
+if(MINGW)
   # The detection of vasprintf fails on MinGW, assumingly because it's
   # defined as an inline function in stdio.h instead of a regular
   # function. So force the result to be 1 despite of the test.
   set(HAVE_VASPRINTF 1)
 endif()
 
-CHECK_FUNCTION_EXISTS(process_vm_readv HAVE_PROCESS_VM_READV)
-CHECK_FUNCTION_EXISTS(mmap HAVE_MMAP)
-
 #Check if __thread is defined
 execute_process(
-  COMMAND "${CMAKE_C_COMPILER} ${CMAKE_HOME_DIRECTORY}/tools/cmake/test_prog/prog_thread_storage.c"
+  COMMAND "${CMAKE_C_COMPILER} ${CMAKE_HOME_DIRECTORY}/tools/cmake/test_prog/prog_thread_storage.c -o testprog"
   WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
-  RESULT_VARIABLE HAVE_thread_storage_run
-  )
-
+  RESULT_VARIABLE HAVE_thread_storage_run)
+file(REMOVE testprog)
 if(HAVE_thread_storage_run)
   set(HAVE_THREAD_LOCAL_STORAGE 1)
 else()
@@ -332,31 +336,28 @@ else()
   SET(HAVE_MMALLOC 0)
 endif()
 
-set(HAVE_UCONTEXT_CONTEXTS 0)
-set(HAVE_THREAD_CONTEXTS 0)
-
 if(enable_jedule)
   set(HAVE_JEDULE 1)
+else()
+  set(HAVE_JEDULE 0)
 endif()
 
 if(enable_mallocators)
-  SET(MALLOCATOR_IS_WANTED 1)
+  SET(HAVE_MALLOCATOR 1)
 else()
-  SET(MALLOCATOR_IS_WANTED 0)
+  SET(HAVE_MALLOCATOR 0)
 endif()
 
 if(enable_model-checking AND HAVE_MMALLOC)
   SET(HAVE_MC 1)
-  SET(MMALLOC_WANT_OVERRIDE_LEGACY 1)
   include(FindLibunwind)
   include(FindLibdw)
 else()
   if(enable_model-checking)
-    message(STATUS "Warning: support for model-checking has been disabled because HAVE_MMALLOC is false")
+    message(STATUS "Warning: support for model-checking has been disabled because you are missing either mmap or __thread.")
   endif()
   SET(HAVE_MC 0)
   SET(HAVE_MMALLOC 0)
-  SET(MMALLOC_WANT_OVERRIDE_LEGACY 0)
 endif()
 
 if(enable_smpi)
@@ -372,6 +373,8 @@ if(enable_smpi)
     message (STATUS "Warning:  no support for SMPI automatic privatization on this platform")
     SET(HAVE_PRIVATIZATION 0)
   endif()
+else()
+  SET(HAVE_SMPI 0)
 endif()
 
 #--------------------------------------------------------------------------------------------------
@@ -411,13 +414,15 @@ endif()
 #--------------------------------------------------------------------------------------------------
 ### Initialize of CONTEXT THREADS
 
+set(HAVE_THREAD_CONTEXTS 0)
+
 if(HAVE_PTHREAD)
   ### Test that we have a way to create semaphores
 
   if(HAVE_SEM_OPEN_LIB)
     execute_process(COMMAND ${CMAKE_C_COMPILER} ${CMAKE_HOME_DIRECTORY}/tools/cmake/test_prog/prog_sem_open.c -lpthread -o sem_open
-    WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
-    OUTPUT_VARIABLE HAVE_SEM_OPEN_compil
+      WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+      OUTPUT_VARIABLE HAVE_SEM_OPEN_compil
     )
 
     # Test sem_open by compiling:
@@ -433,9 +438,9 @@ if(HAVE_PTHREAD)
     # If we're not crosscompiling, we check by executing the program:
     if (HAVE_SEM_OPEN AND NOT CMAKE_CROSSCOMPILING)
       execute_process(COMMAND ./sem_open
-      WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
-      RESULT_VARIABLE HAVE_SEM_OPEN_run
-      OUTPUT_VARIABLE var_compil
+        WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+        RESULT_VARIABLE HAVE_SEM_OPEN_run
+        OUTPUT_VARIABLE var_compil
       )
       if (NOT HAVE_SEM_OPEN_run)
         set(HAVE_SEM_OPEN 1)
@@ -460,8 +465,9 @@ if(HAVE_PTHREAD)
 
   if(HAVE_SEM_INIT_LIB)
     execute_process(COMMAND ${CMAKE_C_COMPILER} ${CMAKE_HOME_DIRECTORY}/tools/cmake/test_prog/prog_sem_init.c -lpthread -o sem_init
-    WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
-    RESULT_VARIABLE HAVE_SEM_INIT_run OUTPUT_VARIABLE HAVE_SEM_INIT_compil)
+      WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+      RESULT_VARIABLE HAVE_SEM_INIT_run 
+      OUTPUT_VARIABLE HAVE_SEM_INIT_compil)
 
     # Test sem_init by compiling:
     if(HAVE_SEM_INIT_compil)
@@ -476,9 +482,9 @@ if(HAVE_PTHREAD)
     # If we're not crosscompiling, we check by executing the program:
     if (HAVE_SEM_INIT AND NOT CMAKE_CROSSCOMPILING)
       execute_process(COMMAND ./sem_init
-      WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
-      RESULT_VARIABLE HAVE_SEM_INIT_run
-      OUTPUT_VARIABLE var_compil
+        WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+        RESULT_VARIABLE HAVE_SEM_INIT_run
+        OUTPUT_VARIABLE var_compil
       )
       if (NOT HAVE_SEM_INIT_run)
         set(HAVE_SEM_INIT 1)
@@ -502,167 +508,150 @@ if(HAVE_PTHREAD)
     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).")
   endif()
 
+  set(HAVE_THREAD_CONTEXTS 1)
+  message("-- Support for thread context factory ok.")
 endif()
 
-# This is needed for ucontext on MacOS X:
-if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
-  add_definitions(-D_XOPEN_SOURCE=700 -D_DARWIN_C_SOURCE)
+
+set(HAVE_UCONTEXT_CONTEXTS 0)
+if(NOT HAVE_UCONTEXT_H)
+  message("-- No ucontext factory: <ucontext.h> not found.")
+elseif(APPLE)
+  message("-- No ucontext factory: Apple don't want us to use them.")
+  set(HAVE_UCONTEXT_H 0)
+else()
+  try_compile(compile_makecontext ${CMAKE_BINARY_DIR} ${CMAKE_HOME_DIRECTORY}/tools/cmake/test_prog/prog_makecontext.c
+    OUTPUT_VARIABLE compile_makecontext_output)
+  
+  #If can have both context
+  if(compile_makecontext)
+    set(HAVE_UCONTEXT_CONTEXTS 1)
+    message("-- Support for ucontext factory ok.")
+  else()
+    message("-- Error: <ucontext.h> exists, but makecontext is not compilable. Compilation output:\n ${compile_makecontext_output}")
+    message("-- No ucontext factory: makecontext() is not compilable.")
+  endif()
+
+  # Stack setup (size and address)
+  try_run(RUN_makecontext_VAR COMPILE_makecontext_VAR
+    ${CMAKE_BINARY_DIR} ${CMAKE_HOME_DIRECTORY}/tools/cmake/test_prog/prog_stacksetup.c
+    RUN_OUTPUT_VARIABLE stack_setup)
+
+  LIST(LENGTH stack_setup stack_setup_len)
+  if("${stack_setup_len}" STREQUAL "2")
+    LIST(GET stack_setup 0 makecontext_addr)
+    LIST(GET stack_setup 1 makecontext_size)
+    set(sg_makecontext_stack_addr "#define sg_makecontext_stack_addr(skaddr) (${makecontext_addr})")
+    set(sg_makecontext_stack_size "#define sg_makecontext_stack_size(sksize) (${makecontext_size})")
+  else()
+    message(FATAL_ERROR "Could not figure out the stack setup. Compil: ${RUN_makecontext_VAR}. Exec: ${COMPILE_makecontext_VAR}. Output: ${stack_setup}")
+  endif()
 endif()
-try_compile(HAVE_UCONTEXT
-    ${CMAKE_BINARY_DIR}
-    ${CMAKE_HOME_DIRECTORY}/tools/cmake/test_prog/prog_AC_CHECK_MCSC.c)
 
-#If can have both context
-if(HAVE_UCONTEXT)
-  set(HAVE_UCONTEXT_CONTEXTS 1)
-  message("-- Support for ucontext factory")
+# Stack growth direction (upward or downward). Used for the following contexts: SysV, raw, Boost
+try_run(RUN_stackgrowth_VAR COMPILE_stackgrowth_VAR
+  ${CMAKE_BINARY_DIR}
+  ${CMAKE_HOME_DIRECTORY}/tools/cmake/test_prog/prog_stackgrowth.c
+  RUN_OUTPUT_VARIABLE stack
+  COPY_FILE test_stackgrowth)
+
+if("${stack}" STREQUAL "down")
+  set(PTH_STACKGROWTH "-1")
+elseif("${stack}" STREQUAL "up")
+  set(PTH_STACKGROWTH "1")
+else()
+  if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
+    set(PTH_STACKGROWTH "-1")
+  elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i686")
+    set(PTH_STACKGROWTH "-1")
+  else()
+    message(FATAL_ERROR "Could not figure out the stack direction. Test prog returned: ${stack}; CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}.")
+  endif()
 endif()
+# If the test ran well, remove the test binary
+file(REMOVE test_stackgrowth)
+#--------------------------------------------------------------------------------------------------
 
-if(HAVE_PTHREAD)
-  set(HAVE_THREAD_CONTEXTS 1)
-  message("-- Support for thread context factory")
+### check for addr2line
+find_path(ADDR2LINE NAMES addr2line    PATHS NO_DEFAULT_PATHS)
+if(ADDR2LINE)
+  set(ADDR2LINE "${ADDR2LINE}/addr2line")
 endif()
 
 ###############
 ## GIT version check
 ##
 if(EXISTS ${CMAKE_HOME_DIRECTORY}/.git/)
-  execute_process(COMMAND git remote
-  COMMAND head -n 1
-  WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/.git/
-  OUTPUT_VARIABLE remote
-  RESULT_VARIABLE ret
-  )
-  string(REPLACE "\n" "" remote "${remote}")
+  execute_process(
+     COMMAND git remote
+     COMMAND head -n 1
+     WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/.git/
+     OUTPUT_VARIABLE remote
+     OUTPUT_STRIP_TRAILING_WHITESPACE)
   #message(STATUS "Git remote: ${remote}")
   execute_process(COMMAND git config --get remote.${remote}.url
-  WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/.git/
-  OUTPUT_VARIABLE url
-  RESULT_VARIABLE ret
-  )
-  string(REPLACE "\n" "" url "${url}")
+     WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/.git/
+     OUTPUT_VARIABLE url
+     OUTPUT_STRIP_TRAILING_WHITESPACE)
   #message(STATUS "Git url: ${url}")
   if(url)
     execute_process(COMMAND git --git-dir=${CMAKE_HOME_DIRECTORY}/.git log --pretty=oneline --abbrev-commit -1
-    WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/.git/
-    OUTPUT_VARIABLE GIT_VERSION
-    RESULT_VARIABLE ret
-    )
-    string(REPLACE "\n" "" GIT_VERSION "${GIT_VERSION}")
+       WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/.git/
+       OUTPUT_VARIABLE GIT_VERSION
+       OUTPUT_STRIP_TRAILING_WHITESPACE)
     message(STATUS "Git version: ${GIT_VERSION}")
+    
     execute_process(COMMAND git --git-dir=${CMAKE_HOME_DIRECTORY}/.git log -n 1 --pretty=format:%ai .
-    WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/.git/
-    OUTPUT_VARIABLE GIT_DATE
-    RESULT_VARIABLE ret
-    )
-    string(REPLACE "\n" "" GIT_DATE "${GIT_DATE}")
+       WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/.git/
+       OUTPUT_VARIABLE GIT_DATE 
+       OUTPUT_STRIP_TRAILING_WHITESPACE)
     message(STATUS "Git date: ${GIT_DATE}")
     string(REGEX REPLACE " .*" "" GIT_VERSION "${GIT_VERSION}")
     
     execute_process(COMMAND git --git-dir=${CMAKE_HOME_DIRECTORY}/.git log --pretty=format:%H -1
-                    WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/.git/
-                   OUTPUT_VARIABLE SIMGRID_GITHASH
-                   RESULT_VARIABLE ret
-                   )
-    string(REPLACE "\n" "" SIMGRID_GITHASH "${SIMGRID_GITHASH}")
-                   
+       WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/.git/
+       OUTPUT_VARIABLE SIMGRID_GITHASH
+       OUTPUT_STRIP_TRAILING_WHITESPACE)
   endif()
 elseif(EXISTS ${CMAKE_HOME_DIRECTORY}/.gitversion)
   FILE(STRINGS ${CMAKE_HOME_DIRECTORY}/.gitversion GIT_VERSION)
 endif()
 
-if(GIT_VERSION)
-  set(SIMGRID_VERSION_BANNER "${SIMGRID_VERSION_BANNER} at commit ${GIT_VERSION}")
-endif()
-if(GIT_DATE)
-  set(SIMGRID_VERSION_BANNER "${SIMGRID_VERSION_BANNER} (${GIT_DATE})")
-endif()
-#--------------------------------------------------------------------------------------------------
 
-set(makecontext_CPPFLAGS_2 "")
-if(HAVE_UCONTEXT_H)
-  set(makecontext_CPPFLAGS "-DTEST_makecontext")
-  if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
-    set(makecontext_CPPFLAGS_2 "-D_XOPEN_SOURCE=700")
-  endif()
-
-  file(REMOVE ${CMAKE_BINARY_DIR}/conftestval)
+### Generate the required headers and scripts
+#############################################
 
-  if(CMAKE_CROSSCOMPILING)
-    set(RUN_makecontext_VAR "cross")
-    set(COMPILE_makecontext_VAR "cross")
+# gcc makes no difference between "#define HAVE_FOOBAR" and "#define HAVE_FOOBAR 0" by default, 
+# but this too error prone. If you forget to include the config.h, you get weird segfaults.
+# If you include it everywhere, everything gets recompiled everytime.
+# So we include only where needed, and compile with -Wundef to notice the missing includes.
+# But cmake sometimes defines to the empty definition (#define HAVE_VALGRIND_H).
+# So we have to make sure that everything got a decent value before generating the files.
+foreach(var HAVE_EXECINFO_H HAVE_FUTEX_H HAVE_GETDTABLESIZE HAVE_GETTIMEOFDAY HAVE_MMAP
+            HAVE_NANOSLEEP  HAVE_POPEN HAVE_POSIX_GETTIME HAVE_PROCESS_VM_READV HAVE_SIGNAL_H
+           HAVE_SYS_PARAM_H HAVE_SYS_SYSCTL_H HAVE_SYSCONF HAVE_UCONTEXT_H HAVE_UNISTD_H
+           HAVE_VALGRIND_H HAVE_VASPRINTF)
+  if(${var})
+    set(${var} 1)
   else()
-    try_run(RUN_makecontext_VAR COMPILE_makecontext_VAR
-      ${CMAKE_BINARY_DIR}
-      ${CMAKE_HOME_DIRECTORY}/tools/cmake/test_prog/prog_stacksetup.c
-      COMPILE_DEFINITIONS "${makecontext_CPPFLAGS} ${makecontext_CPPFLAGS_2}"
-      )
+    set(${var} 0)
   endif()
+endforeach()
 
-  if(EXISTS ${CMAKE_BINARY_DIR}/conftestval)
-    file(READ ${CMAKE_BINARY_DIR}/conftestval MAKECONTEXT_ADDR_SIZE)
-    string(REPLACE "\n" "" MAKECONTEXT_ADDR_SIZE "${MAKECONTEXT_ADDR_SIZE}")
-    string(REGEX MATCH ;^.*,;MAKECONTEXT_ADDR "${MAKECONTEXT_ADDR_SIZE}")
-    string(REGEX MATCH ;,.*$; MAKECONTEXT_SIZE "${MAKECONTEXT_ADDR_SIZE}")
-    string(REPLACE "," "" makecontext_addr "${MAKECONTEXT_ADDR}")
-    string(REPLACE "," "" makecontext_size "${MAKECONTEXT_SIZE}")
-    set(pth_skaddr_makecontext "#define pth_skaddr_makecontext(skaddr,sksize) (${makecontext_addr})")
-    set(pth_sksize_makecontext "#define pth_sksize_makecontext(skaddr,sksize) (${makecontext_size})")
-  endif()
-endif()
-
-#--------------------------------------------------------------------------------------------------
-
-### check for stackgrowth
-if (NOT CMAKE_CROSSCOMPILING)
-  try_run(RUN_stackgrowth_VAR COMPILE_stackgrowth_VAR
-    ${CMAKE_BINARY_DIR}
-    ${CMAKE_HOME_DIRECTORY}/tools/cmake/test_prog/prog_stackgrowth.c
-    RUN_OUTPUT_VARIABLE stack
-    COPY_FILE test_stackgrowth
-  )
-endif()
-if("${stack}" STREQUAL "down")
-  set(PTH_STACKGROWTH "-1")
-elseif("${stack}" STREQUAL "up")
-  set(PTH_STACKGROWTH "1")
-else()
-  if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
-    set(PTH_STACKGROWTH "-1")
-  elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i686")
-    set(PTH_STACKGROWTH "-1")
-  else()
-    message(FATAL_ERROR "Could not figure out the stack direction. Test prog returned: ${stack}; CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}.")
-  endif()
-endif()
-# If the test ran well, remove the test binary
-execute_process(COMMAND ${CMAKE_COMMAND} -E remove test_stackgrowth)
-
-###############
-## System checks
-##
-
-### check for addr2line
-find_path(ADDR2LINE NAMES addr2line    PATHS NO_DEFAULT_PATHS  )
-if(ADDR2LINE)
-  set(ADDR2LINE "${ADDR2LINE}/addr2line")
-endif()
-
-### File to create
-
-configure_file("${CMAKE_HOME_DIRECTORY}/src/context_sysv_config.h.in"
-  "${CMAKE_BINARY_DIR}/src/context_sysv_config.h" @ONLY IMMEDIATE)
+# Avoid triggering a (full) rebuild by touching the files if they did not really change
+configure_file("${CMAKE_HOME_DIRECTORY}/tools/cmake/src/internal_config.h.in" "${CMAKE_BINARY_DIR}/src/internal_config.h.generated"    @ONLY IMMEDIATE)
+configure_file("${CMAKE_HOME_DIRECTORY}/include/simgrid_config.h.in"          "${CMAKE_BINARY_DIR}/include/simgrid_config.h.generated" @ONLY IMMEDIATE)
+execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_BINARY_DIR}/src/internal_config.h.generated ${CMAKE_BINARY_DIR}/src/internal_config.h)
+execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_BINARY_DIR}/include/simgrid_config.h.generated ${CMAKE_BINARY_DIR}/include/simgrid_config.h)
+file(REMOVE ${CMAKE_BINARY_DIR}/src/internal_config.h.generated)
+file(REMOVE ${CMAKE_BINARY_DIR}/include/simgrid_config.h.generated)
 
-SET( CMAKEDEFINE "#cmakedefine" )
-configure_file("${CMAKE_HOME_DIRECTORY}/tools/cmake/src/internal_config.h.in" "${CMAKE_BINARY_DIR}/src/internal_config.h" @ONLY IMMEDIATE)
-configure_file("${CMAKE_BINARY_DIR}/src/internal_config.h" "${CMAKE_BINARY_DIR}/src/internal_config.h" @ONLY IMMEDIATE)
-configure_file("${CMAKE_HOME_DIRECTORY}/include/simgrid_config.h.in" "${CMAKE_BINARY_DIR}/include/simgrid_config.h" @ONLY IMMEDIATE)
+# We need two versions of the SMPI scripts because they contain the path to the library
+# so, it depends of whether SimGrid is installed, or run from the sources (during the build)
 
-set(top_srcdir "${CMAKE_HOME_DIRECTORY}")
-set(srcdir "${CMAKE_HOME_DIRECTORY}/src")
-set(bindir "${CMAKE_BINARY_DIR}")
+file(READ ${CMAKE_HOME_DIRECTORY}/src/smpi/smpitools.sh SMPITOOLS_SH) # Definitions shared amongst all SMPI scripts, inlined in each of them
 
-### Script used when simgrid is installed
+### SMPI script used when simgrid is installed
 set(exec_prefix ${CMAKE_INSTALL_PREFIX})
 set(includeflag "-I${CMAKE_INSTALL_PREFIX}/include -I${CMAKE_INSTALL_PREFIX}/include/smpi")
 set(includedir "${CMAKE_INSTALL_PREFIX}/include")
@@ -673,45 +662,32 @@ if(NS3_LIBRARY_PATH)
 endif()
 set(CMAKE_SMPI_COMMAND "${CMAKE_SMPI_COMMAND}:\${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}\"")
 
-file(READ ${CMAKE_HOME_DIRECTORY}/src/smpi/smpitools.sh SMPITOOLS_SH)
 configure_file(${CMAKE_HOME_DIRECTORY}/include/smpi/mpif.h.in ${CMAKE_BINARY_DIR}/include/smpi/mpif.h @ONLY)
-configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpicc.in ${CMAKE_BINARY_DIR}/bin/smpicc @ONLY)
-configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpicxx.in ${CMAKE_BINARY_DIR}/bin/smpicxx @ONLY)
-configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpiff.in ${CMAKE_BINARY_DIR}/bin/smpiff @ONLY)
-configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpif90.in ${CMAKE_BINARY_DIR}/bin/smpif90 @ONLY)
-configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpirun.in ${CMAKE_BINARY_DIR}/bin/smpirun @ONLY)
+foreach(script cc cxx ff f90 run)
+  configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpi${script}.in ${CMAKE_BINARY_DIR}/bin/smpi${script} @ONLY)
+endforeach()
 
-### Script used when simgrid is compiling
+### SMPI scripts used when compiling simgrid 
+set(exec_prefix "${CMAKE_BINARY_DIR}/smpi_script/")
 set(includeflag "-I${CMAKE_HOME_DIRECTORY}/include -I${CMAKE_HOME_DIRECTORY}/include/smpi")
 set(includeflag "${includeflag} -I${CMAKE_BINARY_DIR}/include -I${CMAKE_BINARY_DIR}/include/smpi")
 set(includedir "${CMAKE_HOME_DIRECTORY}/include")
-set(exec_prefix "${CMAKE_BINARY_DIR}/smpi_script/")
+set(libdir "${CMAKE_BINARY_DIR}/lib")
 set(CMAKE_SMPI_COMMAND "export LD_LIBRARY_PATH=\"${CMAKE_BINARY_DIR}/lib")
 if(NS3_LIBRARY_PATH)
   set(CMAKE_SMPI_COMMAND "${CMAKE_SMPI_COMMAND}:${NS3_LIBRARY_PATH}")
 endif()
 set(CMAKE_SMPI_COMMAND "${CMAKE_SMPI_COMMAND}:\${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}\"")
-set(libdir "${CMAKE_BINARY_DIR}/lib")
-
-configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpicc.in ${CMAKE_BINARY_DIR}/smpi_script/bin/smpicc @ONLY)
-configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpicxx.in ${CMAKE_BINARY_DIR}/smpi_script/bin/smpicxx @ONLY)
-configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpiff.in ${CMAKE_BINARY_DIR}/smpi_script/bin/smpiff @ONLY)
-configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpif90.in ${CMAKE_BINARY_DIR}/smpi_script/bin/smpif90 @ONLY)
-configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpirun.in ${CMAKE_BINARY_DIR}/smpi_script/bin/smpirun @ONLY)
 
-set(top_builddir ${CMAKE_HOME_DIRECTORY})
+foreach(script cc cxx ff f90 run)
+  configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpi${script}.in ${CMAKE_BINARY_DIR}/smpi_script/bin/smpi${script} @ONLY)
+endforeach()
 
 if(NOT WIN32)
-  execute_process(COMMAND chmod a=rwx ${CMAKE_BINARY_DIR}/bin/smpicc)
-  execute_process(COMMAND chmod a=rwx ${CMAKE_BINARY_DIR}/bin/smpicxx)
-  execute_process(COMMAND chmod a=rwx ${CMAKE_BINARY_DIR}/bin/smpiff)
-  execute_process(COMMAND chmod a=rwx ${CMAKE_BINARY_DIR}/bin/smpif90)
-  execute_process(COMMAND chmod a=rwx ${CMAKE_BINARY_DIR}/bin/smpirun)
-  execute_process(COMMAND chmod a=rwx ${CMAKE_BINARY_DIR}/smpi_script/bin/smpicc)
-  execute_process(COMMAND chmod a=rwx ${CMAKE_BINARY_DIR}/smpi_script/bin/smpicxx)
-  execute_process(COMMAND chmod a=rwx ${CMAKE_BINARY_DIR}/smpi_script/bin/smpiff)
-  execute_process(COMMAND chmod a=rwx ${CMAKE_BINARY_DIR}/smpi_script/bin/smpif90)
-  execute_process(COMMAND chmod a=rwx ${CMAKE_BINARY_DIR}/smpi_script/bin/smpirun)
+  foreach(script cc cxx ff f90 run)
+    execute_process(COMMAND chmod a=rwx ${CMAKE_BINARY_DIR}/bin/smpi${script})
+    execute_process(COMMAND chmod a=rwx ${CMAKE_BINARY_DIR}/smpi_script/bin/smpi${script})
+  endforeach()
 endif()
 
 set(generated_headers_to_install
@@ -720,7 +696,6 @@ set(generated_headers_to_install
   )
 
 set(generated_headers
-  ${CMAKE_CURRENT_BINARY_DIR}/src/context_sysv_config.h
   ${CMAKE_CURRENT_BINARY_DIR}/src/internal_config.h
   )
 
@@ -906,12 +881,22 @@ endif()
 message("")
 message("##########################################")
 message("#### Content of src/internal_config.h ####")
+message("##########################################")
 file(STRINGS ${CMAKE_CURRENT_BINARY_DIR}/src/internal_config.h config_output)
-LIST(REMOVE_AT config_output 0 1 2 3 4 5 6 7 8) # Pass the file header
+LIST(REMOVE_AT config_output 0 1 2 3 4 5 6 7 8 9 10) # Pass the file header
 foreach(line ${config_output})
   message("   ${line}")
 endforeach()
-message("####   end of src/internal_config.h   ####")
+message("##########################################")
+message("####   Content of simgrid_config.h    ####")
+message("##########################################")
+file(STRINGS ${CMAKE_CURRENT_BINARY_DIR}/include/simgrid_config.h config_output)
+LIST(REMOVE_AT config_output 0 1 2 3 4 5 6 7 8 9 -1) # Pass the file header
+foreach(line ${config_output})
+  message("   ${line}")
+endforeach()
+message("##########################################")
+message("####   End of configuration headers   ####")
 message("##########################################")
 
 message("\nConfiguration of package `simgrid':")
@@ -984,7 +969,7 @@ message("")
 message("        Simgrid dependencies ........: ${SIMGRID_DEP}")
 message("")
 
-exec_program("${CMAKE_COMMAND} -E make_directory ${PROJECT_BINARY_DIR}/Testing/Notes/" OUTPUT_VARIABLE OKIDOKI)
+execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_BINARY_DIR}/Testing/Notes/)
 file(WRITE ${PROJECT_BINARY_DIR}/Testing/Notes/Build  "GIT version : ${GIT_VERSION}\n")
 file(APPEND ${PROJECT_BINARY_DIR}/Testing/Notes/Build "Release     : simgrid-${release_version}\n")