Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
ignore more cruft
[simgrid.git] / CMakeLists.txt
index f89dd8d..3094852 100644 (file)
@@ -1,16 +1,74 @@
 cmake_minimum_required(VERSION 2.6)
+# Java requires 2.8.6
+message(STATUS "Cmake version ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}")
+
+project(SimGrid C CXX)
+
+#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
+#     Check for the compiler        #
+#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
+
 ### Need to set rc ccompiler before enable language
 if(WIN32)
   SET(CMAKE_RC_COMPILER "windres")
 endif()
-project(SimGrid C)
-if (enable_gtnets OR enable_ns3 OR enable_model-checking)
-  enable_language(CXX)
-endif()
 
-enable_language(CXX)
+## 
+## Check the C/C++ standard that we need
+##   See also tools/cmake/GCCFlags.cmake that sets our paranoid warning flags
+if (MSVC)
+  message("-- You are compiling SimGrid with MicroSoft Visual C. Good luck.")
+
+  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_SCL_SECURE_NO_WARNINGS")
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_SCL_SECURE_NO_WARNINGS")
+else() # gcc or clang
+  INCLUDE(CheckCCompilerFlag)
+  CHECK_C_COMPILER_FLAG(-fstack-cleaner HAVE_C_STACK_CLEANER)
+
+  ## Request full debugging flags
+  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g3")
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3")
+  set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -g")
+
+  if (CMAKE_COMPILER_IS_GNUCC)
+    if (COMPILER_CXX_VERSION_MAJOR_MINOR STRLESS "4.7")
+      message(FATAL_ERROR
+              "SimGrid needs at least g++ version 4.7 to compile "
+             "(c++11 support of previous versions is too limited).")
+    endif()
+  endif()
+
+  ## We need a decent support of the c++11 standard
+  include(CheckCXXCompilerFlag)
+  CHECK_CXX_COMPILER_FLAG("-std=gnu++11" COMPILER_SUPPORTS_CXX11)
+  if(COMPILER_SUPPORTS_CXX11)
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
+  else() 
+    message(FATAL_ERROR 
+            "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. "
+            "Please use a decent C++ compiler.")
+  endif()
 
-if (NOT DEFINED enable_smpi OR enable_smpi) # smpi is enabled by default
+  ### And we need C11 standard, too
+  include(CheckCCompilerFlag)
+  CHECK_C_COMPILER_FLAG("-std=gnu11" COMPILER_SUPPORTS_C11)
+  if(COMPILER_SUPPORTS_C11)
+    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11")
+  else()
+    message(FATAL_ERROR 
+            "The compiler ${CMAKE_C_COMPILER} has no C11 support. "
+            "Please use a decent C compiler "
+            "(note that c++11 support of ${CMAKE_CXX_COMPILER} seems ok).")
+  endif()
+  if(APPLE AND ("4.6" GREATER COMPILER_C_VERSION_MAJOR_MINOR))
+      ### gcc 4.[1-5] cannot compile ucontext on OSX
+      message(STATUS "Ucontext can't be used with this version of gcc (must be greater than 4.5)")
+      set(HAVE_UCONTEXT_H 0)
+  endif()
+endif() # NOT MSVC
+
+### SMPI vs. Fortran
+if ((NOT DEFINED enable_smpi OR enable_smpi) AND NOT APPLE) # smpi is enabled by default
   # Call enable_language(Fortran) in order to load the build rules for
   # this language, needed by teshsuite/smpi/mpich-test/.  Use
   # CMAKE_FORCE_Fortran_COMPILER to bypass checks for a working
@@ -34,30 +92,16 @@ if (NOT DEFINED enable_smpi OR enable_smpi) # smpi is enabled by default
   enable_language(Fortran OPTIONAL)
 endif()
 
-set(CMAKE_C_FLAGS "" CACHE TYPE INTERNAL FORCE)
-set(CMAKE_CXX_FLAGS "" CACHE TYPE INTERNAL FORCE)
-set(CMAKE_EXE_LINKER_FLAGS "" CACHE TYPE INTERNAL FORCE)
-set(CMAKE_C_LINK_FLAGS "" CACHE TYPE INTERNAL FORCE)
-set(CMAKE_Fortran_FLAGS "" CACHE TYPE INTERNAL FORCE)
-set(CMAKE_Fortran_LINK_FLAGS "" CACHE TYPE INTERNAL FORCE)
-## Mapping version number -> version name
-# 3.5.99 -> alpha1 (oops)
-# 3.5.9{1,2} -> beta{1,2}
-# 3.5.9{3,4,5} -> rc{1,2,3}
-# 3.6.{0,1,2} -> release 3.6, 3.6.1, 3.6.2
-# 3.7.{0,1} -> release 3.7, 3.7.1
-# 3.8.{0,1} -> release 3.8, 3.8.1
-# 3.9.0 -> release 3.9
-# 3.9.90 -> release 3.10pre1
-# 3.10.0 -> release 3.10
-# 3.11.0 -> release 3.11
+#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
+#     Build the version number      #
+#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
 
 set(SIMGRID_VERSION_MAJOR "3")
-set(SIMGRID_VERSION_MINOR "12")
+set(SIMGRID_VERSION_MINOR "13")
 set(SIMGRID_VERSION_PATCH "0")
 set(SIMGRID_VERSION_EXTRA "-devel") # Extra words to add to version string (e.g. -rc1)
 
-set(SIMGRID_VERSION_DATE  "2014") # Year for copyright information
+set(SIMGRID_VERSION_DATE  "2015") # Year for copyright information
 
 if(${SIMGRID_VERSION_PATCH} EQUAL "0")
   set(release_version "${SIMGRID_VERSION_MAJOR}.${SIMGRID_VERSION_MINOR}")
@@ -65,15 +109,14 @@ else()
   set(release_version "${SIMGRID_VERSION_MAJOR}.${SIMGRID_VERSION_MINOR}.${SIMGRID_VERSION_PATCH}")
 endif()
 
-set(SIMGRID_VERSION_STRING
-  "SimGrid version ${release_version}${SIMGRID_VERSION_EXTRA}\\nCopyright (c) 2004-${SIMGRID_VERSION_DATE}. The Simgrid Team.")
+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.")
 
 set(libsimgrid_version "${release_version}")
 set(libsimgrid-java_version "${release_version}")
-set(GCC_NEED_VERSION "4.0")
-set(APPLE_NEED_GCC_VERSION "4.6")
 
-### SET THE LIBRARY EXTENSION AND GCC VERSION
+### SET THE LIBRARY EXTENSION 
 if(APPLE) #MAC
   set(LIB_EXE "dylib")
 else()
@@ -92,21 +135,12 @@ if(${CMAKE_C_COMPILER_ID} STREQUAL "GNU")
   string(REGEX MATCH "[0-9].[0-9].[0-9]" COMPILER_CXX_VERSION "${COMPILER_CXX_VERSION}")
 
   string(REGEX MATCH "^[0-9].[0-9]" COMPILER_C_VERSION_MAJOR_MINOR "${COMPILER_C_VERSION}")
-  string(REPLACE "${COMPILER_C_VERSION_MAJOR_MINOR}." "" COMPILER_C_VERSION_PATCH "${COMPILER_C_VERSION}")
-
-  if(${GCC_NEED_VERSION} GREATER  COMPILER_C_VERSION_MAJOR_MINOR)
-    message(FATAL_ERROR "Gcc must be to version ${GCC_NEED_VERSION} current version ${COMPILER_C_VERSION_MAJOR_MINOR}")
-  endif()
+  string(REPLACE "${COMPILER_C_VERSION_MAJOR_MINOR}." "" COMPILER_C_VERSION_PATCH "${COMPILER_C_VERSION}")  
 endif()
 
 exec_program("${CMAKE_LINKER} --version" OUTPUT_VARIABLE "LINKER_VERSION")
 string(REGEX MATCH "[0-9].[0-9]*" LINKER_VERSION "${LINKER_VERSION}")
 
-string(REGEX MATCH "cl.exe" VBC "${CMAKE_C_COMPILER}")
-if(VBC)
-  message(FATAL_ERROR "VB is not yet supported by Simgrid.")
-endif()
-
 ### Find programs and paths
 FIND_PROGRAM(GCOV_PATH gcov)
 include(FindPerl)
@@ -114,6 +148,11 @@ if(NOT PERL_EXECUTABLE)
   message(FATAL_ERROR "-- SimGrid cannot be compiled without Perl installed -- sorry. Bailling out.")
 endif()
 
+if (APPLE)
+  set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
+  set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
+endif()
+
 ### Set some variables for Cmake
 SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
 
@@ -130,7 +169,6 @@ set(INCLUDES
 if(WIN32)
   set(INCLUDES ${INCLUDES} ${CMAKE_HOME_DIRECTORY}/include/xbt ${CMAKE_HOME_DIRECTORY}/src/xbt) #for win32_ucontext.[ch]
 endif()
-set(CMAKE_SOURCE_DIR ${PROJECT_SOURCE_DIRECTORY})
 
 if(NOT CMAKE_CROSSCOMPILING AND EXISTS /usr/include/)
   set(INCLUDES ${INCLUDES} /usr/include/)
@@ -138,7 +176,11 @@ endif()
 
 ### Check 32bits or 64bits
 INCLUDE (CheckTypeSize)
+CHECK_TYPE_SIZE("int" SIZEOF_INT)
+CHECK_TYPE_SIZE("long" SIZEOF_LONG)
+CHECK_TYPE_SIZE("long long" SIZEOF_LONGLONG)
 CHECK_TYPE_SIZE("void*" SIZEOF_VOIDSTAR)
+message ("   Data model: (int)=${SIZEOF_INT} (long)=${SIZEOF_LONG} (long long)=${SIZEOF_LONGLONG} (void*)=${SIZEOF_VOIDSTAR}")
 IF(SIZEOF_VOIDSTAR EQUAL 4)
   SET(ARCH_32_BITS 1)
 ELSE()
@@ -167,28 +209,20 @@ if(WIN32)
     if(COMPILER_C_MINOR_VERSION)
       # set(__GNUC_MINOR__ ${COMPILER_C_MINOR_VERSION})
     endif()
-    set(MSVC 0)
-    set(BORLAND 0)
-  else()
-    message(FATAL_ERROR "Please use MinGW to compile SimGrid!")
-  endif()
-
-  if(ARCH_32_BITS)      ### Arch 32bits
-    set(_WIN32 1)
-  else()        ### Arch 64bits
-    set(_WIN64 1)
   endif()
 
   set(NSIS_WIN_VERSION $ENV{PROCESSOR_ARCHITEW6432})
   if(NSIS_WIN_VERSION MATCHES "")
     set(NSIS_WIN_VERSION $ENV{PROCESSOR_ARCHITECTURE})
   endif()
-  string(TOLOWER ${NSIS_WIN_VERSION} NSIS_WIN_VERSION)
+  if(${NSIS_WIN_VERSION})
+    string(TOLOWER ${NSIS_WIN_VERSION} NSIS_WIN_VERSION)
+  endif()
 
   set(_XBT_WIN32 1)
 
-  message(STATUS "C_COMPILER                    ${CMAKE_C_COMPILER} ${COMPILER_C_VERSION}")
-  message(STATUS "CXX_COMPILER                  ${CMAKE_CXX_COMPILER} ${COMPILER_CXX_VERSION}")
+  message(STATUS "C_COMPILER                    ${CMAKE_C_COMPILER} ${COMPILER_C_VERSION_MAJOR_MINOR}")
+  message(STATUS "CXX_COMPILER                  ${CMAKE_CXX_COMPILER} ${COMPILER_CXX_VERSION_MAJOR_MINOR}")
   message(STATUS "CMAKE_RC_COMPILER             ${CMAKE_RC_COMPILER}")
   message(STATUS "INCLUDE                       ${CMAKE_INCLUDE_WIN}")
   message(STATUS "LIB                           ${CMAKE_LIB_WIN}")
@@ -196,8 +230,6 @@ if(WIN32)
   message(STATUS "CMAKE_BUILD_TOOL              ${CMAKE_BUILD_TOOL}")
   message(STATUS "LINKER                        ${CMAKE_LINKER}")
   message(STATUS "CMAKE_GENERATOR               ${CMAKE_GENERATOR}")
-  message(STATUS "BORLAND                       ${BORLAND}")
-  message(STATUS "VISUALC                       ${MSVC}")
   message(STATUS "GNUC                          ${CMAKE_COMPILER_IS_GNUCC}")
 
 endif()
@@ -205,53 +237,67 @@ endif()
 include_directories(${INCLUDES})
 
 ### Setup Options
-include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Option.cmake)
+include(${CMAKE_HOME_DIRECTORY}/tools/cmake/Option.cmake)
 
 ### Make the *.h files with *.h.in files
-include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/CompleteInFiles.cmake)
+include(${CMAKE_HOME_DIRECTORY}/tools/cmake/CompleteInFiles.cmake)
 
 ### Define source packages for Libs
-include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/DefinePackages.cmake)
+include(${CMAKE_HOME_DIRECTORY}/tools/cmake/DefinePackages.cmake)
 
 ### Build some Maintainer files
-include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/MaintainerMode.cmake)
-include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/UnitTesting.cmake)
+include(${CMAKE_HOME_DIRECTORY}/tools/cmake/MaintainerMode.cmake)
+include(${CMAKE_HOME_DIRECTORY}/tools/cmake/UnitTesting.cmake)
 
-### Setup gcc flags
-include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Flags.cmake)
+### Setup gcc & clang flags
+if (NOT MSVC)
+  include(${CMAKE_HOME_DIRECTORY}/tools/cmake/GCCFlags.cmake)
+endif()
 
 ### Make Libs
 if(NOT WIN32)
-  include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/MakeLib.cmake)
+  include(${CMAKE_HOME_DIRECTORY}/tools/cmake/MakeLib.cmake)
 else()
-  include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/MakeLibWin.cmake)
+  include(${CMAKE_HOME_DIRECTORY}/tools/cmake/MakeLibWin.cmake)
 endif()
 
-### Make Exes
-include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/MakeExe.cmake)
+if(enable_java)
+  include(${CMAKE_HOME_DIRECTORY}/tools/cmake/Java.cmake)
+endif()
 
 ### Make tests
 if(enable_memcheck_xml)
   set(enable_memcheck true)
 endif()
 
-include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/AddTests.cmake)
-include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/CTestConfig.cmake)
+INCLUDE(CTest)
+ENABLE_TESTING()
+include(${CMAKE_HOME_DIRECTORY}/tools/cmake/Tests.cmake)
+include(${CMAKE_HOME_DIRECTORY}/tools/cmake/CTestConfig.cmake)
 
-### Setup the distrib
-include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Distrib.cmake)
+### Define subdirectories
+include(${CMAKE_HOME_DIRECTORY}/tools/cmake/MakeExe.cmake)
 
-### Pipol compilation
-include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/Pipol.cmake)
+### Setup the distrib
+include(${CMAKE_HOME_DIRECTORY}/tools/cmake/Distrib.cmake)
 
-### Build the doc
+### Build the doc (Windows downloads the doc instead of regenerating)
+#
 if(NOT WIN32)
-  include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/GenerateDoc.cmake)
+  include(${CMAKE_HOME_DIRECTORY}/tools/cmake/Documentation.cmake)
 else()
-  include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/GenerateDocWin.cmake)
+  find_program(WGET_PROGRAM  NAMES wget)
+  message(STATUS "wget: ${WGET_PROGRAM}")
+  if(WGET_PROGRAM)
+    ADD_CUSTOM_TARGET(simgrid_documentation
+      COMMENT "Downloading the SimGrid documentation..."
+      COMMAND ${WGET_PROGRAM} -r -np -nH -nd http://simgrid.gforge.inria.fr/simgrid/${release_version}/doc/
+      WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/doc/html
+    )
+  endif()
 endif()
 
 ### Print ARGS
-include(${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/PrintArgs.cmake)
+include(${CMAKE_HOME_DIRECTORY}/tools/cmake/PrintArgs.cmake)
 
 INCLUDE(Dart)