diff --git a/mlir/CMakeLists.txt b/mlir/CMakeLists.txt --- a/mlir/CMakeLists.txt +++ b/mlir/CMakeLists.txt @@ -121,6 +121,9 @@ set(MLIR_BUILD_MLIR_C_DYLIB 0 CACHE BOOL "Builds libMLIR-C shared library.") +option(MLIR_BUILD_TOOLS + "Build the MLIR tools. If OFF, just generate build targets." ON) + #------------------------------------------------------------------------------- # Python Bindings Configuration # Requires: diff --git a/mlir/cmake/modules/AddMLIR.cmake b/mlir/cmake/modules/AddMLIR.cmake --- a/mlir/cmake/modules/AddMLIR.cmake +++ b/mlir/cmake/modules/AddMLIR.cmake @@ -459,3 +459,31 @@ endforeach() endif() endfunction(mlir_check_all_link_libraries) + +macro(add_mlir_executable name) + add_llvm_executable(${name} ${ARGN}) + set_target_properties(${name} PROPERTIES FOLDER "MLIR executables") +endmacro(add_mlir_executable) + +macro(add_mlir_tool name) + if (NOT MLIR_BUILD_TOOLS) + set(EXCLUDE_FROM_ALL ON) + endif() + + add_mlir_executable(${name} ${ARGN}) + + if (MLIR_BUILD_TOOLS) + get_target_export_arg(${name} MLIR export_to_mlirtargets) + install(TARGETS ${name} + ${export_to_mlirtargets} + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + COMPONENT ${name}) + + if(NOT LLVM_ENABLE_IDE) + add_llvm_install_targets(install-${name} + DEPENDS ${name} + COMPONENT ${name}) + endif() + set_property(GLOBAL APPEND PROPERTY MLIR_EXPORTS ${name}) + endif() +endmacro() diff --git a/mlir/examples/standalone/standalone-opt/CMakeLists.txt b/mlir/examples/standalone/standalone-opt/CMakeLists.txt --- a/mlir/examples/standalone/standalone-opt/CMakeLists.txt +++ b/mlir/examples/standalone/standalone-opt/CMakeLists.txt @@ -7,7 +7,7 @@ MLIROptLib MLIRStandalone ) -add_llvm_executable(standalone-opt standalone-opt.cpp) +add_mlir_executable(standalone-opt standalone-opt.cpp) llvm_update_compile_flags(standalone-opt) target_link_libraries(standalone-opt PRIVATE ${LIBS}) diff --git a/mlir/examples/standalone/standalone-translate/CMakeLists.txt b/mlir/examples/standalone/standalone-translate/CMakeLists.txt --- a/mlir/examples/standalone/standalone-translate/CMakeLists.txt +++ b/mlir/examples/standalone/standalone-translate/CMakeLists.txt @@ -5,7 +5,7 @@ get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) get_property(translation_libs GLOBAL PROPERTY MLIR_TRANSLATION_LIBS) -add_llvm_executable(standalone-translate +add_mlir_executable(standalone-translate standalone-translate.cpp ) llvm_update_compile_flags(standalone-translate) diff --git a/mlir/examples/standalone/test/CAPI/CMakeLists.txt b/mlir/examples/standalone/test/CAPI/CMakeLists.txt --- a/mlir/examples/standalone/test/CAPI/CMakeLists.txt +++ b/mlir/examples/standalone/test/CAPI/CMakeLists.txt @@ -10,7 +10,7 @@ StandaloneCAPI ) -add_llvm_executable(standalone-capi-test +add_mlir_executable(standalone-capi-test standalone-capi-test.c ) llvm_update_compile_flags(standalone-capi-test) diff --git a/mlir/test/CAPI/CMakeLists.txt b/mlir/test/CAPI/CMakeLists.txt --- a/mlir/test/CAPI/CMakeLists.txt +++ b/mlir/test/CAPI/CMakeLists.txt @@ -6,7 +6,7 @@ ${ARGN}) set(LLVM_LINK_COMPONENTS ) - add_llvm_executable(${name} + add_mlir_executable(${name} PARTIAL_SOURCES_INTENDED ${ARG_UNPARSED_ARGUMENTS}) llvm_update_compile_flags(${name}) diff --git a/mlir/tools/mlir-cpu-runner/CMakeLists.txt b/mlir/tools/mlir-cpu-runner/CMakeLists.txt --- a/mlir/tools/mlir-cpu-runner/CMakeLists.txt +++ b/mlir/tools/mlir-cpu-runner/CMakeLists.txt @@ -5,7 +5,7 @@ native ) -add_llvm_tool(mlir-cpu-runner +add_mlir_tool(mlir-cpu-runner mlir-cpu-runner.cpp ) llvm_update_compile_flags(mlir-cpu-runner) diff --git a/mlir/tools/mlir-linalg-ods-gen/CMakeLists.txt b/mlir/tools/mlir-linalg-ods-gen/CMakeLists.txt --- a/mlir/tools/mlir-linalg-ods-gen/CMakeLists.txt +++ b/mlir/tools/mlir-linalg-ods-gen/CMakeLists.txt @@ -4,7 +4,7 @@ ) # New mlir-linalg-ods-yaml-gen. -add_llvm_tool(mlir-linalg-ods-yaml-gen +add_mlir_tool(mlir-linalg-ods-yaml-gen mlir-linalg-ods-yaml-gen.cpp ) llvm_update_compile_flags(mlir-linalg-ods-yaml-gen) diff --git a/mlir/tools/mlir-lsp-server/CMakeLists.txt b/mlir/tools/mlir-lsp-server/CMakeLists.txt --- a/mlir/tools/mlir-lsp-server/CMakeLists.txt +++ b/mlir/tools/mlir-lsp-server/CMakeLists.txt @@ -41,7 +41,7 @@ MLIRIR ) -add_llvm_tool(mlir-lsp-server +add_mlir_tool(mlir-lsp-server mlir-lsp-server.cpp DEPENDS diff --git a/mlir/tools/mlir-opt/CMakeLists.txt b/mlir/tools/mlir-opt/CMakeLists.txt --- a/mlir/tools/mlir-opt/CMakeLists.txt +++ b/mlir/tools/mlir-opt/CMakeLists.txt @@ -63,7 +63,7 @@ ${LIBS} ) -add_llvm_tool(mlir-opt +add_mlir_tool(mlir-opt mlir-opt.cpp DEPENDS diff --git a/mlir/tools/mlir-pdll-lsp-server/CMakeLists.txt b/mlir/tools/mlir-pdll-lsp-server/CMakeLists.txt --- a/mlir/tools/mlir-pdll-lsp-server/CMakeLists.txt +++ b/mlir/tools/mlir-pdll-lsp-server/CMakeLists.txt @@ -2,7 +2,7 @@ MLIRPdllLspServerLib ) -add_llvm_tool(mlir-pdll-lsp-server +add_mlir_tool(mlir-pdll-lsp-server mlir-pdll-lsp-server.cpp DEPENDS diff --git a/mlir/tools/mlir-pdll/CMakeLists.txt b/mlir/tools/mlir-pdll/CMakeLists.txt --- a/mlir/tools/mlir-pdll/CMakeLists.txt +++ b/mlir/tools/mlir-pdll/CMakeLists.txt @@ -4,7 +4,7 @@ MLIRPDLLParser ) -add_llvm_tool(mlir-pdll +add_mlir_tool(mlir-pdll mlir-pdll.cpp DEPENDS diff --git a/mlir/tools/mlir-reduce/CMakeLists.txt b/mlir/tools/mlir-reduce/CMakeLists.txt --- a/mlir/tools/mlir-reduce/CMakeLists.txt +++ b/mlir/tools/mlir-reduce/CMakeLists.txt @@ -17,7 +17,7 @@ MLIRReduceLib ) -add_llvm_tool(mlir-reduce +add_mlir_tool(mlir-reduce mlir-reduce.cpp DEPENDS diff --git a/mlir/tools/mlir-spirv-cpu-runner/CMakeLists.txt b/mlir/tools/mlir-spirv-cpu-runner/CMakeLists.txt --- a/mlir/tools/mlir-spirv-cpu-runner/CMakeLists.txt +++ b/mlir/tools/mlir-spirv-cpu-runner/CMakeLists.txt @@ -5,7 +5,7 @@ if (MLIR_ENABLE_SPIRV_CPU_RUNNER) message(STATUS "Building SPIR-V CPU runner") - add_llvm_tool(mlir-spirv-cpu-runner + add_mlir_tool(mlir-spirv-cpu-runner mlir-spirv-cpu-runner.cpp ) diff --git a/mlir/tools/mlir-translate/CMakeLists.txt b/mlir/tools/mlir-translate/CMakeLists.txt --- a/mlir/tools/mlir-translate/CMakeLists.txt +++ b/mlir/tools/mlir-translate/CMakeLists.txt @@ -5,7 +5,7 @@ get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) get_property(translation_libs GLOBAL PROPERTY MLIR_TRANSLATION_LIBS) -add_llvm_tool(mlir-translate +add_mlir_tool(mlir-translate mlir-translate.cpp ) llvm_update_compile_flags(mlir-translate) diff --git a/mlir/tools/mlir-vulkan-runner/CMakeLists.txt b/mlir/tools/mlir-vulkan-runner/CMakeLists.txt --- a/mlir/tools/mlir-vulkan-runner/CMakeLists.txt +++ b/mlir/tools/mlir-vulkan-runner/CMakeLists.txt @@ -88,7 +88,7 @@ LIST(APPEND targets_to_link "LLVM${t}") ENDFOREACH(t) - add_llvm_tool(mlir-vulkan-runner + add_mlir_tool(mlir-vulkan-runner mlir-vulkan-runner.cpp DEPENDS