From f8337d554d80cfa2588512696696fd4c878dd7a3 Mon Sep 17 00:00:00 2001 From: Robert Scott Date: Sun, 3 Nov 2024 13:13:40 +0000 Subject: [PATCH 1/2] cmake: add option to disable vendored nlohmann_json library this also renames the vendored copy's inner directory to nlohmann to match the directory name most "installed" copies of this lib are installed under, meaning we can #include via the same path for system and vendored versions --- CMakeLists.txt | 1 + cmake/detect_dependencies.cmake | 20 ++++++++++++++----- .../{nlohmann_json => nlohmann}/json.hpp | 0 .../module_identification/utils/statistics.h | 2 +- .../src/netlist_preprocessing.cpp | 2 +- plugins/z3_utils/src/netlist_comparison.cpp | 2 +- 6 files changed, 19 insertions(+), 8 deletions(-) rename deps/nlohmann_json/{nlohmann_json => nlohmann}/json.hpp (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index d9632df926c..2549e3a0fb9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,6 +66,7 @@ option(USE_VENDORED_PYBIND11 "Use vendored 'pybind11' Python library" ON) option(USE_VENDORED_SPDLOG "Use vendored 'spdlog' library" ON) option(USE_VENDORED_QUAZIP "Use vendored 'quazip' library" ON) option(USE_VENDORED_IGRAPH "Use vendored 'igraph' library" ON) +option(USE_VENDORED_NLOHMANN_JSON "Use vendored 'nlohmann_json' library" ON) option(BUILD_ALL_PLUGINS "Build all available plugins" OFF) option(BUILD_TESTS "Enable test builds" OFF) option(BUILD_COVERAGE "Enable code coverage build" OFF) diff --git a/cmake/detect_dependencies.cmake b/cmake/detect_dependencies.cmake index 9e4535a4419..2d38fa934d4 100644 --- a/cmake/detect_dependencies.cmake +++ b/cmake/detect_dependencies.cmake @@ -193,11 +193,21 @@ set_target_properties(subprocess::subprocess PROPERTIES # ############################### # #### nlohmann_json # ############################### -message(STATUS "using nlohmann_json from deps") -add_library(nlohmann_json::nlohmann_json INTERFACE IMPORTED) -set_target_properties(nlohmann_json::nlohmann_json PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_SOURCE_DIR}/deps/nlohmann_json" -) +if(USE_VENDORED_NLOHMANN_JSON) + message(STATUS "using nlohmann_json from deps") + add_library(nlohmann_json::nlohmann_json INTERFACE IMPORTED) + set_target_properties(nlohmann_json::nlohmann_json PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_SOURCE_DIR}/deps/nlohmann_json" + ) +else() + find_package(nlohmann_json REQUIRED) + if(nlohmann_json_FOUND) + get_target_property(NLOHMANN_JSON_HEADERS_DIR nlohmann_json::nlohmann_json INTERFACE_INCLUDE_DIRECTORIES) + message(STATUS "Using system's nlohmann_json headers at ${NLOHMANN_JSON_HEADERS_DIR}") + else() + message(FATAL_ERROR "nlohmann_json was not found and USE_VENDORED_NLOHMANN_JSON is OFF") + endif() +endif() # ############################### diff --git a/deps/nlohmann_json/nlohmann_json/json.hpp b/deps/nlohmann_json/nlohmann/json.hpp similarity index 100% rename from deps/nlohmann_json/nlohmann_json/json.hpp rename to deps/nlohmann_json/nlohmann/json.hpp diff --git a/plugins/module_identification/include/module_identification/utils/statistics.h b/plugins/module_identification/include/module_identification/utils/statistics.h index 5b52fd8cea6..fe3130f9a69 100644 --- a/plugins/module_identification/include/module_identification/utils/statistics.h +++ b/plugins/module_identification/include/module_identification/utils/statistics.h @@ -4,7 +4,7 @@ #include "module_identification/candidates/base_candidate.h" #include "module_identification/candidates/functional_candidate.h" #include "module_identification/types/candidate_types.h" -#include "nlohmann_json/json.hpp" +#include "nlohmann/json.hpp" #include #include diff --git a/plugins/netlist_preprocessing/src/netlist_preprocessing.cpp b/plugins/netlist_preprocessing/src/netlist_preprocessing.cpp index f78892c196e..1ad79725dc7 100644 --- a/plugins/netlist_preprocessing/src/netlist_preprocessing.cpp +++ b/plugins/netlist_preprocessing/src/netlist_preprocessing.cpp @@ -11,7 +11,7 @@ #include "hal_core/netlist/net.h" #include "hal_core/netlist/netlist.h" #include "hal_core/utilities/token_stream.h" -#include "nlohmann_json/json.hpp" +#include "nlohmann/json.hpp" #include "rapidjson/document.h" #include "resynthesis/resynthesis.h" #include "z3_utils/netlist_comparison.h" diff --git a/plugins/z3_utils/src/netlist_comparison.cpp b/plugins/z3_utils/src/netlist_comparison.cpp index 215839d4955..1a0aa47059d 100644 --- a/plugins/z3_utils/src/netlist_comparison.cpp +++ b/plugins/z3_utils/src/netlist_comparison.cpp @@ -8,7 +8,7 @@ #include "hal_core/netlist/net.h" #include "hal_core/netlist/netlist.h" #include "hal_core/utilities/log.h" -#include "nlohmann_json/json.hpp" +#include "nlohmann/json.hpp" #include "z3_utils/z3_utils.h" namespace hal From fe1fe74719ab4fef873a22e2b28cce0c57d570e0 Mon Sep 17 00:00:00 2001 From: Robert Scott Date: Sun, 3 Nov 2024 16:39:38 +0000 Subject: [PATCH 2/2] fix building with system igraph --- plugins/graph_algorithm/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/graph_algorithm/CMakeLists.txt b/plugins/graph_algorithm/CMakeLists.txt index 5db5f4a6c1a..c5ddc362014 100644 --- a/plugins/graph_algorithm/CMakeLists.txt +++ b/plugins/graph_algorithm/CMakeLists.txt @@ -14,6 +14,8 @@ if(PL_GRAPH_ALGORITHM OR BUILD_ALL_PLUGINS) LINK_LIBRARIES PUBLIC ${igraph_LIBRARIES} ) -add_dependencies(graph_algorithm igraph_0_10) +if(USE_VENDORED_IGRAPH) + add_dependencies(graph_algorithm igraph_0_10) +endif() endif()