diff --git a/CMakeLists.txt b/CMakeLists.txt index 9e22476c1..40ed6c081 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,20 +13,34 @@ if(POLICY CMP0077) cmake_policy(SET CMP0077 NEW) endif() +#------------------------------------------------------------------------------- +# Project setup and globals +#------------------------------------------------------------------------------- + project(npcomp LANGUAGES CXX C) +set(CMAKE_C_STANDARD 11) +set(CMAKE_CXX_STANDARD 14) + +#------------------------------------------------------------------------------- +# Options and settings +#------------------------------------------------------------------------------- + +option(NPCOMP_ENABLE_IREE "Enables the IREE backend (must configure location via IREE_DIR)." OFF) +set(NPCOMP_IREE_SRCDIR "" CACHE STRING "If building IREE, then setting this elects to build from a source directory (versus installed package)") + +#------------------------------------------------------------------------------- +# MLIR/LLVM Configuration +#------------------------------------------------------------------------------- find_package(MLIR REQUIRED CONFIG) - message(STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR}") message(STATUS "Using LLVMConfig.cmake in: ${LLVM_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_directories(${LLVM_INCLUDE_DIRS}) include_directories(${MLIR_INCLUDE_DIRS}) include_directories(${PROJECT_SOURCE_DIR}/include) @@ -34,8 +48,26 @@ include_directories(${PROJECT_BINARY_DIR}/include) link_directories(${LLVM_BUILD_LIBRARY_DIR}) add_definitions(${LLVM_DEFINITIONS}) -set(MLIR_NPCOMP_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) -set(MLIR_NPCOMP_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) +#------------------------------------------------------------------------------- +# IREE configuration +#------------------------------------------------------------------------------- + +if(${NPCOMP_ENABLE_IREE}) + add_compile_definitions(NPCOMP_ENABLE_IREE) + if(NPCOMP_IREE_SRCDIR) + message(STATUS "Depending on IREE source: ${NPCOMP_IREE_SRCDIR}") + set(IREE_BUILD_TESTS OFF CACHE BOOL "Override IREE setting") + set(IREE_BUILD_SAMPLES OFF CACHE BOOL "Override IREE setting") + set(IREE_MLIR_DEP_MODE "DISABLED" CACHE STRING "Override IREE setting") + add_subdirectory("${NPCOMP_IREE_SRCDIR}" "iree" EXCLUDE_FROM_ALL) + else() + find_package(IREE REQUIRED CONFIG) + endif() +endif() + +#------------------------------------------------------------------------------- +# Python Configuration +#------------------------------------------------------------------------------- # TODO(laurenzo): Rationalize with how this is done elsewhere find_package(PythonInterp REQUIRED) @@ -45,6 +77,13 @@ message(STATUS "Found ppython libraries: ${PYTHON_LIBRARIES}") find_package(pybind11 CONFIG REQUIRED) message(STATUS "Found pybind11 v${pybind11_VERSION}: ${pybind11_INCLUDE_DIRS}") +#------------------------------------------------------------------------------- +# Directory setup +#------------------------------------------------------------------------------- + +set(MLIR_NPCOMP_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) +set(MLIR_NPCOMP_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) + add_custom_target(check-npcomp) add_subdirectory(include/npcomp) diff --git a/tools/cmake_configure_iree.sh b/tools/cmake_configure_iree.sh new file mode 100755 index 000000000..9c1192ee3 --- /dev/null +++ b/tools/cmake_configure_iree.sh @@ -0,0 +1,15 @@ +#!/bin/bash +# Experimental configure script that includes IREE. +set -e + +td="$(realpath $(dirname $0))" +iree_dir="$(realpath "$td/../../iree")" +if ! [ -d "$iree_dir" ]; then + echo "Could not find IREE src dir: $iree_dir" + exit 1 +fi + +"$td/cmake_configure.sh" \ + -DNPCOMP_ENABLE_IREE=1 \ + "-DNPCOMP_IREE_SRCDIR=$iree_dir" \ + "$@"