Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Test for JSON before using it
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Mon, 13 Mar 2023 23:43:27 +0000 (00:43 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Mon, 13 Mar 2023 23:46:42 +0000 (00:46 +0100)
CMakeLists.txt
docs/source/Installing_SimGrid.rst
include/simgrid/config.h.in
src/dag/loaders.cpp
tools/cmake/MakeLib.cmake
tools/cmake/Modules/nlohmann_jsonConfig.cmake [new file with mode: 0644]

index f702831..ac8fa34 100644 (file)
@@ -231,6 +231,16 @@ 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()
 
+# Check for our JSON dependency
+set(SIMGRID_HAVE_JSON 0)
+find_package(nlohmann_json 3.11.2
+             HINTS ${nlohmann_json_HINT})
+if (nlohmann_json_FOUND)
+  set(SIMGRID_HAVE_JSON 1)
+  message(STATUS "Found nlohmann_json: ${NLOHMANN_JSON_INCLUDE_DIR}")
+  include_directories(${NLOHMANN_JSON_INCLUDE_DIR})
+endif()
+
 set(HAVE_PAPI 0)
 if(enable_smpi_papi)
   include(FindPAPI)
index adfb90e..5cb50fb 100644 (file)
@@ -107,6 +107,9 @@ Eigen3 (optional)
   - On CentOS / Fedora: ``dnf install eigen3-devel``
   - On macOS with homebrew: ``brew install eigen``
   - Use EIGEN3_HINT to specify where it's installed if cmake doesn't find it automatically.
+JSON (optional, for the DAG wfcommons loader)
+  - On Debian / Ubuntu: ``apt install nlohmann-json3-dev``
+  - Use nlohmann_json_HINT to specify where it's installed if cmake doesn't find it automatically.
 
 For platform-specific details, please see below.
 
index 2995c8d..6ef3fd7 100644 (file)
@@ -18,4 +18,6 @@
 #cmakedefine NS3_MINOR_VERSION @NS3_MINOR_VERSION@
 /* Was the Eigen3 support compiled in? */
 #cmakedefine01 SIMGRID_HAVE_EIGEN3
+/* Was the JSON support compiled in? */
+#cmakedefine01 SIMGRID_HAVE_JSON
 #endif /* SIMGRID_PUBLIC_CONFIG_H */
index e78e716..676b98b 100644 (file)
@@ -1,5 +1,4 @@
-/* Copyright (c) 2009-2023. The SimGrid Team.
- * All rights reserved.                                                     */
+/* Copyright (c) 2009-2023. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -21,7 +20,9 @@
 #include "dax_dtd.h"
 #include "dax_dtd.c"
 
+#if SIMGRID_HAVE_JSON
 #include <nlohmann/json.hpp>
+#endif
 
 #if HAVE_GRAPHVIZ
 #include <graphviz/cgraph.h>
@@ -89,6 +90,7 @@ static ExecPtr current_job;
  */
 std::vector<ActivityPtr> create_DAG_from_json(const std::string& filename)
 {
+#if SIMGRID_HAVE_JSON
   std::ifstream f(filename);
   auto data = nlohmann::json::parse(f);
   std::vector<ActivityPtr> dag = {};
@@ -149,8 +151,11 @@ std::vector<ActivityPtr> create_DAG_from_json(const std::string& filename)
       activity->start();
   }
   return dag;
+#else
+  xbt_die("JSON support was not compiled in, probably because nlohmann/json was not found. Please install "
+          "nlohmann-json3-dev and recompile SimGrid to use this feature.");
+#endif
 }
-
 /** @brief loads a DAX file describing a DAG
  *
  * See https://confluence.pegasus.isi.edu/display/pegasus/WorkflowGenerator for more details.
index 4afca47..11cf6b9 100644 (file)
@@ -95,6 +95,10 @@ if(HAVE_GRAPHVIZ)
   endif()
 endif()
 
+if(SIMGRID_HAVE_JSON)
+  target_link_libraries(simgrid  nlohmann_json::nlohmann_json)
+endif()
+
 if(NOT ${DL_LIBRARY} STREQUAL "")
   SET(SIMGRID_DEP "${SIMGRID_DEP} ${DL_LIBRARY}")
 endif()
diff --git a/tools/cmake/Modules/nlohmann_jsonConfig.cmake b/tools/cmake/Modules/nlohmann_jsonConfig.cmake
new file mode 100644 (file)
index 0000000..27b0a86
--- /dev/null
@@ -0,0 +1,15 @@
+include(FindPackageHandleStandardArgs)
+set(${CMAKE_FIND_PACKAGE_NAME}_CONFIG ${CMAKE_CURRENT_LIST_FILE})
+find_package_handle_standard_args(nlohmann_json CONFIG_MODE)
+
+if(NOT TARGET nlohmann_json::nlohmann_json)
+    include("${CMAKE_CURRENT_LIST_DIR}/nlohmann_jsonTargets.cmake")
+    if((NOT TARGET nlohmann_json) AND
+       (NOT nlohmann_json_FIND_VERSION OR
+        nlohmann_json_FIND_VERSION VERSION_LESS 3.2.0))
+        add_library(nlohmann_json INTERFACE IMPORTED)
+        set_target_properties(nlohmann_json PROPERTIES
+            INTERFACE_LINK_LIBRARIES nlohmann_json::nlohmann_json
+        )
+    endif()
+endif()