+ unset(CMAKE_INCLUDE_WIN)
+endif()
+
+include_directories(${INCLUDES})
+
+# library dependency cannot start with a space (CMP0004), so initialize it with something that is never desactivated.
+set(SIMGRID_DEP "-lm")
+
+### Determine the assembly flavor that we need today
+set(HAVE_RAW_CONTEXTS 0)
+include(CMakeDetermineSystem)
+IF(CMAKE_SYSTEM_PROCESSOR MATCHES ".86|AMD64|amd64")
+ IF(CMAKE_SIZEOF_VOID_P EQUAL 4) # 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 (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)
+include(CheckTypeSize)
+include(CheckIncludeFile)
+include(CheckIncludeFiles)
+include(CheckLibraryExists)
+include(CheckSymbolExists)
+
+set(HAVE_GRAPHVIZ 0)
+include(FindGraphviz)
+
+set(HAVE_LUA 0)
+if(enable_lua)
+ include(FindLuaSimgrid)
+endif()
+
+set(HAVE_NS3 0)
+if(enable_ns3)
+ include(FindNS3)
+ if (NOT HAVE_NS3)
+ message(FATAL_ERROR "Cannot find NS3. Please install it (apt-get install ns3 libns3-dev) or disable that cmake option")
+ endif()
+endif()
+
+if(WIN32)
+ set(Boost_USE_STATIC_LIBS 1)
+endif()
+set(HAVE_PAPI 0)
+if(enable_smpi_papi)
+ include(FindPAPI)
+ if (NOT HAVE_PAPI)
+ message(FATAL_ERROR "Cannot find PAPI. Please install it (apt-get install papi-tools libpapi-dev) or disable PAPI bindings.")
+ endif()
+endif()
+
+find_package(Boost 1.48)
+if(Boost_FOUND)
+ include_directories(${Boost_INCLUDE_DIRS})
+else()
+ if(APPLE)
+ message(FATAL_ERROR "Failed to find Boost libraries (Try to install them with 'sudo fink install boost1.53.nopython')")
+ else()
+ message(FATAL_ERROR "Failed to find Boost libraries."
+ "Did you install libboost-dev and libboost-context-dev?"
+ "(libboost-context-dev is optional)"
+ "SimGrid requires Boost >= 1.48.0")
+ endif()
+endif()
+
+#Boost context 1.61 will break compatibility with our implementation.
+#Warn users about that
+find_package(Boost 1.61 COMPONENTS context)
+
+if(Boost_FOUND AND Boost_CONTEXT_FOUND)
+ message("WARNING : our implementation of Boost context factory is not compatible with Boost >=1.61 yet.")
+
+ set(Boost_FOUND 1)
+ set(HAVE_BOOST_CONTEXTS 0)
+else()
+# Try again to see if we have libboost-context
+ find_package(Boost 1.42 COMPONENTS context)
+ set(Boost_FOUND 1) # We don't care of whether this component is missing
+
+ if(Boost_FOUND AND Boost_CONTEXT_FOUND)
+ # We should use feature detection for this instead:
+ if (Boost_VERSION LESS 105600)
+ message("Found Boost.Context API v1")
+ set(HAVE_BOOST_CONTEXTS 1)
+ else()
+ message("Found Boost.Context API v2")
+ set(HAVE_BOOST_CONTEXTS 2)
+ endif()
+ else()
+ message (" boost : found.")
+ message (" boost-context: missing. Install libboost-context-dev for this optional feature.")
+ set(HAVE_BOOST_CONTEXTS 0)
+ endif()
+endif()
+
+# Checks for header libraries functions.
+CHECK_LIBRARY_EXISTS(rt clock_gettime "" HAVE_POSIX_GETTIME)
+
+CHECK_LIBRARY_EXISTS(pthread pthread_create "" HAVE_PTHREAD)
+if(NOT APPLE) # OS X El Capitan deprecates this function
+ CHECK_LIBRARY_EXISTS(pthread sem_init "" HAVE_SEM_INIT_LIB)
+endif()
+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")
+ set(CMAKE_REQUIRED_DEFINITIONS "-D_XOPEN_SOURCE=700 -D_DARWIN_C_SOURCE")
+elseif(MINGW)
+ # Use the GNU version of unusual modifiers like PRIx64
+ add_definitions(-D__USE_MINGW_ANSI_STDIO=1)
+ set(CMAKE_REQUIRED_DEFINITIONS "-D__USE_MINGW_ANSI_STDIO=1")
+else()
+ set(CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE")
+endif()
+
+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)
+CHECK_INCLUDE_FILE("sys/param.h" HAVE_SYS_PARAM_H)
+CHECK_INCLUDE_FILE("sys/sysctl.h" HAVE_SYS_SYSCTL_H)
+CHECK_INCLUDE_FILE("ucontext.h" HAVE_UCONTEXT_H)
+CHECK_INCLUDE_FILE("linux/futex.h" HAVE_FUTEX_H)
+
+CHECK_FUNCTION_EXISTS(backtrace HAVE_BACKTRACE)
+CHECK_FUNCTION_EXISTS(dlfunc HAVE_DLFUNC)
+CHECK_FUNCTION_EXISTS(gettimeofday HAVE_GETTIMEOFDAY)
+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_FUNCTION_EXISTS(mremap HAVE_MREMAP)
+
+CHECK_SYMBOL_EXISTS(vasprintf stdio.h HAVE_VASPRINTF)
+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 if __thread is defined
+execute_process(
+ 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)
+file(REMOVE testprog)
+if(HAVE_thread_storage_run)
+ set(HAVE_THREAD_LOCAL_STORAGE 1)
+else()
+ set(HAVE_THREAD_LOCAL_STORAGE 0)
+endif()
+
+if(enable_model-checking AND NOT "${CMAKE_SYSTEM}" MATCHES "Linux")
+ message(WARNING "Support for model-checking has not been enabled on ${CMAKE_SYSTEM}: disabling it")
+ set(enable_model-checking FALSE)
+endif()
+
+if(HAVE_MMAP AND HAVE_THREAD_LOCAL_STORAGE)
+ SET(HAVE_MMALLOC 1)
+else()
+ SET(HAVE_MMALLOC 0)
+ if(enable_model-checking)
+ message(STATUS "Warning: support for model-checking has been disabled because you are missing either mmap or __thread.")
+ endif()
+ SET(enable_model-checking 0)
+endif()
+
+if(enable_jedule)
+ set(HAVE_JEDULE 1)
+else()
+ set(HAVE_JEDULE 0)
+endif()
+
+if(enable_mallocators)
+ SET(HAVE_MALLOCATOR 1)
+else()
+ SET(HAVE_MALLOCATOR 0)
+endif()
+
+include(FindLibunwind)
+if(HAVE_LIBUNWIND)
+ if(NOT APPLE)
+ SET(SIMGRID_DEP "${SIMGRID_DEP} -lunwind")
+ else()
+ # Apple forbids to link directly against its libunwind implementation
+ # So let's comply and link against the System framework
+ SET(SIMGRID_DEP "${SIMGRID_DEP} -lSystem")
+ endif()
+ if("${CMAKE_SYSTEM}" MATCHES "Linux")
+ set(SIMGRID_DEP "${SIMGRID_DEP} -lunwind-ptrace")
+ # This supposes that the host machine is either an AMD or a X86.
+ # This is deeply wrong, and should be fixed by manually loading -lunwind-PLAT (FIXME)
+ if(PROCESSOR_x86_64)
+ SET(SIMGRID_DEP "${SIMGRID_DEP} -lunwind-x86_64")
+ else()
+ SET(SIMGRID_DEP "${SIMGRID_DEP} -lunwind-x86")
+ endif()
+ endif()
+else()
+ if(enable_model-checking)
+ message(FATAL_ERROR "Please either install the libunwind7-dev package (or equivalent) or turn off the model-checking option of SimGrid.")
+ endif()
+endif()
+
+if(enable_model-checking)
+ SET(HAVE_MC 1)
+
+ include(FindLibdw)
+ SET(SIMGRID_DEP "${SIMGRID_DEP} -ldw")
+else()
+ SET(HAVE_MC 0)
+ set(HAVE_MMALLOC 0)
+endif()
+
+if (enable_model-checking AND enable_ns3)
+ message(FATAL_ERROR "Cannot activate both model-checking and NS3 bindings: NS3 pull too much dependencies for the MC to work")
+endif()
+
+if(enable_smpi)
+ SET(HAVE_SMPI 1)
+ if("${CMAKE_SYSTEM}" MATCHES "Linux|FreeBSD")
+ SET(USE_LIBUTIL 0)
+ SET(HAVE_PRIVATIZATION 1)
+ else()
+ message (STATUS "Warning: no support for SMPI automatic privatization on this platform")
+ SET(HAVE_PRIVATIZATION 0)
+ endif()
+else()
+ SET(HAVE_SMPI 0)
+endif()
+
+#--------------------------------------------------------------------------------------------------
+### Check for GNU dynamic linker
+CHECK_INCLUDE_FILE("dlfcn.h" HAVE_DLFCN_H)
+if (HAVE_DLFCN_H)
+ execute_process(COMMAND ${CMAKE_C_COMPILER} ${CMAKE_HOME_DIRECTORY}/tools/cmake/test_prog/prog_gnu_dynlinker.c ${DL_LIBRARY} -o test_gnu_ld
+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+ OUTPUT_VARIABLE HAVE_GNU_LD_compil
+ )
+ if(HAVE_GNU_LD_compil)
+ set(HAVE_GNU_LD 0)
+ message(STATUS "Warning: test program toward GNU ld failed to compile:")
+ message(STATUS "${HAVE_GNU_LD_comp_output}")
+ else()
+ execute_process(COMMAND ./test_gnu_ld
+ WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
+ RESULT_VARIABLE HAVE_GNU_LD_run
+ OUTPUT_VARIABLE var_exec
+ )
+
+ if(NOT HAVE_GNU_LD_run)
+ set(HAVE_GNU_LD 1)
+ message(STATUS "We are using GNU dynamic linker")
+ else()
+ set(HAVE_GNU_LD 0)
+ message(STATUS "Warning: error while checking for GNU ld:")
+ message(STATUS "Test output: '${var_exec}'")
+ message(STATUS "Exit status: ${HAVE_GNU_LD_run}")
+ endif()
+ file(REMOVE test_gnu_ld)
+ endif()
+endif()
+
+#--------------------------------------------------------------------------------------------------
+### Initialize of CONTEXT THREADS