Fix CMakeFiles to include information from LLVM.

Also: fix 'check-circt' and 'install' rules.  Linkage was broken for
most of the tools.
This commit is contained in:
Stephen Neuendorffer 2020-06-17 13:27:14 -07:00
parent 3e0100ae89
commit 7d03c27a82
6 changed files with 88 additions and 51 deletions

View File

@ -1,20 +1,44 @@
cmake_minimum_required(VERSION 3.10)
if(POLICY CMP0068)
cmake_policy(SET CMP0068 NEW)
set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)
endif()
if(POLICY CMP0075)
cmake_policy(SET CMP0075 NEW)
endif()
if(POLICY CMP0077)
cmake_policy(SET CMP0077 NEW)
endif()
project(circt LANGUAGES CXX C)
find_package(MLIR REQUIRED CONFIG)
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})
# Define the default arguments to use with 'lit', and an option for the user to
# override.
set(LIT_ARGS_DEFAULT "-sv")
if (MSVC_IDE OR XCODE)
set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
endif()
set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
# CIRCT project.
set(CIRCT_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include ) # --src-root
set(CIRCT_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include ) # --includedir
set(CIRCT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(CIRCT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
## Should get this from MLIR build files somehow?
set(MLIR_TABLEGEN_EXE mlir-tblgen)
set(MLIR_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../llvm-project/mlir)
set(MLIR_MAIN_SRC_DIR ${MLIR_SOURCE_DIR})
set(MLIR_INCLUDE_DIR ${MLIR_SOURCE_DIR}/include )
set(MLIR_BINARY_INCLUDE_DIR ${LLVM_TOOLS_BINARY_DIR}/../tools/mlir/include )
set(CIRCT_BINARY_DIR ${CMAKE_BINARY_DIR}/bin)
set(CIRCT_TOOLS_DIR ${CMAKE_BINARY_DIR}/bin)
# Installing the headers and docs needs to depend on generating any public
# tablegen'd targets.
@ -22,10 +46,20 @@ add_custom_target(circt-headers)
set_target_properties(circt-headers PROPERTIES FOLDER "Misc")
add_custom_target(circt-doc)
include_directories( ${MLIR_INCLUDE_DIR})
include_directories( ${MLIR_BINARY_INCLUDE_DIR})
include_directories( ${CIRCT_INCLUDE_DIR})
include_directories( ${CIRCT_MAIN_SRC_DIR})
list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}")
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
include(TableGen)
include(AddLLVM)
include(AddMLIR)
include(HandleLLVMOptions)
include_directories(${LLVM_INCLUDE_DIRS})
include_directories(${MLIR_INCLUDE_DIRS})
#include_directories( ${MLIR_BINARY_INCLUDE_DIR})
include_directories(${PROJECT_SOURCE_DIR}/include)
include_directories(${PROJECT_BINARY_DIR}/include)
add_subdirectory(include/circt)
add_subdirectory(lib)

View File

@ -4,10 +4,6 @@
set(CIRCT_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm)
set(circt_cmake_builddir "${CMAKE_BINARY_DIR}/${CIRCT_INSTALL_PACKAGE_DIR}")
# Keep this in sync with llvm/cmake/CMakeLists.txt!
set(LLVM_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm)
set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}")
get_property(CIRCT_EXPORTS GLOBAL PROPERTY CIRCT_EXPORTS)
export(TARGETS ${CIRCT_EXPORTS} FILE ${circt_cmake_builddir}/CIRCTTargets.cmake)
@ -53,10 +49,12 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
COMPONENT circt-cmake-exports)
endif()
install(FILES #${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/CIRCTConfig.cmake
${CMAKE_CURRENT_SOURCE_DIR}/AddCIRCT.cmake
DESTINATION ${CIRCT_INSTALL_PACKAGE_DIR}
COMPONENT circt-cmake-exports)
# FIXME: Figure out what from this directory actually needs be
# installed to allow out of tree users.
# install(FILES #${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/CIRCTConfig.cmake
# ${CMAKE_CURRENT_SOURCE_DIR}/AddCIRCT.cmake
# DESTINATION ${CIRCT_INSTALL_PACKAGE_DIR}
# COMPONENT circt-cmake-exports)
if(NOT LLVM_ENABLE_IDE)
# Add a dummy target so this can be used with LLVM_DISTRIBUTION_COMPONENTS

View File

@ -53,6 +53,7 @@ llvm_config.with_environment('PATH', config.llvm_tools_dir, append_path=True)
tool_dirs = [config.circt_tools_dir, config.mlir_tools_dir, config.llvm_tools_dir]
tools = [
'firtool',
'circt-opt',
'circt-translate',
]

View File

@ -1,4 +1,12 @@
set(LIBS
set(LLVM_LINK_COMPONENTS
Support
)
add_llvm_tool(circt-opt
circt-opt.cpp
)
llvm_update_compile_flags(circt-opt)
target_link_libraries(circt-opt PRIVATE
MLIRFIRRTL
MLIRRTL
@ -8,13 +16,5 @@ set(LIBS
MLIROptLib
MLIRStandardOps
MLIRTransforms
LLVMSupport
)
add_llvm_tool(circt-opt
circt-opt.cpp
)
llvm_update_compile_flags(circt-opt)
target_link_libraries(circt-opt PRIVATE ${LIBS} ${targets_to_link})
)

View File

@ -1,4 +1,13 @@
set(LIBS
set(LLVM_LINK_COMPONENTS
Support
)
add_llvm_tool(circt-translate
circt-translate.cpp
)
llvm_update_compile_flags(circt-translate)
target_link_libraries(circt-translate
PRIVATE
MLIRTranslation
MLIRIR
MLIRStandardOps
@ -6,9 +15,4 @@ set(LIBS
CIRCTEmitVerilog
CIRCTFIRParser
)
add_llvm_tool(circt-translate
circt-translate.cpp
)
llvm_update_compile_flags(circt-translate)
target_link_libraries(circt-translate PRIVATE ${LIBS} LLVMSupport)
)

View File

@ -1,4 +1,12 @@
set(LIBS
set(LLVM_LINK_COMPONENTS
Support
)
add_llvm_tool(firtool
firtool.cpp
)
llvm_update_compile_flags(firtool)
target_link_libraries(firtool PRIVATE
CIRCTEmitVerilog
CIRCTFIRParser
@ -9,13 +17,5 @@ set(LIBS
MLIRStandardOps
MLIRTransforms
MLIRTranslation
LLVMSupport
)
add_llvm_tool(firtool
firtool.cpp
)
llvm_update_compile_flags(firtool)
target_link_libraries(firtool PRIVATE ${LIBS} ${targets_to_link})
)