Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Troubleshooting Homebrew binaries on macOS (Thanks Paul Adam)
[simgrid.git] / CMakeLists.txt
index 01a299e..47a5670 100644 (file)
@@ -1,7 +1,7 @@
 # Build the version number
 
 set(SIMGRID_VERSION_MAJOR "3")
-set(SIMGRID_VERSION_MINOR "32")
+set(SIMGRID_VERSION_MINOR "34")
 set(SIMGRID_VERSION_PATCH "1") # odd => git branch; even => stable release or released snapshot
 
 if(${SIMGRID_VERSION_PATCH} EQUAL "0")
@@ -21,12 +21,9 @@ set(SIMGRID_VERSION_STRING "SimGrid version ${release_version}")
 set(libsimgrid_version "${release_version}")
 
 # Basic checks on cmake
-cmake_minimum_required(VERSION 3.5)
-#for lto, to avoid warning (should be removed when switching to requiring cmake >= 3.9)
-if(NOT CMAKE_VERSION VERSION_LESS "3.9")
-  cmake_policy(SET CMP0069 NEW)
-endif()
-# once we move >= 3.13, we should use target_link_option in examples/sthread
+cmake_minimum_required(VERSION 3.12)
+# once we move CMake to >= 3.13, we should use target_link_option in examples/sthread
+# once we move CMake to >= 3.13.1, we could get rid of _Boost_STACKTRACE_BACKTRACE_HEADERS
 message(STATUS "Cmake version ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}")
 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_HOME_DIRECTORY}/tools/cmake/Modules)
 
@@ -38,12 +35,8 @@ include(GNUInstallDirs)
 #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
 #     Check for the compiler        #
 #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
-##
-## Check the C/C++ standard that we need
-##   See also tools/cmake/Flags.cmake that sets our paranoid warning flags
-INCLUDE(CheckCCompilerFlag)
-CHECK_C_COMPILER_FLAG(-fstack-cleaner HAVE_C_STACK_CLEANER)
 
+INCLUDE(CheckCCompilerFlag)
 ## Request full debugging flags
 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g3")
 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3")
@@ -80,7 +73,7 @@ if ((NOT DEFINED enable_smpi) OR enable_smpi)
   # configuration where it was saved as smpiff
   unset(CMAKE_Fortran_COMPILER)
 
-  SET(SMPI_FORTRAN 0)
+  SET(SMPI_FORTRAN OFF)
   if(enable_fortran)
     enable_language(Fortran OPTIONAL)
   endif()
@@ -109,7 +102,7 @@ if ((NOT DEFINED enable_smpi) OR enable_smpi)
     ## Request debugging flags for Fortran too
     set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -g")
 
-    set(SMPI_FORTRAN 1)
+    set(SMPI_FORTRAN ON)
   endif(CMAKE_Fortran_COMPILER)
 
 endif()
@@ -132,21 +125,11 @@ if(NOT PERL_FOUND)
 endif()
 
 # tesh.py needs python 3 (or the module python-subprocess32 on python2.8+)
-if(CMAKE_VERSION VERSION_LESS "3.12")
-  set(PythonInterp_FIND_VERSION 3)
-  set(PythonInterp_FIND_VERSION_COUNT 1)
-  set(PythonInterp_FIND_VERSION_MAJOR 3)
-  include(FindPythonInterp)
-  if(NOT PYTHONINTERP_FOUND)
-    message(FATAL_ERROR "Please install Python (version 3 or higher) to compile SimGrid.")
-  endif()
-else()
-  find_package(Python3 COMPONENTS Interpreter Development)
-  if(NOT Python3_Interpreter_FOUND)
-    message(FATAL_ERROR "Please install Python (version 3 or higher) to compile SimGrid.")
-  endif()
-  set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
+find_package(Python3 COMPONENTS Interpreter)
+if(NOT Python3_Interpreter_FOUND)
+  message(FATAL_ERROR "Please install Python (version 3 or higher) to compile SimGrid.")
 endif()
+set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
 
 SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
 
@@ -162,7 +145,6 @@ include_directories(
 set(INTERNAL_INCLUDES
   ${CMAKE_BINARY_DIR}
   ${CMAKE_HOME_DIRECTORY}
-  ${CMAKE_HOME_DIRECTORY}/src/include
   )
 
 if(enable_smpi)
@@ -209,21 +191,21 @@ include(CheckIncludeFiles)
 include(CheckLibraryExists)
 include(CheckSymbolExists)
 
-set(HAVE_GRAPHVIZ 0)
+set(HAVE_GRAPHVIZ OFF)
 if(minimal-bindings)
   message(STATUS "Don't even look for graphviz, as we build minimal binding libraries.")
 else()
   include(FindGraphviz)
 endif()
 
-set(SIMGRID_HAVE_NS3 0)
+set(SIMGRID_HAVE_NS3 OFF)
 if(enable_ns3)
   include(FindNS3)
   if (SIMGRID_HAVE_NS3)
     if (NOT NS3_VERSION EQUAL "3-dev" AND NS3_VERSION VERSION_LESS "3.28")
       message(FATAL_ERROR "SimGrid needs ns-3 in version 3.28 or higher. Please upgrade or disable that cmake option.")
     endif()
-    set(SIMGRID_HAVE_NS3 1)
+    set(SIMGRID_HAVE_NS3 ON)
     set(SIMGRID_DEP "${SIMGRID_DEP} ${NS3_LIBRARIES}")
   else()
     message(FATAL_ERROR "Cannot find ns-3. Please install it (apt-get install ns3 libns3-dev) or disable that cmake option")
@@ -231,28 +213,50 @@ if(enable_ns3)
 endif()
 
 ### Check for Eigen library
-set(SIMGRID_HAVE_EIGEN3 0)
-find_package (Eigen3 3.3 CONFIG
-              HINTS ${EIGEN3_HINT})
-if (Eigen3_FOUND)
-  set(SIMGRID_HAVE_EIGEN3 1)
-  message(STATUS "Found Eigen3: ${EIGEN3_INCLUDE_DIR}")
-  include_directories(${EIGEN3_INCLUDE_DIR})
-  if ("3.3.4" VERSION_EQUAL EIGEN3_VERSION_STRING AND CMAKE_COMPILER_IS_GNUCC)
-    message(STATUS "Avoid build error of Eigen3 v3.3.4 using -Wno-error=int-in-bool-context")
-    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=int-in-bool-context")
+if ((NOT DEFINED EIGEN3_HINT) OR (NOT EIGEN3_HINT STRLESS_EQUAL "OFF"))
+  set(SIMGRID_HAVE_EIGEN3 OFF)
+  find_package (Eigen3 3.3 CONFIG
+                HINTS ${EIGEN3_HINT})
+  if (Eigen3_FOUND)
+    set(SIMGRID_HAVE_EIGEN3 ON)
+    message(STATUS "Found Eigen3: ${EIGEN3_INCLUDE_DIR}")
+    include_directories(${EIGEN3_INCLUDE_DIR})
+    if ("3.3.4" VERSION_EQUAL EIGEN3_VERSION_STRING AND CMAKE_COMPILER_IS_GNUCC)
+      message(STATUS "Avoid build error of Eigen3 v3.3.4 using -Wno-error=int-in-bool-context")
+      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=int-in-bool-context")
+    endif()
+  else()
+    message(STATUS "Disabling model BMF because Eigen3 was not found. If it's installed, use EIGEN3_HINT to hint cmake about the location of Eigen3Config.cmake")
   endif()
+  mark_as_advanced(Eigen3_DIR)
 else()
-  message(STATUS "Disabling model BMF because Eigen3 was not found. If it's installed, use EIGEN3_HINT to hint cmake about the location of Eigen3Config.cmake")
+  message(STATUS "Disabling Eigen3 as requested by the user (EIGEN3_HINT is set to 'OFF')")
+endif()
+
+# Check for our JSON dependency
+set(SIMGRID_HAVE_JSON 0)
+find_package(nlohmann_json 3.7
+             HINTS ${nlohmann_json_HINT})
+if (nlohmann_json_FOUND)
+  set(SIMGRID_HAVE_JSON 1)
+  if (NOT NLOHMANN_JSON_INCLUDE_DIR)
+    get_target_property(NLOHMANN_JSON_INCLUDE_DIR nlohmann_json::nlohmann_json INTERFACE_INCLUDE_DIRECTORIES)
+    list(REMOVE_DUPLICATES NLOHMANN_JSON_INCLUDE_DIR)
+  else()
+    include_directories(${NLOHMANN_JSON_INCLUDE_DIR})
+  endif()
+  message(STATUS "Found nlohmann_json: ${NLOHMANN_JSON_INCLUDE_DIR}")
 endif()
+mark_as_advanced(nlohmann_json_DIR)
 
-set(HAVE_PAPI 0)
+set(HAVE_PAPI OFF)
 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()
+mark_as_advanced(PAPI_PREFIX)
 
 # But we do need the core of Boost
 # cmake before 3.13.1 does not know about stacktrace components. Fix it.
@@ -290,10 +294,10 @@ set(_Boost_STACKTRACE_ADDR2LINE_HEADERS "boost/stacktrace.hpp")
 
       if(Boost_CONTEXT_FOUND)
         message (STATUS "  context: found. Activating Boost contexts.")
-        set(HAVE_BOOST_CONTEXTS 1)
+        set(HAVE_BOOST_CONTEXTS ON)
       else()
         message (STATUS "  context: MISSING. Install libboost-context-dev for this optional feature.")
-        set(HAVE_BOOST_CONTEXTS 0)
+        set(HAVE_BOOST_CONTEXTS OFF)
       endif()
     endif()
   else()
@@ -309,6 +313,10 @@ set(_Boost_STACKTRACE_ADDR2LINE_HEADERS "boost/stacktrace.hpp")
       endif()
     endif()
   endif()
+mark_as_advanced(Boost_CONTEXT_LIBRARY_RELEASE)
+mark_as_advanced(Boost_INCLUDE_DIR)
+mark_as_advanced(Boost_STACKTRACE_ADDR2LINE_LIB)
+mark_as_advanced(Boost_STACKTRACE_BACKTRACE_LIB)
 
 # Checks for header libraries functions.
 CHECK_LIBRARY_EXISTS(rt      clock_gettime           "" HAVE_POSIX_GETTIME)
@@ -333,7 +341,6 @@ if(NOT HAVE_SYSCONF)
   message(FATAL_ERROR "Cannot build without sysconf.")
 endif()
 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)
@@ -346,61 +353,33 @@ else()
   set(SG_HAVE_SENDFILE 0)
 endif()
 
-if(enable_model-checking AND NOT "${CMAKE_SYSTEM}" MATCHES "Linux|FreeBSD")
-  message(FATAL_ERROR "Support for model-checking has not been enabled on ${CMAKE_SYSTEM}. Please use a Linux docker to use the model checker.")
-endif()
-
-if(enable_model-checking AND minimal-bindings)
-  message(FATAL_ERROR "Compile-time option 'minimal-bindings' cannot be enabled with 'model-checking'")
-endif()
-
-if(HAVE_MMAP)
-  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_mallocators)
   SET(SIMGRID_HAVE_MALLOCATOR 1)
 else()
   SET(SIMGRID_HAVE_MALLOCATOR 0)
 endif()
 
+SET(SIMGRID_HAVE_MC OFF)
+
 if(enable_model-checking)
-  include(FindLibunwind)
-  if(HAVE_LIBUNWIND)
-    SET(SIMGRID_DEP "${SIMGRID_DEP} ${LIBUNWIND_LIBRARIES}")
+  find_package(Libevent)
+  if(Libevent_FOUND)
+    message(STATUS "Found libevent. The stateless model-checking can be enabled.")
+    include_directories(${LIBEVENT_INCLUDE_DIR})
+    set(SIMGRID_DEP "${SIMGRID_DEP} ${LIBEVENT_LIBRARIES}")
+    SET(SIMGRID_HAVE_MC ON)
   else()
-    message(FATAL_ERROR "Please install libunwind-dev libdw-dev libelf-dev libevent-dev if you want to compile the SimGrid model checker.")
+    message(STATUS "libevent not found. Please install libevent-dev to enable the SimGrid model checker.")
   endif()
-  find_package(Libdw REQUIRED)
-  find_package(Libelf REQUIRED)
-  find_package(Libevent REQUIRED)
-  include_directories(${LIBDW_INCLUDE_DIR} ${LIBELF_INCLUDE_DIR} ${LIBEVENT_INCLUDE_DIR})
-  set(SIMGRID_DEP "${SIMGRID_DEP} ${LIBEVENT_LIBRARIES} ${LIBELF_LIBRARIES} ${LIBDW_LIBRARIES}")
-  set(SIMGRID_HAVE_MC 1)
-  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -gdwarf-4")
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -gdwarf-4")
-else()
-  SET(SIMGRID_HAVE_MC 0)
-  set(HAVE_MMALLOC 0)
-endif()
-mark_as_advanced(PATH_LIBDW_H)
-mark_as_advanced(PATH_LIBDW_LIB)
-
-if (enable_model-checking AND enable_ns3)
-  message(WARNING "Activating both model-checking and ns-3 bindings is considered experimental.")
+  mark_as_advanced(LIBEVENT_LIBRARY)
+  mark_as_advanced(LIBEVENT_THREADS_LIBRARY)
 endif()
 
 if(enable_smpi)
-  SET(HAVE_SMPI 1)
-  SET(HAVE_PRIVATIZATION 1)
+  SET(HAVE_SMPI ON)
+  SET(HAVE_PRIVATIZATION ON)
 else()
-  SET(HAVE_SMPI 0)
+  SET(HAVE_SMPI OFF)
 endif()
 
 #--------------------------------------------------------------------------------------------------
@@ -463,7 +442,7 @@ else()
   endif()
 endif()
 # If the test ran well, remove the test binary
-file(REMOVE test_stackgrowth)
+file(REMOVE ${CMAKE_BINARY_DIR}/test_stackgrowth)
 #--------------------------------------------------------------------------------------------------
 
 ###############
@@ -743,6 +722,10 @@ SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES
 add_custom_target(tests    COMMENT "Recompiling the tests")
 add_custom_target(tests-mc COMMENT "Recompiling the MC tests and tools.")
 add_dependencies(tests tests-mc)
+add_custom_target(tests-ns3 COMMENT "Recompiling the ns3 tests and tools.")
+add_dependencies(tests tests-ns3)
+add_custom_target(examples COMMENT "Recompiling all examples")
+add_dependencies(examples tests)
 
 ### Build some Maintainer files
 include(${CMAKE_HOME_DIRECTORY}/tools/cmake/MaintainerMode.cmake)
@@ -770,22 +753,22 @@ if((NOT DEFINED enable_python) OR enable_python)
       set(pybind11_FOUND OFF)
     endif()
   endif()
-
-  if(NOT PYTHONLIBS_FOUND AND NOT Python3_Development_FOUND)
-    message(STATUS "Python libs not found. Turn pybind11 off.")
-
-    set(pybind11_FOUND OFF)
-  endif()
 endif()
 
-option(enable_python "Whether the Python bindings are activated." ${pybind11_FOUND}) # ON by default if dependencies are met
-
-if("${CMAKE_SYSTEM}" MATCHES "FreeBSD" AND enable_model-checking AND enable_python)
-  message(WARNING "FreeBSD + Model-Checking + Python = too much for now. Disabling the Python bindings.")
-  set(enable_python FALSE)
+find_package(Python3 COMPONENTS Development)
+if(NOT Python3_Development_FOUND OR NOT pybind11_FOUND)
+  message(STATUS "SimGrid Python bindings cannot be built on this system.")
+  set(default_enable_python OFF)
+else()
+  set(default_enable_python ON)
 endif()
 
+option(enable_python "Whether the Python bindings are activated." ${default_enable_python}) # ON by default if dependencies are met
+
 if(enable_python)
+  if(NOT Python3_Development_FOUND)
+    message(FATAL_ERROR "Please install the development components of Python (python3-dev on Debian) to build the Python bindings (or disable that option).")
+  endif()
   if(pybind11_FOUND)
     message(STATUS "Found pybind11.")
     if(NOT enable_lto)
@@ -909,30 +892,37 @@ if(pybind11_FOUND)
 else()
   message("        Compile Python bindings .....: OFF (disabled, or pybind11 not found)")
 endif()
-if(Eigen3_FOUND)
+if(SIMGRID_HAVE_EIGEN3)
   message("        Eigen3 library ..............: ${EIGEN3_VERSION_STRING} in ${EIGEN3_INCLUDE_DIR}")
 else()
-  message("        Eigen3 library ..............: not found (EIGEN3_HINT='${EIGEN3_HINT}').")
+  message("        Eigen3 library ..............: not found (EIGEN3_HINT='${EIGEN3_HINT}')")
+endif()
+if(SIMGRID_HAVE_JSON)
+  message("        JSON library ................: ${nlohmann_json_VERSION} in ${NLOHMANN_JSON_INCLUDE_DIR}")
+else()
+  message("        JSON library ................: not found (nlohmann_json_HINT='${nlohmann_json_HINT}')")
 endif()
 message("        Compile Smpi ................: ${HAVE_SMPI}")
 message("          Smpi fortran ..............: ${SMPI_FORTRAN}")
-message("          MPICH3 testsuite ..........: ${enable_smpi_MPICH3_testsuite}")
-message("          MBI testsuite .............: ${enable_smpi_MBI_testsuite}")
+message("          MPICH3 testsuite ..........: ${enable_testsuite_smpi_MPICH3}")
+message("          MBI testsuite .............: ${enable_testsuite_smpi_MBI}")
 message("          Privatization .............: ${HAVE_PRIVATIZATION}")
-message("          PAPI support...............: ${HAVE_PAPI}")
+message("          PAPI support ..............: ${HAVE_PAPI}")
 message("        Compile Boost.Context support: ${HAVE_BOOST_CONTEXTS}")
 message("")
-message("        Maintainer mode .............: ${enable_maintainer_mode}")
-message("        Documentation................: ${enable_documentation}")
 message("        Model checking ..............: ${SIMGRID_HAVE_MC}")
+message("          MBI testsuite .............: ${enable_testsuite_smpi_MBI}")
+message("          McMini testsuite ..........: ${enable_testsuite_McMini}")
+message("")
+message("        Maintainer mode .............: ${enable_maintainer_mode}")
+message("        Documentation ...............: ${enable_documentation}")
 message("        Graphviz mode ...............: ${HAVE_GRAPHVIZ}")
 message("        Mallocators .................: ${enable_mallocators}")
 message("")
-message("        Simgrid dependencies ........: ${SIMGRID_DEP}")
+message("        SimGrid dependencies ........: ${SIMGRID_DEP}")
 message("")
 
 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")
 
-INCLUDE(Dart)