Skip to content

Commit

Permalink
Clean up P4Tools and control-plane linking.
Browse files Browse the repository at this point in the history
  • Loading branch information
fruffy committed Mar 12, 2024
1 parent 5730c63 commit 519271a
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 48 deletions.
15 changes: 0 additions & 15 deletions backends/p4tools/cmake/common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,9 @@ find_package(LibGc 7.2.0 REQUIRED)
# Helper for defining a p4tools executable target.
function(add_p4tools_executable target source)
add_executable(${target} ${source} ${ARGN})
target_include_directories(
${target}
PUBLIC "${CMAKE_SOURCE_DIR}"
PUBLIC "${CMAKE_BINARY_DIR}"
)
install(TARGETS ${target} RUNTIME DESTINATION ${P4C_RUNTIME_OUTPUT_DIRECTORY})
endfunction(add_p4tools_executable)

# Helper for defining a p4tools library target.
function(add_p4tools_library target)
add_library(${target} ${ARGN})
target_include_directories(
${target}
PUBLIC "${CMAKE_SOURCE_DIR}"
PUBLIC "${CMAKE_BINARY_DIR}"
)
endfunction(add_p4tools_library)

macro(p4tools_obtain_z3)
option(TOOLS_USE_PREINSTALLED_Z3 "Look for a preinstalled version of Z3 instead of installing a prebuilt binary using FetchContent." OFF)

Expand Down
11 changes: 4 additions & 7 deletions backends/p4tools/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,21 @@ set(
lib/variables.cpp
)

add_p4tools_library(p4tools-common ${P4C_TOOLS_COMMON_SOURCES})
add_library(p4tools-common OBJECT ${P4C_TOOLS_COMMON_SOURCES})

target_link_libraries(
p4tools-common
# We export Z3' with the common library.
PUBLIC ${P4TOOLS_Z3_LIB}
# For Abseil includes.
PRIVATE frontend
)

target_include_directories(
p4tools-common
# We export Z3's includes with the common library.
SYSTEM BEFORE PUBLIC ${P4TOOLS_Z3_INCLUDE_DIR}
)
target_include_directories(
p4tools-common
PUBLIC "${CMAKE_BINARY_DIR}/common"
PUBLIC "${P4C_SOURCE_DIR}"
PUBLIC "${P4C_BINARY_DIR}"
)

# Add control-plane-specific extensions.
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/control_plane)
2 changes: 1 addition & 1 deletion backends/p4tools/common/control_plane/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ set(
symbolic_variables.cpp
)

add_p4tools_library(p4tools-control-plane ${P4C_TOOLS_CONTROL_PLANE_SOURCES})
add_library(p4tools-control-plane STATIC ${P4C_TOOLS_CONTROL_PLANE_SOURCES})
target_link_libraries(p4tools-control-plane PRIVATE controlplane)
23 changes: 14 additions & 9 deletions backends/p4tools/modules/testgen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ set(
TESTGEN_LIBS
PRIVATE p4tools-common
PRIVATE p4tools-control-plane
# Make sure the testgen library and anything that links to it see both the Inja includes.
PUBLIC inja
)
set(TESTGEN_INCLUDES)
Expand Down Expand Up @@ -104,9 +105,14 @@ set(IR_DEF_FILES ${IR_DEF_FILES} PARENT_SCOPE)
configure_file(register.h.in register.h)

# The library.
add_p4tools_library(testgen ${TESTGEN_SOURCES})
# Make sure the testgen library and anything that links to it see both the Z3 and Inja includes.
target_link_libraries(testgen ${TESTGEN_LIBS})
add_library(testgen STATIC ${TESTGEN_SOURCES})
target_link_libraries(testgen
${TESTGEN_LIBS}
# For Abseil includes.
PRIVATE frontend
# For Protobuf includes.
PRIVATE controlplane
)
if (TESTGEN_INCLUDES)
target_include_directories(testgen ${TESTGEN_INCLUDES})
endif()
Expand All @@ -117,9 +123,8 @@ target_link_libraries(
p4testgen
PRIVATE testgen
${TESTGEN_LIBS}
${P4C_LIBRARIES}
${P4C_LIB_DEPS}
${CMAKE_THREAD_LIBS_INIT}
PRIVATE ${P4C_LIBRARIES}
PRIVATE ${P4C_LIB_DEPS}
)

add_custom_target(
Expand All @@ -141,9 +146,9 @@ if(ENABLE_GTESTS)
testgen-gtest
PRIVATE testgen
PRIVATE gtest
${TESTGEN_LIBS}
${P4C_LIBRARIES}
${P4C_LIB_DEPS}
PRIVATE ${TESTGEN_LIBS}
PRIVATE ${P4C_LIBRARIES}
PRIVATE ${P4C_LIB_DEPS}
)

if(ENABLE_TESTING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ execute_process(COMMAND ln -sfn ${P4C_SOURCE_DIR}/backends/bmv2/run-bmv2-test.py

set(
TESTGEN_LIBS ${TESTGEN_LIBS}
PRIVATE controlplane
PARENT_SCOPE
)

27 changes: 14 additions & 13 deletions control-plane/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,17 @@ set (CONTROLPLANE_HDRS
)

add_library(controlplane-gen OBJECT ${P4RUNTIME_GEN_SRCS})
# TODO(https://github.com/p4lang/p4c/issues/4477):
# We should not need this, but because of the way managed includes and
# libraries for Protobuf we need to explicitly add the include directories here.
target_include_directories(
controlplane-gen SYSTEM BEFORE PUBLIC ${Protobuf_INCLUDE_DIRS} SYSTEM BEFORE
PUBLIC ${ABSL_COMMON_INCLUDE_DIRS}

target_include_directories(controlplane-gen
# TODO(https://github.com/p4lang/p4c/issues/4477):
# We should not need this, but because of the way managed includes and
# libraries for Protobuf we need to explicitly add the include directories here.
SYSTEM BEFORE PUBLIC ${Protobuf_INCLUDE_DIRS}
# Needed for the correct import of google/status.pb.cc
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} PUBLIC ${CMAKE_CURRENT_BINARY_DIR}
)

target_link_libraries(controlplane-gen PUBLIC ${Protobuf_LIBRARY} PRIVATE absl::log)
# Needed for the correct import of google/status.pb.cc
target_include_directories(
controlplane-gen PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} PUBLIC ${CMAKE_CURRENT_BINARY_DIR}
)

# Silence various warnings as the root issue is out of our control, example
# https://github.com/protocolbuffers/protobuf/issues/7140
Expand All @@ -119,8 +117,11 @@ set_source_files_properties(

add_library(controlplane STATIC ${CONTROLPLANE_SRCS})
target_link_libraries(controlplane
PUBLIC ${CMAKE_THREAD_LIBS_INIT}
# Export Protobuf includes with controlplane-gen.
PUBLIC controlplane-gen
PRIVATE absl::strings)
# Required for the generated parser and the Abseil includes.
PRIVATE frontend
PRIVATE absl::strings
)

add_dependencies(controlplane mkP4configdir ir-generated controlplane-gen frontend-parser-gen)
add_dependencies(controlplane mkP4configdir)
1 change: 0 additions & 1 deletion frontends/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ if (FLEX_INCLUDE_DIRS)
include_directories (${FLEX_INCLUDE_DIRS})
endif ()
add_library (frontend STATIC ${FRONTEND_SOURCES})
add_dependencies (frontend frontend-parser-gen)
target_link_libraries (frontend
PRIVATE frontend-parser-gen
PRIVATE absl::strings
Expand Down
5 changes: 4 additions & 1 deletion midend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,8 @@ set (MIDEND_HDRS


add_library (midend STATIC ${MIDEND_SRCS})
target_link_libraries(midend frontend) # For TypeMap / RefMap
target_link_libraries(midend
# For TypeMap / RefMap
PRIVATE frontend
)
add_dependencies(midend genIR ir-generated)

0 comments on commit 519271a

Please sign in to comment.