Skip to content

Commit

Permalink
Review comments.
Browse files Browse the repository at this point in the history
Signed-off-by: fruffy <[email protected]>
  • Loading branch information
fruffy committed Aug 26, 2024
1 parent ce14238 commit 171e459
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 26 deletions.
10 changes: 7 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions backends/graphs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 0 additions & 6 deletions backends/graphs/graphs.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ limitations under the License.
#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 <map>
#include <optional>
#include <utility> // std::pair
Expand Down
20 changes: 3 additions & 17 deletions cmake/Boost.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand All @@ -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)
Expand All @@ -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
)
Expand Down

0 comments on commit 171e459

Please sign in to comment.