From b04b083b7ef19bb8a3a76c0c08ab38f747b44387 Mon Sep 17 00:00:00 2001 From: fruffy Date: Mon, 26 Aug 2024 19:20:50 +0200 Subject: [PATCH] Review comments. Signed-off-by: fruffy --- CMakeLists.txt | 10 +++++++--- backends/graphs/CMakeLists.txt | 5 +++++ backends/graphs/graphs.h | 11 ++--------- cmake/Boost.cmake | 20 +++----------------- 4 files changed, 17 insertions(+), 29 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e86dc6e3dde..579b0cc5014 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,7 +43,7 @@ OPTION (ENABLE_P4TC "Build the P4TC backend" ON) OPTION (ENABLE_P4FMT "Build the P4FMT backend" ON) OPTION (ENABLE_P4TEST "Build the P4Test backend (required for the full test suite)" ON) OPTION (ENABLE_TEST_TOOLS "Build the P4Tools development platform" OFF) -OPTION (ENABLE_P4C_GRAPHS "Build the p4c-graphs backend" ON) +OPTION (ENABLE_P4C_GRAPHS "Build the p4c-graphs backend" OFF) OPTION (ENABLE_PROTOBUF_STATIC "Link against Protobuf statically" ON) OPTION (ENABLE_GC "Compile with the Boehm-Demers-Weiser garbage collector." ON) OPTION (ENABLE_WERROR "Treat warnings as errors" OFF) @@ -55,6 +55,7 @@ likely depend on the standard libary anyway. If you have some non-static C++ dep STATIC_BUILD_WITH_DYNAMIC_STDLIB." OFF) OPTION (STATIC_BUILD_WITH_DYNAMIC_STDLIB "Build a (mostly) statically linked release binary. \ Glibc and C++ standard library is linked dynamically." OFF) +set(ADDITIONAL_P4C_BOOST_LIBRARIES "" CACHE STRING "Build and make these additional boost modules available. Modules are separated with semicolons.") if (STATIC_BUILD_WITH_DYNAMIC_GLIBC OR STATIC_BUILD_WITH_DYNAMIC_STDLIB) # We want to optimize the binary size for a static release binary by default. @@ -200,7 +201,10 @@ include(Abseil) p4c_obtain_abseil() include(Protobuf) p4c_obtain_protobuf() - +# The boost graph module is optional and only required by the graphs back end. +if(ENABLE_P4C_GRAPHS AND NOT P4C_USE_PREINSTALLED_BOOST) + list(APPEND ADDITIONAL_P4C_BOOST_LIBRARIES graph) +endif() include(Boost) p4c_obtain_boost() @@ -456,7 +460,7 @@ endif () if (ENABLE_EBPF) add_subdirectory (backends/ebpf) endif () -if (ENABLE_P4C_GRAPHS AND HAVE_LIBBOOST_GRAPH EQUAL 1) +if (ENABLE_P4C_GRAPHS) add_subdirectory (backends/graphs) endif () if (ENABLE_P4TC) diff --git a/backends/graphs/CMakeLists.txt b/backends/graphs/CMakeLists.txt index 20ee2d545d2..ebf9b15937a 100644 --- a/backends/graphs/CMakeLists.txt +++ b/backends/graphs/CMakeLists.txt @@ -12,6 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. +if (P4C_USE_PREINSTALLED_BOOST) + find_package(Boost REQUIRED COMPONENTS graph) + set(HAVE_LIBBOOST_GRAPH 1) +endif() + configure_file("${CMAKE_CURRENT_SOURCE_DIR}/version.h.cmake" "${CMAKE_CURRENT_BINARY_DIR}/version.h" @ONLY) diff --git a/backends/graphs/graphs.h b/backends/graphs/graphs.h index 8ac8d7e957f..6ff511bdb20 100644 --- a/backends/graphs/graphs.h +++ b/backends/graphs/graphs.h @@ -17,15 +17,6 @@ limitations under the License. #ifndef BACKENDS_GRAPHS_GRAPHS_H_ #define BACKENDS_GRAPHS_GRAPHS_H_ -#include "config.h" -#include "lib/cstring.h" - -/// Shouldn't happen as cmake will not try to build this backend if the boost -/// graph headers couldn't be found. -#ifndef HAVE_LIBBOOST_GRAPH -#error "This backend requires the boost graph headers, which could not be found" -#endif - #include #include #include // std::pair @@ -35,9 +26,11 @@ limitations under the License. #include #include +#include "config.h" #include "frontends/p4/parserCallGraph.h" #include "ir/ir.h" #include "ir/visitor.h" +#include "lib/cstring.h" namespace P4 { diff --git a/cmake/Boost.cmake b/cmake/Boost.cmake index beaae32cc03..81327eb1388 100644 --- a/cmake/Boost.cmake +++ b/cmake/Boost.cmake @@ -13,20 +13,11 @@ macro(p4c_obtain_boost) set(Boost_USE_STATIC_LIBS ON) set(Boost_USE_STATIC_RUNTIME OFF) endif() - - # The boost graph headers are optional and only required by the graphs back end. - find_package(Boost QUIET COMPONENTS graph) - if(Boost_FOUND) - set(HAVE_LIBBOOST_GRAPH 1) - else() - message(WARNING "Boost graph headers not found, will not build 'graphs' backend") - endif() find_package(Boost REQUIRED COMPONENTS iostreams) set(P4C_BOOST_LIBRARIES Boost::iostreams) else() - # This option can be used to include custom boost modules. - set(P4C_TARGET_BOOST_LIBRARIES "" CACHE STRING "Build and make these boost modules available. Modules are separated with semicolons.") set(P4C_BOOST_VERSION "1.86.0") + set(P4C_BOOST_HASH "2c5ec5edcdff47ff55e27ed9560b0a0b94b07bd07ed9928b476150e16b0efc57") message(STATUS "Fetching Boost version ${P4C_BOOST_VERSION} for P4C...") # Print out download state while setting up Boost. set(FETCHCONTENT_QUIET_PREV ${FETCHCONTENT_QUIET}) @@ -38,14 +29,9 @@ macro(p4c_obtain_boost) # Add boost modules. # format, multiprecision, and iostreams are needed by P4C core. set(BOOST_INCLUDE_LIBRARIES format multiprecision iostreams) + list(APPEND BOOST_INCLUDE_LIBRARIES ${ADDITIONAL_P4C_BOOST_LIBRARIES}) set(BOOST_ENABLE_CMAKE ON) - # The boost graph module is optional and only required by the graphs back end. - if(ENABLE_P4C_GRAPHS) - set(HAVE_LIBBOOST_GRAPH 1) - list(APPEND BOOST_INCLUDE_LIBRARIES graph) - endif() - list(APPEND BOOST_INCLUDE_LIBRARIES ${P4C_TARGET_BOOST_LIBRARIES}) # Always link local Boost statically. set(Boost_USE_STATIC_LIBS ON) @@ -56,7 +42,7 @@ macro(p4c_obtain_boost) FetchContent_Declare( Boost URL https://github.com/boostorg/boost/releases/download/boost-${P4C_BOOST_VERSION}/boost-${P4C_BOOST_VERSION}-cmake.tar.xz - URL_HASH SHA256=2c5ec5edcdff47ff55e27ed9560b0a0b94b07bd07ed9928b476150e16b0efc57 + URL_HASH SHA256=${P4C_BOOST_HASH} USES_TERMINAL_DOWNLOAD TRUE GIT_PROGRESS TRUE )