Index: mlir/CMakeLists.txt =================================================================== --- mlir/CMakeLists.txt +++ 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") @@ -97,7 +124,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) Index: mlir/lib/Conversion/GPUToNVVM/CMakeLists.txt =================================================================== --- mlir/lib/Conversion/GPUToNVVM/CMakeLists.txt +++ 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 Index: mlir/lib/Conversion/GPUToROCDL/CMakeLists.txt =================================================================== --- mlir/lib/Conversion/GPUToROCDL/CMakeLists.txt +++ 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 Index: mlir/lib/Conversion/GPUToSPIRV/CMakeLists.txt =================================================================== --- mlir/lib/Conversion/GPUToSPIRV/CMakeLists.txt +++ mlir/lib/Conversion/GPUToSPIRV/CMakeLists.txt @@ -1,6 +1,7 @@ set(LLVM_TARGET_DEFINITIONS GPUToSPIRV.td) mlir_tablegen(GPUToSPIRV.cpp.inc -gen-rewriters) add_public_tablegen_target(MLIRGPUToSPIRVIncGen) +include_directories(${CMAKE_CURRENT_BINARY_DIR}) add_mlir_conversion_library(MLIRGPUToSPIRVTransforms ConvertGPUToSPIRV.cpp Index: mlir/lib/Dialect/SPIRV/CMakeLists.txt =================================================================== --- mlir/lib/Dialect/SPIRV/CMakeLists.txt +++ mlir/lib/Dialect/SPIRV/CMakeLists.txt @@ -2,6 +2,7 @@ set(LLVM_TARGET_DEFINITIONS SPIRVCanonicalization.td) mlir_tablegen(SPIRVCanonicalization.inc -gen-rewriters) add_public_tablegen_target(MLIRSPIRVCanonicalizationIncGen) +include_directories(${CMAKE_CURRENT_BINARY_DIR}) add_mlir_dialect_library(MLIRSPIRV LayoutUtils.cpp Index: mlir/lib/Dialect/Shape/IR/CMakeLists.txt =================================================================== --- mlir/lib/Dialect/Shape/IR/CMakeLists.txt +++ 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 Index: mlir/test/CMakeLists.txt =================================================================== --- mlir/test/CMakeLists.txt +++ mlir/test/CMakeLists.txt @@ -40,7 +40,6 @@ set(MLIR_TEST_DEPENDS FileCheck count not - MLIRUnitTests mlir-capi-ir-test mlir-cpu-runner mlir-edsc-builder-api-test @@ -55,6 +54,9 @@ mlir_runner_utils mlir_c_runner_utils ) +if(TARGET gtest) + list(APPEND MLIR_TEST_DEPENDS MLIRUnitTests) +endif() if(LLVM_BUILD_EXAMPLES) list(APPEND MLIR_TEST_DEPENDS Index: mlir/test/lib/Dialect/Test/CMakeLists.txt =================================================================== --- mlir/test/lib/Dialect/Test/CMakeLists.txt +++ mlir/test/lib/Dialect/Test/CMakeLists.txt @@ -2,6 +2,7 @@ TestDialect.cpp TestPatterns.cpp ) +include_directories(${CMAKE_CURRENT_BINARY_DIR}) set(LLVM_TARGET_DEFINITIONS TestInterfaces.td) mlir_tablegen(TestTypeInterfaces.h.inc -gen-type-interface-decls) Index: mlir/test/lit.cfg.py =================================================================== --- mlir/test/lit.cfg.py +++ mlir/test/lit.cfg.py @@ -60,6 +60,10 @@ 'mlir-translate', 'mlir-capi-ir-test', 'mlir-edsc-builder-api-test', + 'mlir-cpu-runner', + 'mlir-linalg-ods-gen', + 'mlir-reduce', + 'mlir-sdbm-api-test', ] # The following tools are optional Index: mlir/unittests/TableGen/CMakeLists.txt =================================================================== --- mlir/unittests/TableGen/CMakeLists.txt +++ 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