Skip to content

Commit

Permalink
Make the out-of-tree build approach optional
Browse files Browse the repository at this point in the history
Signed-off-by: Bili Dong <qobilidop@gmail.com>
  • Loading branch information
qobilidop committed Jan 28, 2025
1 parent 0410960 commit 8b4f3b5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
34 changes: 21 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
cmake_minimum_required(VERSION 3.20.0)
project(p4mlir LANGUAGES CXX C)
project(p4mlir LANGUAGES CXX)

# TODO: Consider unify the build process and remove this option.
option(BUILD_P4MLIR_OUT_OF_TREE "Whether to build P4MLIR out-of-tree" OFF)

set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)

set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

find_package(MLIR REQUIRED CONFIG)
if(BUILD_P4MLIR_OUT_OF_TREE)
find_package(MLIR REQUIRED CONFIG)

message(STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
message(STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")

set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/bin)
set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/lib)
set(MLIR_BINARY_DIR ${CMAKE_BINARY_DIR})
set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/bin)
set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/lib)
set(MLIR_BINARY_DIR ${CMAKE_BINARY_DIR})

list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}")
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}")
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")

include(TableGen)
include(AddLLVM)
include(AddMLIR)
include(HandleLLVMOptions)
include(TableGen)
include(AddLLVM)
include(AddMLIR)
include(HandleLLVMOptions)
else()
add_subdirectory(third_party)
set(LLVM_RUNTIME_OUTPUT_INTDIR ${P4MLIR_BINARY_DIR}/bin)
endif()

set(P4MLIR_SOURCE_DIR ${PROJECT_SOURCE_DIR})
set(P4MLIR_BINARY_DIR ${PROJECT_BINARY_DIR})
Expand Down
1 change: 1 addition & 0 deletions build_tools/build_p4c_with_p4mlir_ext.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ CMAKE_FLAGS+=" -DENABLE_TEST_TOOLS=OFF"
CMAKE_FLAGS+=" -DENABLE_P4C_GRAPHS=OFF"

# Configure P4MLIR CMake flags
CMAKE_FLAGS+=" -DBUILD_P4MLIR_OUT_OF_TREE=ON"
CMAKE_FLAGS+=" -DCMAKE_INSTALL_PREFIX=$LLVM_INSTALL_DIR"
CMAKE_FLAGS+=" -DMLIR_DIR=$LLVM_INSTALL_DIR/lib/cmake/mlir"
CMAKE_FLAGS+=" -DLLVM_EXTERNAL_LIT=$LLVM_BUILD_DIR/bin/llvm-lit"
Expand Down
4 changes: 0 additions & 4 deletions lib/Dialect/P4HIR/P4HIR_Attrs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
using namespace mlir;
using namespace P4::P4MLIR::P4HIR;

Type BoolType::parse(mlir::AsmParser &parser) { return get(parser.getContext()); }

void BoolType::print(mlir::AsmPrinter &printer) const {}

Attribute IntAttr::parse(AsmParser &parser, Type odsType) {
mlir::APInt APValue;

Expand Down

0 comments on commit 8b4f3b5

Please sign in to comment.