Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add an hide option "enable_pcre" for enable or not pcre lib.
[simgrid.git] / buildtools / Cmake / CompleteInFiles.cmake
index e97750e..cb94883 100644 (file)
@@ -1,16 +1,35 @@
+set(CMAKE_MODULE_PATH 
+${CMAKE_MODULE_PATH}
+${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Modules
+)
+
+message(STATUS "Cmake version ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}")
+
 include(CheckFunctionExists)
 include(CheckIncludeFile)
 include(CheckIncludeFiles)
 include(CheckLibraryExists)
 include(TestBigEndian)
-
 TEST_BIG_ENDIAN(BIGENDIAN)
 
-# Checks for header libraries functions.
-
-find_library(HAVE_CGRAPH_LIB cgraph)
-find_file(HAVE_CGRAPH_H graphviz/cgraph.h)
+include(FindGraphviz)
+if(enable_pcre)
+include(FindPCRE)
+endif(enable_pcre)
+if(enable_gtnets)      
+       include(FindGTnets)
+endif(enable_gtnets)
+if(enable_ruby)
+       include(FindRubySimgrid)        
+endif(enable_ruby)
+if(enable_smpi)
+       include(FindF2c)
+endif(enable_smpi)
+if(enable_lua)
+       include(FindLua51Simgrid)
+endif(enable_lua)
 
+# Checks for header libraries functions.
 CHECK_LIBRARY_EXISTS(pthread   pthread_create          NO_DEFAULT_PATHS pthread)
 CHECK_LIBRARY_EXISTS(pthread   sem_init                NO_DEFAULT_PATHS HAVE_SEM_INIT_LIB)
 CHECK_LIBRARY_EXISTS(pthread   sem_timedwait           NO_DEFAULT_PATHS HAVE_SEM_TIMEDWAIT_LIB)
@@ -41,6 +60,7 @@ CHECK_INCLUDE_FILE("stdlib.h" HAVE_STDLIB_H)
 CHECK_INCLUDE_FILE("strings.h" HAVE_STRINGS_H)
 CHECK_INCLUDE_FILE("string.h" HAVE_STRING_H)
 CHECK_INCLUDE_FILE("ucontext.h" HAVE_UCONTEXT_H)
+CHECK_INCLUDE_FILE("stdio.h" HAVE_STDIO_H)
 
 CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
 CHECK_FUNCTION_EXISTS(usleep HAVE_USLEEP)
@@ -56,22 +76,33 @@ CHECK_FUNCTION_EXISTS(vasprintf HAVE_VASPRINTF)
 CHECK_FUNCTION_EXISTS(makecontext HAVE_MAKECONTEXT)
 CHECK_FUNCTION_EXISTS(mmap HAVE_MMAP)
 
-if(WIN32)
+if(WIN32) #THOSE FILES ARE FUNCTIONS ARE NOT DETECTED BUT THEY SHOULD...
     set(HAVE_UCONTEXT_H 1)
     set(HAVE_MAKECONTEXT 1)
+    set(HAVE_SNPRINTF 1)
+    set(HAVE_VSNPRINTF 1)
 endif(WIN32)
 
 set(CONTEXT_UCONTEXT 0)
 SET(CONTEXT_THREADS 0)
-SET(HAVE_RUBY 0)
-set(HAVE_LUA 0)
-SET(HAVE_JAVA 0)
 SET(HAVE_TRACING 0)
 
 if(enable_tracing)
        SET(HAVE_TRACING 1)
 endif(enable_tracing)
 
+if(enable_latency_bound_tracking)
+       SET(HAVE_LATENCY_BOUND_TRACKING 1)
+else(enable_latency_bound_tracking)
+  if(enable_gtnets)
+    message(STATUS "Warning : Turning latency_bound_tracking to ON because GTNeTs is ON")
+    SET(enable_latency_bound_tracking ON)
+    SET(HAVE_LATENCY_BOUND_TRACKING 1)
+  else(enable_gtnets)
+    SET(HAVE_LATENCY_BOUND_TRACKING 0)
+  endif(enable_gtnets)
+endif(enable_latency_bound_tracking)
+
 if(enable_model-checking AND HAVE_MMAP)
        SET(HAVE_MC 1)
        SET(MMALLOC_WANT_OVERIDE_LEGACY 1)
@@ -80,114 +111,6 @@ else(enable_model-checking AND HAVE_MMAP)
        SET(MMALLOC_WANT_OVERIDE_LEGACY 0)
 endif(enable_model-checking AND HAVE_MMAP)
 
-if(enable_lua)
-       include(FindLua51)
-       if(LUA51_FOUND)
-               set(HAVE_LUA 1)
-               SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}-I${LUA_INCLUDE_DIR} ")
-               foreach(path_lua ${LUA_LIBRARIES})
-               string(REGEX REPLACE "liblua.*" "" path_lua_to_use ${path_lua})
-               string(REGEX MATCH ".*lua.*" operation "${path_lua}")
-               if(NOT operation)
-                       string(REGEX REPLACE "${path_lua_to_use}" "" liblua ${path_lua})
-                       string(REPLACE "lib" "" liblua "${liblua}")
-                       string(REGEX REPLACE "[.][^.]*$" "" liblua "${liblua}")                 
-               endif(NOT operation)
-               endforeach(path_lua ${LUA_LIBRARIES})
-       else(LUA51_FOUND)
-               message("Lua binding need version 5.1 and cmake version 2.8")
-               message("Cmake version ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}")
-       endif(LUA51_FOUND)
-endif(enable_lua)
-
-if(enable_ruby)
-       include(FindRuby)
-       if(RUBY_LIBRARY)
-               if(RUBY_VERSION_MAJOR MATCHES "1" AND RUBY_VERSION_MINOR MATCHES "8")
-                       set(LIB_RUBY_VERSION "${RUBY_VERSION_MAJOR}.${RUBY_VERSION_MINOR}.${RUBY_VERSION_PATCH}")
-                       string(REGEX MATCH "ruby.*[0-9]" RUBY_LIBRARY_NAME ${RUBY_LIBRARY})
-                       if(NOT RUBY_LIBRARY_NAME)
-                               set(RUBY_LIBRARY_NAME ruby)
-                       endif(NOT RUBY_LIBRARY_NAME)
-                       string(REGEX REPLACE "/libruby.*$" "" RUBY_LIBRARY ${RUBY_LIBRARY})
-                       SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}-I${RUBY_CONFIG_INCLUDE_DIR} ") #path to config.h
-                       string(COMPARE EQUAL "${RUBY_INCLUDE_DIR}" "${RUBY_CONFIG_INCLUDE_DIR}" operation)
-                       if(NOT operation)
-                               SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}-I${RUBY_INCLUDE_DIR} ") #path to ruby.h
-                       endif(NOT operation)
-                       ADD_DEFINITIONS("-I${PROJECT_DIRECTORY}/src/bindings/ruby -I${PROJECT_DIRECTORY}/src/simix")
-                       SET(HAVE_RUBY 1)
-               else(RUBY_VERSION_MAJOR MATCHES "1" AND RUBY_VERSION_MINOR MATCHES "8")
-                       message("Ruby binding need version 1.8.x actually version ${RUBY_VERSION_MAJOR}.${RUBY_VERSION_MINOR}.x")
-                       SET(HAVE_RUBY 0)
-               endif(RUBY_VERSION_MAJOR MATCHES "1" AND RUBY_VERSION_MINOR MATCHES "8")
-       else(RUBY_LIBRARY)
-               SET(HAVE_RUBY 0)
-       endif(RUBY_LIBRARY)
-       
-       if(NOT RUBY_EXECUTABLE)
-               message("Take care : you don't have ruby executable so you can compile and build examples but can't execute them!!!") 
-       endif(NOT RUBY_EXECUTABLE)
-       
-endif(enable_ruby)
-
-#--------------------------------------------------------------------------------------------------
-### Initialize of CONTEXT JAVA
-
-if(enable_java)
-       include(FindJava)
-       include(FindJNI)
-       if(JAVA_INCLUDE_PATH)
-               set(HAVE_JNI_H 1)
-       endif(JAVA_INCLUDE_PATH)        
-       if(JAVA_COMPILE AND JAVA_INCLUDE_PATH AND JAVA_INCLUDE_PATH2)
-               SET(HAVE_JAVA 1)
-               SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}-I${JAVA_INCLUDE_PATH} ")
-               if(NOT JAVA_INCLUDE_PATH STREQUAL JAVA_INCLUDE_PATH2)
-               SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}-I${JAVA_INCLUDE_PATH2} ")                   
-               endif(NOT JAVA_INCLUDE_PATH STREQUAL JAVA_INCLUDE_PATH2)
-       else(JAVA_COMPILE AND JAVA_INCLUDE_PATH AND JAVA_INCLUDE_PATH2) 
-               SET(HAVE_JAVA 0)
-       endif(JAVA_COMPILE AND JAVA_INCLUDE_PATH AND JAVA_INCLUDE_PATH2)
-endif(enable_java)
-
-#--------------------------------------------------------------------------------------------------
-### Initialize of CONTEXT GTNETS
-if(NOT enable_gtnets OR enable_supernovae)
-       SET(HAVE_GTNETS 0)
-else(NOT enable_gtnets OR enable_supernovae)
-       set(GTNETS_LDFLAGS "-L${gtnets_path}/lib")
-       set(GTNETS_CPPFLAGS "-I${gtnets_path}/include/gtnets")
-       exec_program("${CMAKE_CXX_COMPILER} ${GTNETS_CPPFLAGS} -lgtnets ${GTNETS_LDFLAGS} ${PROJECT_DIRECTORY}/buildtools/Cmake/test_prog/prog_gtnets.cpp " OUTPUT_VARIABLE COMPILE_GTNETS_VAR) 
-       if(COMPILE_GTNETS_VAR)
-               SET(HAVE_GTNETS 0)
-       else(COMPILE_GTNETS_VAR)
-               SET(HAVE_GTNETS 1)
-               SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}${GTNETS_CPPFLAGS} ${GTNETS_LDFLAGS} ")
-               SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}${GTNETS_CPPFLAGS} ${GTNETS_LDFLAGS} ")
-               string(REGEX MATCH "${gtnets_path}/lib" operation "$ENV{LD_LIBRARY_PATH}")
-               if(NOT operation)
-                       message(FATAL_ERROR "\n\nTo use GTNETS don't forget to set LD_LIBRARY_PATH with \n\texport LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${gtnets_path}/lib\n\n")
-               endif(NOT operation)
-       endif(COMPILE_GTNETS_VAR)
-endif(NOT enable_gtnets OR enable_supernovae)
-
-#--------------------------------------------------------------------------------------------------
-### Initialize of cgraph
-mark_as_advanced(HAVE_CGRAPH_LIB)
-mark_as_advanced(HAVE_CGRAPH_H)
-
-if(HAVE_CGRAPH_LIB AND HAVE_CGRAPH_H)
-       string(REGEX REPLACE "/libcgraph.*" "" lib_cgraph ${HAVE_CGRAPH_LIB})
-       string(REPLACE "/cgraph.h" "" file_cgraph_h ${HAVE_CGRAPH_H})
-               
-       string(REGEX MATCH "-I${file_cgraph_h} " operation "${CMAKE_C_FLAGS}")
-       if(NOT operation)
-               SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}-I${file_cgraph_h} ")
-       endif(NOT operation)
-       
-endif(HAVE_CGRAPH_LIB AND HAVE_CGRAPH_H)
-
 #--------------------------------------------------------------------------------------------------
 ### Initialize of CONTEXT THREADS
 
@@ -201,7 +124,7 @@ if(pthread)
        ### HAVE_SEM_INIT
        
        if(HAVE_SEM_INIT_LIB)
-               exec_program("${CMAKE_C_COMPILER} -lpthread ${PROJECT_DIRECTORY}/buildtools/Cmake/test_prog/prog_sem_init.c" OUTPUT_VARIABLE HAVE_SEM_INIT_run)
+               exec_program("${CMAKE_C_COMPILER} -lpthread ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_sem_init.c" OUTPUT_VARIABLE HAVE_SEM_INIT_run)
                if(HAVE_SEM_INIT_run)
                        set(HAVE_SEM_INIT 0)
                else(HAVE_SEM_INIT_run)
@@ -212,7 +135,7 @@ if(pthread)
        ### HAVE_SEM_TIMEDWAIT
 
        if(HAVE_SEM_TIMEDWAIT_LIB)
-               exec_program("${CMAKE_C_COMPILER} -lpthread ${PROJECT_DIRECTORY}/buildtools/Cmake/test_prog/prog_sem_timedwait.c" OUTPUT_VARIABLE HAVE_SEM_TIMEDWAIT_run)
+               exec_program("${CMAKE_C_COMPILER} -lpthread ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_sem_timedwait.c" OUTPUT_VARIABLE HAVE_SEM_TIMEDWAIT_run)
                if(HAVE_SEM_TIMEDWAIT_run)
                        set(HAVE_SEM_TIMEDWAIT 0)
                else(HAVE_SEM_TIMEDWAIT_run)
@@ -223,7 +146,7 @@ if(pthread)
        ### HAVE_MUTEX_TIMEDLOCK
 
        if(HAVE_MUTEX_TIMEDLOCK_LIB)
-               exec_program("${CMAKE_C_COMPILER} -lpthread ${PROJECT_DIRECTORY}/buildtools/Cmake/test_prog/prog_mutex_timedlock.c" OUTPUT_VARIABLE HAVE_SEM_TIMEDWAIT_run)
+               exec_program("${CMAKE_C_COMPILER} -lpthread ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_mutex_timedlock.c" OUTPUT_VARIABLE HAVE_SEM_TIMEDWAIT_run)
                if(HAVE_MUTEX_TIMEDLOCK_run)
                        set(HAVE_MUTEX_TIMEDLOCK 0)
                else(HAVE_MUTEX_TIMEDLOCK_run)
@@ -240,31 +163,38 @@ endif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
 
 if(WIN32)
     if(__VISUALC__)
-       set(mcsc_flags "/D_XBT_WIN32 /I${PROJECT_DIRECTORY}/include/xbt /I${PROJECT_DIRECTORY}/src/xbt")
+       set(mcsc_flags "/D_XBT_WIN32 /I${CMAKE_HOME_DIRECTORY}/include/xbt /I${CMAKE_HOME_DIRECTORY}/src/xbt")
        endif(__VISUALC__)
        if(__GNUC__)
-               set(mcsc_flags "-D_XBT_WIN32 -I${PROJECT_DIRECTORY}/include/xbt -I${PROJECT_DIRECTORY}/src/xbt")
+               set(mcsc_flags "-D_XBT_WIN32 -I${CMAKE_HOME_DIRECTORY}/include/xbt -I${CMAKE_HOME_DIRECTORY}/src/xbt")
        endif(__GNUC__)
 endif(WIN32)
 
-try_run(RUN_mcsc_VAR COMPILE_mcsc_VAR
-       ${PROJECT_DIRECTORY}
-       ${PROJECT_DIRECTORY}/buildtools/Cmake/test_prog/prog_AC_CHECK_MCSC.c
-       COMPILE_DEFINITIONS "${mcsc_flags}"
-       OUTPUT_VARIABLE var_compil
-       )
-
-if(EXISTS "${simgrid_BINARY_DIR}/conftestval" AND COMPILE_mcsc_VAR)
-       file(READ "${simgrid_BINARY_DIR}/conftestval" mcsc)
-       STRING(REPLACE "\n" "" mcsc "${mcsc}")
-       if(mcsc)
-               set(mcsc "yes")
-       elseif(mcsc)
-               set(mcsc "no")
-       endif(mcsc)
-else(EXISTS "${simgrid_BINARY_DIR}/conftestval" AND COMPILE_mcsc_VAR)
-       set(mcsc "no")
-endif(EXISTS "${simgrid_BINARY_DIR}/conftestval" AND COMPILE_mcsc_VAR)
+IF(CMAKE_CROSSCOMPILING)
+       IF(WIN32)
+               set(windows_context "yes")
+               set(IS_WINDOWS 1)       
+       ENDIF(WIN32)
+ELSE(CMAKE_CROSSCOMPILING)
+       try_run(RUN_mcsc_VAR COMPILE_mcsc_VAR
+               ${simgrid_BINARY_DIR}
+               ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_AC_CHECK_MCSC.c
+               COMPILE_DEFINITIONS "${mcsc_flags}"
+               OUTPUT_VARIABLE var_compil
+               )
+               
+               if(EXISTS "${simgrid_BINARY_DIR}/conftestval" AND COMPILE_mcsc_VAR)
+                       file(READ "${simgrid_BINARY_DIR}/conftestval" mcsc)
+                       STRING(REPLACE "\n" "" mcsc "${mcsc}")
+                       if(mcsc)
+                               set(mcsc "yes")
+                       elseif(mcsc)
+                               set(mcsc "no")
+                       endif(mcsc)
+               else(EXISTS "${simgrid_BINARY_DIR}/conftestval" AND COMPILE_mcsc_VAR)
+                       set(mcsc "no")
+               endif(EXISTS "${simgrid_BINARY_DIR}/conftestval" AND COMPILE_mcsc_VAR)
+ENDIF(CMAKE_CROSSCOMPILING)
 
 if(mcsc MATCHES "no" AND pthread)
        if(HAVE_WINDOWS_H)
@@ -275,105 +205,84 @@ if(mcsc MATCHES "no" AND pthread)
        endif(HAVE_WINDOWS_H)
 endif(mcsc MATCHES "no" AND pthread)
 
-if(with_context MATCHES "ucontext" AND mcsc MATCHES "no")
-       message(FATAL_ERROR "-Dwith-context=ucontext specified but ucontext unusable.")
-endif(with_context MATCHES "ucontext" AND mcsc MATCHES "no")
+#Only windows
 
-set(with_context_ok 0)
-if(with_context MATCHES "windows")
-       set(with_context_ok 1)
+if(WIN32)
        if(NOT HAVE_WINDOWS_H)
                message(FATAL_ERROR "no appropriate backend found windows")
        endif(NOT HAVE_WINDOWS_H)
-endif(with_context MATCHES "windows")
-
-if(with_context MATCHES "pthreads")
-       set(with_context_ok 1)
-       set(with_context "pthread")
-endif(with_context MATCHES "pthreads")
-
-if(with_context MATCHES "auto")
-       set(with_context_ok 1)
-       set(with_context "ucontext")
-       message("with_context auto change to ucontext")
-endif(with_context MATCHES "auto")
-
-if(with_context MATCHES "ucontext")
-       set(with_context_ok 1)
-       if(mcsc)
-               set(CONTEXT_UCONTEXT 1)
-       else(mcsc)
-               if(windows_context MATCHES "yes")
-                       set(with_context "windows")
-                       message("with_context ucontext change to windows")
-               else(windows_context MATCHES "yes")
-                       set(with_context "pthread")
-                       message("with_context ucontext change to pthread")
-               endif(windows_context MATCHES "yes")
-       endif(mcsc)
-endif(with_context MATCHES "ucontext")
-
-if(with_context MATCHES "pthread")
-       set(with_context_ok 1)
-       if(NOT pthread)
-               message(FATAL_ERROR "Cannot find pthreads (try -Dwith_context=ucontext if you haven't already tried).")
-       endif(NOT pthread)
-       SET(CONTEXT_THREADS 1)
-endif(with_context MATCHES "pthread")
-
-if(with_context MATCHES "ucontext")
-       SET(CONTEXT_THREADS 0)
-endif(with_context MATCHES "ucontext")
-
-if(NOT with_context_ok)
-       message(FATAL_ERROR "-Dwith-context must be either ucontext or pthread")
-endif(NOT with_context_ok)
+endif(WIN32)
+
+if(windows_context MATCHES "yes")
+       message(STATUS "Context change to windows")
+endif(windows_context MATCHES "yes")
+
+#If can have both context
+
+if(mcsc)
+       set(CONTEXT_UCONTEXT 1)
+endif(mcsc)
+
+if(pthread)
+       set(CONTEXT_THREADS 1)
+endif(pthread)
+
 
 ###############
 ## SVN version check
 ##
-if(IS_DIRECTORY ${PROJECT_DIRECTORY}/.svn)
-       find_file(SVN ".svn" ${PROJECT_DIRECTORY})
-       exec_program("svnversion ${PROJECT_DIRECTORY}" OUTPUT_VARIABLE "SVN_VERSION")
-       message("SVN_VERSION : ${SVN_VERSION}")
-endif(IS_DIRECTORY ${PROJECT_DIRECTORY}/.svn)
+if(IS_DIRECTORY ${CMAKE_HOME_DIRECTORY}/.svn)
+       find_file(SVN ".svn" ${CMAKE_HOME_DIRECTORY})
+       exec_program("svnversion ${CMAKE_HOME_DIRECTORY}" OUTPUT_VARIABLE "SVN_VERSION")
+       message(STATUS "svn version ${SVN_VERSION}")
+endif(IS_DIRECTORY ${CMAKE_HOME_DIRECTORY}/.svn)
 
-if(IS_DIRECTORY ${PROJECT_DIRECTORY}/.git)
+if(IS_DIRECTORY ${CMAKE_HOME_DIRECTORY}/.git)
 
-       exec_program("git --git-dir=${PROJECT_DIRECTORY}/.git log --oneline -1" OUTPUT_VARIABLE "GIT_VERSION")
-       exec_program("git --git-dir=${PROJECT_DIRECTORY}/.git log -n 1 --format=%ai ." OUTPUT_VARIABLE "GIT_DATE")
-       exec_program("git svn info" ${PROJECT_DIRECTORY} OUTPUT_VARIABLE "GIT_SVN_VERSION")
+       exec_program("git --git-dir=${CMAKE_HOME_DIRECTORY}/.git log --oneline -1" OUTPUT_VARIABLE "GIT_VERSION")
+       exec_program("git --git-dir=${CMAKE_HOME_DIRECTORY}/.git log -n 1 --format=%ai ." OUTPUT_VARIABLE "GIT_DATE")
+       exec_program("git svn info" ${CMAKE_HOME_DIRECTORY} OUTPUT_VARIABLE "GIT_SVN_VERSION")
        
        string(REGEX REPLACE " .*" "" GIT_VERSION "${GIT_VERSION}")
-       string(REPLACE "\n" ";" GIT_SVN_VERSION ${GIT_SVN_VERSION})
        STRING(REPLACE " +0000" "" GIT_DATE ${GIT_DATE})
        STRING(REPLACE " " "~" GIT_DATE ${GIT_DATE})
        STRING(REPLACE ":" "-" GIT_DATE ${GIT_DATE})
-       foreach(line ${GIT_SVN_VERSION})
-               string(REGEX MATCH "^Revision:.*" line_good ${line})
-               if(line_good)
-                       string(REPLACE "Revision: " "" line_good ${line_good})
-                       set(SVN_VERSION ${line_good})
-               endif(line_good)
-       endforeach(line ${GIT_SVN_VERSION})
-endif(IS_DIRECTORY ${PROJECT_DIRECTORY}/.git)
+
+       exec_program("git config --get svn-remote.svn.url"
+               OUTPUT_VARIABLE url
+               RETURN_VALUE ret)
+       if(ret EQUAL 0)
+               exec_program("git svn info" ${CMAKE_HOME_DIRECTORY}
+                       OUTPUT_VARIABLE "GIT_SVN_VERSION")
+               string(REPLACE "\n" ";" GIT_SVN_VERSION ${GIT_SVN_VERSION})
+               foreach(line ${GIT_SVN_VERSION})
+                       string(REGEX MATCH "^Revision:.*" line_good ${line})
+                       if(line_good)
+                               string(REPLACE "Revision: " ""
+                                       line_good ${line_good})
+                               set(SVN_VERSION ${line_good})
+                       endif(line_good)
+               endforeach(line ${GIT_SVN_VERSION})
+       endif(ret EQUAL 0)
+endif(IS_DIRECTORY ${CMAKE_HOME_DIRECTORY}/.git)
 
 ###################################
 ## SimGrid and GRAS specific checks
 ##
 
+IF(NOT CMAKE_CROSSCOMPILING)
 # Check architecture signature begin
 try_run(RUN_GRAS_VAR COMPILE_GRAS_VAR
-       ${PROJECT_DIRECTORY}
-       ${PROJECT_DIRECTORY}/buildtools/Cmake/test_prog/prog_GRAS_ARCH.c
+       ${simgrid_BINARY_DIR}
+       ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_GRAS_ARCH.c
        RUN_OUTPUT_VARIABLE var1
        )
 if(BIGENDIAN)
-set(val_big "B${var1}")
-set(GRAS_BIGENDIAN 1)
+  set(val_big "B${var1}")
+  set(GRAS_BIGENDIAN 1)
 else(BIGENDIAN)
-set(val_big "l${var1}")
-set(GRAS_BIGENDIAN 0)
+  set(val_big "l${var1}")
+  set(GRAS_BIGENDIAN 0)
 endif(BIGENDIAN)
 
 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:")
@@ -436,8 +345,8 @@ 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:")
 
 # Check architecture signature end
 try_run(RUN_GRAS_VAR COMPILE_GRAS_VAR
-       ${PROJECT_DIRECTORY}
-       ${PROJECT_DIRECTORY}/buildtools/Cmake/test_prog/prog_GRAS_CHECK_STRUCT_COMPACTION.c
+       ${simgrid_BINARY_DIR}
+       ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_GRAS_CHECK_STRUCT_COMPACTION.c
        RUN_OUTPUT_VARIABLE var2
        )
 separate_arguments(var2)
@@ -447,11 +356,12 @@ endforeach(var_tmp ${var2})
 
 # Check for [SIZEOF_MAX]
 try_run(RUN_SM_VAR COMPILE_SM_VAR
-       ${PROJECT_DIRECTORY}
-       ${PROJECT_DIRECTORY}/buildtools/Cmake/test_prog/prog_max_size.c
+       ${simgrid_BINARY_DIR}
+       ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_max_size.c
        RUN_OUTPUT_VARIABLE var3
        )
 SET(SIZEOF_MAX ${var3})
+ENDIF(NOT CMAKE_CROSSCOMPILING)
 
 #--------------------------------------------------------------------------------------------------
 
@@ -462,20 +372,18 @@ if(HAVE_MAKECONTEXT OR WIN32)
                set(makecontext_CPPFLAGS_2 "-DOSX")
        endif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
        
-    if(WIN32)
-        if(__VISUALC__)
-            set(makecontext_CPPFLAGS "/DTEST_makecontext")
-           set(makecontext_CPPFLAGS_2 "/D_XBT_WIN32 /I${PROJECT_DIRECTORY}/include/xbt /I${PROJECT_DIRECTORY}/src/xbt")
-       endif(__VISUALC__)
-       if(__GNUC__)
-           set(makecontext_CPPFLAGS "-DTEST_makecontext")
-               set(makecontext_CPPFLAGS_2 "-D_XBT_WIN32 -I${PROJECT_DIRECTORY}/include/xbt -I${PROJECT_DIRECTORY}/src/xbt")
-       endif(__GNUC__)
-    endif(WIN32)
-
+    if(WIN32 AND __VISUALC__)
+        set(makecontext_CPPFLAGS "/DTEST_makecontext")
+           set(makecontext_CPPFLAGS_2 "/D_XBT_WIN32 /I${CMAKE_HOME_DIRECTORY}/include/xbt /I${CMAKE_HOME_DIRECTORY}/src/xbt")
+       endif(WIN32 AND __VISUALC__)
+       if(WIN32 AND __GNUC__)
+           set(makecontext_CPPFLAGS "-DTEST_makecontext")
+           set(makecontext_CPPFLAGS_2 "-D_XBT_WIN32 -I${CMAKE_HOME_DIRECTORY}/include/xbt -I${CMAKE_HOME_DIRECTORY}/src/xbt")
+       endif(WIN32 AND __GNUC__)
+       
        try_run(RUN_makecontext_VAR COMPILE_makecontext_VAR
-               ${PROJECT_DIRECTORY}
-               ${PROJECT_DIRECTORY}/buildtools/Cmake/test_prog/prog_stacksetup.c
+               ${simgrid_BINARY_DIR}
+               ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_stacksetup.c
                COMPILE_DEFINITIONS "${makecontext_CPPFLAGS} ${makecontext_CPPFLAGS_2}"
                )
        file(READ ${simgrid_BINARY_DIR}/conftestval MAKECONTEXT_ADDR_SIZE)
@@ -486,15 +394,16 @@ if(HAVE_MAKECONTEXT OR WIN32)
        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(HAVE_MAKECONTEXT OR WIN32)
 
 #--------------------------------------------------------------------------------------------------
 
 ### check for stackgrowth
-
+if (NOT CMAKE_CROSSCOMPILING)
        try_run(RUN_makecontext_VAR COMPILE_makecontext_VAR
-               ${PROJECT_DIRECTORY}
-               ${PROJECT_DIRECTORY}/buildtools/Cmake/test_prog/prog_stackgrowth.c
+               ${simgrid_BINARY_DIR}
+               ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_stackgrowth.c
                )
 file(READ "${simgrid_BINARY_DIR}/conftestval" stack)
 if(stack MATCHES "down")
@@ -504,6 +413,7 @@ if(stack MATCHES "up")
        set(PTH_STACKGROWTH "1")
 endif(stack MATCHES "up")
 
+endif(NOT CMAKE_CROSSCOMPILING)
 ###############
 ## System checks
 ##
@@ -517,8 +427,8 @@ endif(stack MATCHES "up")
 
 #AC_PRINTF_NULL
 try_run(RUN_PRINTF_NULL_VAR COMPILE_PRINTF_NULL_VAR
-       ${PROJECT_DIRECTORY}
-       ${PROJECT_DIRECTORY}/buildtools/Cmake/test_prog/prog_printf_null.c
+       ${simgrid_BINARY_DIR}
+       ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_printf_null.c
        )
 
 if(RUN_PRINTF_NULL_VAR MATCHES "FAILED_TO_RUN")
@@ -535,12 +445,12 @@ set(diff_va "va_copy((d),(s))"
 "__builtin_va_copy((d),(s))"
 "do { (d) = (s)\; } while (0)"
 "do { *(d) = *(s)\; } while (0)"
-"memcpy((void *)&(d), (void *)&(s)), sizeof((s))"
-"memcpy((void *)(d), (void *)(s)), sizeof(*(s))"
+"memcpy((void *)&(d), (void *)&(s), sizeof(s))"
+"memcpy((void *)(d), (void *)(s), sizeof(*(s)))"
 )
 
 foreach(fct ${diff_va})
-       write_file("${PROJECT_DIRECTORY}/buildtools/Cmake/test_prog/prog_va_copy.c" "#include <stdlib.h>
+       write_file("${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_va_copy.c" "#include <stdlib.h>
        #include <stdarg.h>
        #include <string.h>
        #define DO_VA_COPY(d,s) ${fct}
@@ -570,8 +480,8 @@ foreach(fct ${diff_va})
        }"
        )
        try_compile(COMPILE_VA_NULL_VAR
-       ${PROJECT_DIRECTORY}
-       ${PROJECT_DIRECTORY}/buildtools/Cmake/test_prog/prog_va_copy.c
+       ${simgrid_BINARY_DIR}
+       ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_va_copy.c
        )
        if(COMPILE_VA_NULL_VAR)
                string(REGEX REPLACE "\;" "" fctbis ${fct})
@@ -606,15 +516,15 @@ foreach(fct ${diff_va})
                        set(__VA_COPY_USE_ASP "do { *(d) = *(s); } while (0)")
                endif(${fctbis} STREQUAL "do { *(d) = *(s) } while (0)")
 
-               if(${fctbis} STREQUAL "memcpy((void *)&(d), (void *)&(s)), sizeof((s))")
+               if(${fctbis} STREQUAL "memcpy((void *)&(d), (void *)&(s), sizeof(s))")
                        set(ac_cv_va_copy "CPS")
-                       set(__VA_COPY_USE_CPS "memcpy((void *)&(d), (void *)&(s)), sizeof((s))")
-               endif(${fctbis} STREQUAL "memcpy((void *)&(d), (void *)&(s)), sizeof((s))")
+                       set(__VA_COPY_USE_CPS "memcpy((void *)&(d), (void *)&(s), sizeof(s))")
+               endif(${fctbis} STREQUAL "memcpy((void *)&(d), (void *)&(s), sizeof(s))")
 
-               if(${fctbis} STREQUAL "memcpy((void *)(d), (void *)(s)), sizeof(*(s))")
+               if(${fctbis} STREQUAL "memcpy((void *)(d), (void *)(s), sizeof(*(s)))")
                        set(ac_cv_va_copy "CPP")
-                       set(__VA_COPY_USE_CPP "memcpy((void *)(d), (void *)(s)), sizeof(*(s))")
-               endif(${fctbis} STREQUAL "memcpy((void *)(d), (void *)(s)), sizeof(*(s))")
+                       set(__VA_COPY_USE_CPP "memcpy((void *)(d), (void *)(s), sizeof(*(s)))")
+               endif(${fctbis} STREQUAL "memcpy((void *)(d), (void *)(s), sizeof(*(s)))")
                                
                if(NOT STATUS_OK)
                set(__VA_COPY_USE "__VA_COPY_USE_${ac_cv_va_copy}(d, s)")
@@ -626,11 +536,10 @@ foreach(fct ${diff_va})
 endforeach(fct ${diff_va})
 
 #--------------------------------------------------------------------------------------------------
-### Try execut getline command
-try_run(RUN_RESULT_VAR COMPILE_RESULT_VAR
-       ${PROJECT_DIRECTORY}
-       ${PROJECT_DIRECTORY}/buildtools/Cmake/test_prog/prog_getline.c
-       OUTPUT_VARIABLE GETLINE_OUTPUT
+### check for getline
+try_compile(COMPILE_RESULT_VAR
+       ${simgrid_BINARY_DIR}
+       ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_getline.c
        )
 
 if(NOT COMPILE_RESULT_VAR)
@@ -642,23 +551,32 @@ SET(SIMGRID_NEED_GETLINE 0)
 endif(NOT COMPILE_RESULT_VAR)
 
 ### check for a working snprintf
-if(HAVE_SNPRINTF AND HAVE_VSNPRINTF)
-
-       try_run(RUN_SNPRINTF_FUNC_VAR COMPILE_SNPRINTF_FUNC_VAR
-               ${PROJECT_DIRECTORY}
-               ${PROJECT_DIRECTORY}/buildtools/Cmake/test_prog/prog_snprintf.c
-               )
+if(HAVE_SNPRINTF AND HAVE_VSNPRINTF OR WIN32)
+    if(WIN32)
+        #set(HAVE_SNPRINTF 1)
+        #set(HAVE_VSNPRINTF 1)
+    endif(WIN32)
+    
        if(CMAKE_CROSSCOMPILING)
-               set(RUN_SNPRINTF_FUNC "cross") 
+               set(RUN_SNPRINTF_FUNC "cross")
+               #set(PREFER_PORTABLE_SNPRINTF 1)
+       else(CMAKE_CROSSCOMPILING)
+           try_run(RUN_SNPRINTF_FUNC_VAR COMPILE_SNPRINTF_FUNC_VAR
+               ${simgrid_BINARY_DIR}
+               ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_snprintf.c
+           )   
        endif(CMAKE_CROSSCOMPILING)
 
-       try_run(RUN_VSNPRINTF_FUNC_VAR COMPILE_VSNPRINTF_FUNC_VAR
-               ${PROJECT_DIRECTORY}
-               ${PROJECT_DIRECTORY}/buildtools/Cmake/test_prog/prog_vsnprintf.c
-               )
        if(CMAKE_CROSSCOMPILING)
                set(RUN_VSNPRINTF_FUNC "cross")
+               set(PREFER_PORTABLE_VSNPRINTF 1)
+       else(CMAKE_CROSSCOMPILING)
+          try_run(RUN_VSNPRINTF_FUNC_VAR COMPILE_VSNPRINTF_FUNC_VAR
+               ${simgrid_BINARY_DIR}
+               ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_vsnprintf.c
+          )
        endif(CMAKE_CROSSCOMPILING)
+       
        set(PREFER_PORTABLE_SNPRINTF 0)
        if(RUN_VSNPRINTF_FUNC_VAR MATCHES "FAILED_TO_RUN")
                set(PREFER_PORTABLE_SNPRINTF 1)
@@ -666,7 +584,7 @@ if(HAVE_SNPRINTF AND HAVE_VSNPRINTF)
        if(RUN_SNPRINTF_FUNC_VAR MATCHES "FAILED_TO_RUN")
                set(PREFER_PORTABLE_SNPRINTF 1)
        endif(RUN_SNPRINTF_FUNC_VAR MATCHES "FAILED_TO_RUN")
-endif(HAVE_SNPRINTF AND HAVE_VSNPRINTF)
+endif(HAVE_SNPRINTF AND HAVE_VSNPRINTF OR WIN32)
 
 ### check for asprintf function familly
 if(HAVE_ASPRINTF)
@@ -694,28 +612,32 @@ endif(ADDR2LINE)
 
 ### File to create
 
-configure_file("${PROJECT_DIRECTORY}/src/context_sysv_config.h.in"                     "${PROJECT_DIRECTORY}/src/context_sysv_config.h" @ONLY IMMEDIATE)
+configure_file("${CMAKE_HOME_DIRECTORY}/src/context_sysv_config.h.in"                  "${CMAKE_CURRENT_BINARY_DIR}/src/context_sysv_config.h" @ONLY IMMEDIATE)
 
 SET( CMAKEDEFINE "#cmakedefine" )
-configure_file("${PROJECT_DIRECTORY}/buildtools/Cmake/gras_config.h.in"        "${PROJECT_DIRECTORY}/src/gras_config.h" @ONLY IMMEDIATE)
-configure_file("${PROJECT_DIRECTORY}/src/gras_config.h"                                "${PROJECT_DIRECTORY}/src/gras_config.h" @ONLY IMMEDIATE)
-configure_file("${PROJECT_DIRECTORY}/include/simgrid_config.h.in"                      "${PROJECT_DIRECTORY}/include/simgrid_config.h" @ONLY IMMEDIATE)
-#configure_file("${PROJECT_DIRECTORY}/buildtools/Cmake/tracing_config.h.in"    "${PROJECT_DIRECTORY}/include/instr/tracing_config.h" @ONLY IMMEDIATE)
-#configure_file("${PROJECT_DIRECTORY}/include/instr/tracing_config.h"          "${PROJECT_DIRECTORY}/include/instr/tracing_config.h" @ONLY IMMEDIATE)
-
-set(top_srcdir "${PROJECT_DIRECTORY}")
-set(srcdir "${PROJECT_DIRECTORY}/src")
-
-set(exec_prefix ${prefix})
-set(includedir ${prefix}/include)
-set(top_builddir ${PROJECT_DIRECTORY})
+configure_file("${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/gras_config.h.in"     "${CMAKE_CURRENT_BINARY_DIR}/src/gras_config.h" @ONLY IMMEDIATE)
+configure_file("${CMAKE_CURRENT_BINARY_DIR}/src/gras_config.h"                         "${CMAKE_CURRENT_BINARY_DIR}/src/gras_config.h" @ONLY IMMEDIATE)
+configure_file("${CMAKE_HOME_DIRECTORY}/include/simgrid_config.h.in"           "${CMAKE_CURRENT_BINARY_DIR}/include/simgrid_config.h" @ONLY IMMEDIATE)
+
+set(top_srcdir "${CMAKE_HOME_DIRECTORY}")
+set(srcdir "${CMAKE_HOME_DIRECTORY}/src")
+
+set(exec_prefix ${CMAKE_INSTALL_PREFIX})
+set(includedir ${CMAKE_INSTALL_PREFIX}/include)
+set(top_builddir ${CMAKE_HOME_DIRECTORY})
 set(libdir ${exec_prefix}/lib)
 set(CMAKE_LINKARGS "${CMAKE_CURRENT_BINARY_DIR}/lib")
+set(CMAKE_SMPI_COMMAND "export LD_LIBRARY_PATH=${CMAKE_CURRENT_BINARY_DIR}/lib:${GTNETS_LIB_PATH}:$LD_LIBRARY_PATH")
 
-configure_file(${PROJECT_DIRECTORY}/src/smpi/smpicc.in ${CMAKE_CURRENT_BINARY_DIR}/bin/smpicc @ONLY)
-configure_file(${PROJECT_DIRECTORY}/src/smpi/smpirun.in ${CMAKE_CURRENT_BINARY_DIR}/bin/smpirun @ONLY)
-configure_file(${PROJECT_DIRECTORY}/examples/smpi/hostfile ${CMAKE_CURRENT_BINARY_DIR}/examples/smpi/hostfile COPYONLY)
-configure_file(${PROJECT_DIRECTORY}/examples/msg/small_platform.xml ${CMAKE_CURRENT_BINARY_DIR}/examples/msg/small_platform.xml COPYONLY)
+configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpicc.in ${CMAKE_CURRENT_BINARY_DIR}/bin/smpicc @ONLY)
+configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpif2c.in ${CMAKE_CURRENT_BINARY_DIR}/bin/smpif2c @ONLY)
+configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpiff.in ${CMAKE_CURRENT_BINARY_DIR}/bin/smpiff @ONLY)
+configure_file(${CMAKE_HOME_DIRECTORY}/src/smpi/smpirun.in ${CMAKE_CURRENT_BINARY_DIR}/bin/smpirun @ONLY)
+configure_file(${CMAKE_HOME_DIRECTORY}/examples/smpi/hostfile ${CMAKE_CURRENT_BINARY_DIR}/examples/smpi/hostfile COPYONLY)
+configure_file(${CMAKE_HOME_DIRECTORY}/examples/msg/small_platform.xml ${CMAKE_CURRENT_BINARY_DIR}/examples/msg/small_platform.xml COPYONLY)
+configure_file(${CMAKE_HOME_DIRECTORY}/examples/msg/small_platform_with_routers.xml ${CMAKE_CURRENT_BINARY_DIR}/examples/msg/small_platform_with_routers.xml COPYONLY)
 
 exec_program("chmod a=rwx ${CMAKE_CURRENT_BINARY_DIR}/bin/smpicc" OUTPUT_VARIABLE OKITOKI)
+exec_program("chmod a=rwx ${CMAKE_CURRENT_BINARY_DIR}/bin/smpif2c" OUTPUT_VARIABLE OKITOKI)
+exec_program("chmod a=rwx ${CMAKE_CURRENT_BINARY_DIR}/bin/smpiff" OUTPUT_VARIABLE OKITOKI)
 exec_program("chmod a=rwx ${CMAKE_CURRENT_BINARY_DIR}/bin/smpirun" OUTPUT_VARIABLE OKITOKI)