diff --git a/mlir/CMakeLists.txt b/mlir/CMakeLists.txt --- a/mlir/CMakeLists.txt +++ b/mlir/CMakeLists.txt @@ -1,10 +1,37 @@ # MLIR project. + +# Check if MLIR is built as a standalone project. +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + project(mlir) + cmake_minimum_required(VERSION 3.13.4) + + find_package(LLVM CONFIG REQUIRED) + set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LLVM_CMAKE_DIR}) + include(HandleLLVMOptions) + include(AddLLVM) + include(TableGen) + + include_directories(${LLVM_INCLUDE_DIRS}) + + set(LLVM_MAIN_SRC_DIR ${CMAKE_SOURCE_DIR}/../llvm CACHE PATH + "Path to LLVM source tree") + set(UNITTEST_DIR ${LLVM_MAIN_SRC_DIR}/utils/unittest) + if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h) + add_subdirectory(${UNITTEST_DIR} utils/unittest) + endif() + + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY + "${CMAKE_CURRENT_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}") + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin") +endif() + set(MLIR_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR} ) set(MLIR_MAIN_INCLUDE_DIR ${MLIR_MAIN_SRC_DIR}/include ) set(MLIR_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) set(MLIR_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) set(MLIR_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include) +set(MLIR_TOOLS_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules") @@ -106,7 +133,11 @@ add_subdirectory(lib/CAPI) if (MLIR_INCLUDE_TESTS) add_definitions(-DMLIR_INCLUDE_TESTS) - add_subdirectory(unittests) + if (TARGET gtest) + add_subdirectory(unittests) + else() + message(WARNING "gtest not found, unittests will not be available") + endif() add_subdirectory(test) endif() if (MLIR_INCLUDE_INTEGRATION_TESTS) diff --git a/mlir/lib/Conversion/GPUToNVVM/CMakeLists.txt b/mlir/lib/Conversion/GPUToNVVM/CMakeLists.txt --- a/mlir/lib/Conversion/GPUToNVVM/CMakeLists.txt +++ b/mlir/lib/Conversion/GPUToNVVM/CMakeLists.txt @@ -1,6 +1,7 @@ set(LLVM_TARGET_DEFINITIONS GPUToNVVM.td) mlir_tablegen(GPUToNVVM.cpp.inc -gen-rewriters) add_public_tablegen_target(MLIRGPUToNVVMIncGen) +include_directories(${CMAKE_CURRENT_BINARY_DIR}) add_mlir_conversion_library(MLIRGPUToNVVMTransforms LowerGpuOpsToNVVMOps.cpp diff --git a/mlir/lib/Conversion/GPUToROCDL/CMakeLists.txt b/mlir/lib/Conversion/GPUToROCDL/CMakeLists.txt --- a/mlir/lib/Conversion/GPUToROCDL/CMakeLists.txt +++ b/mlir/lib/Conversion/GPUToROCDL/CMakeLists.txt @@ -1,6 +1,7 @@ set(LLVM_TARGET_DEFINITIONS GPUToROCDL.td) mlir_tablegen(GPUToROCDL.cpp.inc -gen-rewriters) add_public_tablegen_target(MLIRGPUToROCDLIncGen) +include_directories(${CMAKE_CURRENT_BINARY_DIR}) add_mlir_conversion_library(MLIRGPUToROCDLTransforms LowerGpuOpsToROCDLOps.cpp diff --git a/mlir/lib/Conversion/GPUToSPIRV/CMakeLists.txt b/mlir/lib/Conversion/GPUToSPIRV/CMakeLists.txt --- a/mlir/lib/Conversion/GPUToSPIRV/CMakeLists.txt +++ b/mlir/lib/Conversion/GPUToSPIRV/CMakeLists.txt @@ -2,6 +2,7 @@ mlir_tablegen(GPUToSPIRV.cpp.inc -gen-rewriters) add_public_tablegen_target(MLIRGPUToSPIRVIncGen) +include_directories(${CMAKE_CURRENT_BINARY_DIR}) add_mlir_conversion_library(MLIRGPUToSPIRV GPUToSPIRV.cpp GPUToSPIRVPass.cpp diff --git a/mlir/lib/Conversion/ShapeToStandard/CMakeLists.txt b/mlir/lib/Conversion/ShapeToStandard/CMakeLists.txt --- a/mlir/lib/Conversion/ShapeToStandard/CMakeLists.txt +++ b/mlir/lib/Conversion/ShapeToStandard/CMakeLists.txt @@ -2,6 +2,7 @@ mlir_tablegen(ShapeToStandard.cpp.inc -gen-rewriters) add_public_tablegen_target(ShapeToStandardIncGen) +include_directories(${CMAKE_CURRENT_BINARY_DIR}) add_mlir_conversion_library(MLIRShapeToStandard ConvertShapeConstraints.cpp ShapeToStandard.cpp diff --git a/mlir/lib/Dialect/SPIRV/IR/CMakeLists.txt b/mlir/lib/Dialect/SPIRV/IR/CMakeLists.txt --- a/mlir/lib/Dialect/SPIRV/IR/CMakeLists.txt +++ b/mlir/lib/Dialect/SPIRV/IR/CMakeLists.txt @@ -2,6 +2,7 @@ mlir_tablegen(SPIRVCanonicalization.inc -gen-rewriters) add_public_tablegen_target(MLIRSPIRVCanonicalizationIncGen) +include_directories(${CMAKE_CURRENT_BINARY_DIR}) add_mlir_dialect_library(MLIRSPIRV SPIRVAttributes.cpp SPIRVCanonicalization.cpp diff --git a/mlir/lib/Dialect/Shape/IR/CMakeLists.txt b/mlir/lib/Dialect/Shape/IR/CMakeLists.txt --- a/mlir/lib/Dialect/Shape/IR/CMakeLists.txt +++ b/mlir/lib/Dialect/Shape/IR/CMakeLists.txt @@ -1,6 +1,7 @@ set(LLVM_TARGET_DEFINITIONS ShapeCanonicalization.td) mlir_tablegen(ShapeCanonicalization.inc -gen-rewriters) add_public_tablegen_target(MLIRShapeCanonicalizationIncGen) +include_directories(${CMAKE_CURRENT_BINARY_DIR}) add_mlir_dialect_library(MLIRShape Shape.cpp diff --git a/mlir/test/CMakeLists.txt b/mlir/test/CMakeLists.txt --- a/mlir/test/CMakeLists.txt +++ b/mlir/test/CMakeLists.txt @@ -42,7 +42,6 @@ set(MLIR_TEST_DEPENDS FileCheck count not - MLIRUnitTests mlir-capi-ir-test mlir-capi-pass-test mlir-cpu-runner @@ -58,6 +57,10 @@ mlir_async_runtime ) +if(TARGET gtest) + list(APPEND MLIR_TEST_DEPENDS MLIRUnitTests) +endif() + if(LLVM_BUILD_EXAMPLES) list(APPEND MLIR_TEST_DEPENDS toyc-ch1 diff --git a/mlir/test/lib/Dialect/Test/CMakeLists.txt b/mlir/test/lib/Dialect/Test/CMakeLists.txt --- a/mlir/test/lib/Dialect/Test/CMakeLists.txt +++ b/mlir/test/lib/Dialect/Test/CMakeLists.txt @@ -4,6 +4,7 @@ TestTraits.cpp ) +include_directories(${CMAKE_CURRENT_BINARY_DIR}) set(LLVM_TARGET_DEFINITIONS TestInterfaces.td) mlir_tablegen(TestTypeInterfaces.h.inc -gen-type-interface-decls) mlir_tablegen(TestTypeInterfaces.cpp.inc -gen-type-interface-defs) diff --git a/mlir/test/lit.cfg.py b/mlir/test/lit.cfg.py --- a/mlir/test/lit.cfg.py +++ b/mlir/test/lit.cfg.py @@ -61,6 +61,10 @@ 'mlir-capi-ir-test', 'mlir-capi-pass-test', 'mlir-edsc-builder-api-test', + 'mlir-cpu-runner', + 'mlir-linalg-ods-gen', + 'mlir-reduce', + 'mlir-sdbm-api-test', ] # The following tools are optional diff --git a/mlir/unittests/TableGen/CMakeLists.txt b/mlir/unittests/TableGen/CMakeLists.txt --- a/mlir/unittests/TableGen/CMakeLists.txt +++ b/mlir/unittests/TableGen/CMakeLists.txt @@ -21,6 +21,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../test/lib/Dialect/Test) include_directories(${CMAKE_CURRENT_BINARY_DIR}/../../test/lib/Dialect/Test) +include_directories(${CMAKE_CURRENT_BINARY_DIR}) target_link_libraries(MLIRTableGenTests PRIVATE MLIRTableGen MLIRIR