diff mlir/CMakeLists.txt @ 173:0572611fdcc8 llvm10 llvm12

reorgnization done
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 11:55:54 +0900
parents 1d019706d866
children 2e18cbf3894f
line wrap: on
line diff
--- a/mlir/CMakeLists.txt	Mon May 25 11:50:15 2020 +0900
+++ b/mlir/CMakeLists.txt	Mon May 25 11:55:54 2020 +0900
@@ -1,40 +1,24 @@
 # MLIR project.
-set(MLIR_MAIN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include ) # --src-root
-set(MLIR_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include ) # --includedir
-set(MLIR_TABLEGEN_EXE mlir-tblgen)
+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_SOURCE_DIR  ${CMAKE_CURRENT_SOURCE_DIR})
+set(MLIR_BINARY_DIR  ${CMAKE_CURRENT_BINARY_DIR})
+set(MLIR_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include)
 
 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
 
-function(add_mlir_dialect dialect dialect_doc_filename)
-  set(LLVM_TARGET_DEFINITIONS ${dialect}.td)
-  mlir_tablegen(${dialect}.h.inc -gen-op-decls)
-  mlir_tablegen(${dialect}.cpp.inc -gen-op-defs)
-  add_public_tablegen_target(MLIR${dialect}IncGen)
-  add_dependencies(mlir-headers MLIR${dialect}IncGen)
-
-  # Generate Dialect Documentation
-  set(LLVM_TARGET_DEFINITIONS ${dialect_doc_filename}.td)
-  tablegen(MLIR ${dialect_doc_filename}.md -gen-op-doc "-I${MLIR_MAIN_SRC_DIR}" "-I${MLIR_INCLUDE_DIR}")
-  set(GEN_DOC_FILE ${MLIR_BINARY_DIR}/docs/Dialects/${dialect_doc_filename}.md)
-  add_custom_command(
-          OUTPUT ${GEN_DOC_FILE}
-          COMMAND ${CMAKE_COMMAND} -E copy
-                  ${CMAKE_CURRENT_BINARY_DIR}/${dialect_doc_filename}.md
-                  ${GEN_DOC_FILE}
-          DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${dialect_doc_filename}.md)
-  add_custom_target(${dialect_doc_filename}DocGen DEPENDS ${GEN_DOC_FILE})
-  add_dependencies(mlir-doc ${dialect_doc_filename}DocGen)
-endfunction()
-
 include(AddMLIR)
 
 # Installing the headers and docs needs to depend on generating any public
 # tablegen'd targets.
+# mlir-generic-headers are dialect-independent.
+add_custom_target(mlir-generic-headers)
+set_target_properties(mlir-generic-headers PROPERTIES FOLDER "Misc")
+# mlir-headers may be dialect-dependent.
 add_custom_target(mlir-headers)
 set_target_properties(mlir-headers PROPERTIES FOLDER "Misc")
+add_dependencies(mlir-headers mlir-generic-headers)
 add_custom_target(mlir-doc)
 
 # Build the CUDA conversions and run according tests if the NVPTX backend
@@ -44,17 +28,34 @@
 else()
   set(MLIR_CUDA_CONVERSIONS_ENABLED 0)
 endif()
+# TODO: we should use a config.h file like LLVM does
+add_definitions(-DMLIR_CUDA_CONVERSIONS_ENABLED=${MLIR_CUDA_CONVERSIONS_ENABLED})
 
 set(MLIR_CUDA_RUNNER_ENABLED 0 CACHE BOOL "Enable building the mlir CUDA runner")
+set(MLIR_VULKAN_RUNNER_ENABLED 0 CACHE BOOL "Enable building the mlir Vulkan runner")
+
+option(MLIR_INCLUDE_TESTS
+       "Generate build targets for the MLIR unit tests."
+       ${LLVM_INCLUDE_TESTS})
 
 include_directories( "include")
 include_directories( ${MLIR_INCLUDE_DIR})
 
+# Adding tools/mlir-tblgen here as calling add_tablegen sets some variables like
+# MLIR_TABLEGEN_EXE in PARENT_SCOPE which gets lost if that folder is included
+# from another directory like tools
+add_subdirectory(tools/mlir-tblgen)
+
 add_subdirectory(include/mlir)
 add_subdirectory(lib)
+if (MLIR_INCLUDE_TESTS)
+  add_definitions(-DMLIR_INCLUDE_TESTS)
+  add_subdirectory(unittests)
+  add_subdirectory(test)
+endif()
+# Tools needs to come late to ensure that MLIR_ALL_LIBS is populated.
+# Generally things after this point may depend on MLIR_ALL_LIBS or libMLIR.so.
 add_subdirectory(tools)
-add_subdirectory(unittests)
-add_subdirectory(test)
 
 if( LLVM_INCLUDE_EXAMPLES )
   add_subdirectory(examples)