Revert "[RFC] Factor out repetitive cmake patterns for llvm-style projects"

This reverts commit e9b87f43bd.

There are issues with macros generating macros without an obvious simple fix
so I'm going to revert this and try something different.
This commit is contained in:
Stephen Neuendorffer 2020-10-04 15:17:34 -07:00
parent 37010d4ddf
commit b0dce6b37f
17 changed files with 28 additions and 221 deletions

View File

@ -1,68 +0,0 @@
# LLVM-style projects generally have the same directory structure. This file
# provides some bolierplate cmake support for projects that supports this
# directory structure. Note that generally speaking, projects should prefer
# to use their own rules for these rather than relying on the core llvm build
# targets.
# Generally name should be lower case.
function(add_llvm_project_options name)
string(TOUPPER "${name}" uppername)
# Define options to control the inclusion and default build behavior for
# components which may not strictly be necessary (tools, examples, and tests).
#
# This is primarily to support building smaller or faster project files.
option(${uppername}_INCLUDE_TOOLS
"Generate build targets for the ${uppername} tools."
${LLVM_INCLUDE_TOOLS})
option(${uppername}_BUILD_TOOLS
"Build the ${uppername} tools. If OFF, just generate build targets."
${LLVM_BUILD_TOOLS})
option(${uppername}_INCLUDE_UTILS
"Generate build targets for the ${uppername} utils."
${LLVM_INCLUDE_UTILS})
option(${uppername}_BUILD_UTILS
"Build ${uppername} utility binaries. If OFF, just generate build targets."
${LLVM_BUILD_UTILS})
option(${uppername}_INSTALL_UTILS
"Include utility binaries in the 'install' target."
${LLVM_INSTALL_UTILS})
# i.e. Don't install headers, for instance.
option(${uppername}_INSTALL_TOOLCHAIN_ONLY
"Only include toolchain files in the 'install' target."
${LLVM_INSTALL_TOOLCHAIN_ONLY})
option(${uppername}_BUILD_EXAMPLES
"Build the ${uppername} example programs. If OFF, just generate build targets."
${LLVM_BUILD_EXAMPLES})
option(${uppername}_INCLUDE_EXAMPLES
"Generate build targets for the ${uppername} examples"
${LLVM_INCLUDE_EXAMPLES})
if(${uppername}_BUILD_EXAMPLES)
add_definitions(-DBUILD_EXAMPLES)
endif(${uppername}_BUILD_EXAMPLES)
option(${uppername}_BUILD_TESTS
"Build ${uppername} unit tests. If OFF, just generate build targets."
${LLVM_BUILD_TESTS})
option(${uppername}_INCLUDE_TESTS
"Generate build targets for the ${uppername} unit tests."
${LLVM_INCLUDE_TESTS})
if (${uppername}_INCLUDE_TESTS)
add_definitions(-D${uppername}_INCLUDE_TESTS)
endif()
option(${uppername}_INCLUDE_INTEGRATION_TESTS
"Generate build targets for the ${uppername} integration tests."
${LLVM_INCLUDE_INTEGRATION_TESTS})
if (${uppername}_INCLUDE_INTEGRATION_TESTS)
add_definitions(-D${uppername}_INCLUDE_INTEGRATION_TESTS)
endif()
option(${uppername}_INCLUDE_DOCS
"Generate build targets for the ${uppername} docs."
${LLVM_INCLUDE_DOCS})
endfunction(add_llvm_project_options)

View File

@ -1,109 +0,0 @@
# For project foo, this function generates:
# add_foo_tool(name) (An executable installed by default)
# add_foo_utility(name) (An executable *not* installed by default)
# add_foo_example(name) (An executable which is built, but never installed)
# add_foo_example_library(name) (A library to go along with an example)
# It also assumes the following configuration environment variables
# (see LLVMProjectOptions.cmake)
# FOO_TOOLS_INSTALL_DIR
# FOO_BUILD_TOOLS
# FOO_BUILD_UTILS
# FOO_INSTALL_UTILS
# FOO_BUILD_EXAMPLES
# FOO_HAS_EXPORTS
# FOO_INSTALL_TOOLCHAIN_ONLY
function(add_llvm_project_targets projectname)
string(TOUPPER "${name}" upperprojectname)
macro(add_${projectname}_tool name)
if( NOT ${upperprojectname}_BUILD_TOOLS )
set(EXCLUDE_FROM_ALL ON)
endif()
add_llvm_executable(${name} ${ARGN})
if ( ${name} IN_LIST LLVM_TOOLCHAIN_TOOLS OR NOT ${upperprojectname}_INSTALL_TOOLCHAIN_ONLY)
if( ${upperprojectname}_BUILD_TOOLS )
set(export_to_${projectname}exports)
if(${name} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
NOT LLVM_DISTRIBUTION_COMPONENTS)
set(export_to_${projectname}exports EXPORT ${upperprojectname}Exports)
set_property(GLOBAL PROPERTY ${upperprojectname}_HAS_EXPORTS True)
endif()
install(TARGETS ${name}
${export_to_${projectname}exports}
RUNTIME DESTINATION ${${upperprojectname}_TOOLS_INSTALL_DIR}
COMPONENT ${name})
if (NOT LLVM_ENABLE_IDE)
add_llvm_install_targets(install-${name}
DEPENDS ${name}
COMPONENT ${name})
endif()
endif()
endif()
if( ${upperprojectname}_BUILD_TOOLS )
set_property(GLOBAL APPEND PROPERTY ${upperprojectname}_EXPORTS ${name})
endif()
set_target_properties(${name} PROPERTIES FOLDER "Tools")
endmacro(add_${projectname}_tool name)
macro(add_${projectname}_example name)
if( NOT ${upperprojectname}_BUILD_EXAMPLES )
set(EXCLUDE_FROM_ALL ON)
endif()
add_llvm_executable(${name} ${ARGN})
if( ${upperprojectname}_BUILD_EXAMPLES )
install(TARGETS ${name} RUNTIME DESTINATION examples)
endif()
set_target_properties(${name} PROPERTIES FOLDER "Examples")
endmacro(add_${projectname}_example name)
macro(add_${projectname}_example_library name)
if( NOT ${upperprojectname}_BUILD_EXAMPLES )
set(EXCLUDE_FROM_ALL ON)
add_llvm_library(${name} BUILDTREE_ONLY ${ARGN})
else()
add_llvm_library(${name} ${ARGN})
endif()
set_target_properties(${name} PROPERTIES FOLDER "Examples")
endmacro(add_${projectname}_example_library name)
# This is a macro that is used to create targets for executables that are needed
# for development, but that are not intended to be installed by default.
macro(add_${projectname}_utility name)
if ( NOT ${upperprojectname}_BUILD_UTILS )
set(EXCLUDE_FROM_ALL ON)
endif()
add_llvm_executable(${name} DISABLE_LLVM_LINK_LLVM_DYLIB ${ARGN})
set_target_properties(${name} PROPERTIES FOLDER "Utils")
if (NOT ${upperprojectname}_INSTALL_TOOLCHAIN_ONLY)
if (${upperprojectname}_INSTALL_UTILS AND ${upperprojectname}_BUILD_UTILS)
set(export_to_${projectname}exports)
if (${name} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
NOT LLVM_DISTRIBUTION_COMPONENTS)
set(export_to_${projectname}exports EXPORT ${upperprojectname}Exports)
set_property(GLOBAL PROPERTY ${upperprojectname}_HAS_EXPORTS True)
endif()
install(TARGETS ${name}
${export_to_${projectname}exports}
RUNTIME DESTINATION ${LLVM_UTILS_INSTALL_DIR}
COMPONENT ${name})
if (NOT LLVM_ENABLE_IDE)
add_llvm_install_targets(install-${name}
DEPENDS ${name}
COMPONENT ${name})
endif()
set_property(GLOBAL APPEND PROPERTY ${upperprojectname}_EXPORTS ${name})
elseif(${upperprojectname}_BUILD_UTILS)
set_property(GLOBAL APPEND PROPERTY ${upperprojectname}_EXPORTS_BUILDTREE_ONLY ${name})
endif()
endif()
endmacro(add_${projectname}_utility name)
endfunction(add_llvm_project_targets)

View File

@ -21,10 +21,6 @@ set_target_properties(mlir-headers PROPERTIES FOLDER "Misc")
add_dependencies(mlir-headers mlir-generic-headers)
add_custom_target(mlir-doc)
# Get a bunch of LLVM-style default options.
include(LLVMProjectOptions)
add_llvm_project_options(mlir)
# Build the CUDA conversions and run according tests if the NVPTX backend
# is available
if ("NVPTX" IN_LIST LLVM_TARGETS_TO_BUILD)
@ -48,6 +44,13 @@ set(MLIR_CUDA_RUNNER_ENABLED 0 CACHE BOOL "Enable building the mlir CUDA runner"
set(MLIR_ROCM_RUNNER_ENABLED 0 CACHE BOOL "Enable building the mlir ROCm 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})
option(MLIR_INCLUDE_INTEGRATION_TESTS
"Generate build targets for the MLIR integration tests.")
#-------------------------------------------------------------------------------
# Python Bindings Configuration
# Requires:
@ -80,46 +83,42 @@ if(MLIR_BINDINGS_PYTHON_ENABLED)
"extension = '${PYTHON_MODULE_EXTENSION}")
endif()
# Get a bunch of default targets
include(LLVMProjectTargets)
add_llvm_project_targets(mlir)
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
if (MLIR_INCLUDE_TOOLS)
add_subdirectory(tools/mlir-tblgen)
endif()
add_subdirectory(tools/mlir-tblgen)
add_subdirectory(include/mlir)
add_subdirectory(lib)
# C API needs all dialects for registration, but should be built before tests.
add_subdirectory(lib/CAPI)
if (MLIR_INCLUDE_TESTS)
add_definitions(-DMLIR_INCLUDE_TESTS)
add_subdirectory(unittests)
add_subdirectory(test)
endif()
if (MLIR_INCLUDE_INTEGRATION_TESTS)
add_definitions(-DMLIR_INCLUDE_INTEGRATION_TESTS)
add_subdirectory(integration_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.
if (MLIR_INCLUDE_TOOLS)
add_subdirectory(tools)
endif()
add_subdirectory(tools)
if (MLIR_INCLUDE_EXAMPLES)
if( LLVM_INCLUDE_EXAMPLES )
add_subdirectory(examples)
endif()
option(MLIR_INCLUDE_DOCS "Generate build targets for the MLIR docs."
${LLVM_INCLUDE_DOCS})
if (MLIR_INCLUDE_DOCS)
add_subdirectory(docs)
endif()
if (NOT MLIR_INSTALL_TOOLCHAIN_ONLY)
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
install(DIRECTORY include/mlir include/mlir-c
DESTINATION include
COMPONENT mlir-headers

View File

@ -24,12 +24,7 @@ function(add_mlir_interface interface)
endfunction()
# Generate Documentation using the mlir-doc rule
# doc_filename: the basename of a .td tablegen file
# command: the tablegen command to run, typically "-gen-op-doc",
# "-gen-pass-doc", or "-gen-dialect-doc"
# output_file: the basename of a .md markdown file to be output
# output_directory: the directory to place the output
# Generate Documentation
function(add_mlir_doc doc_filename command output_file output_directory)
set(LLVM_TARGET_DEFINITIONS ${doc_filename}.td)
tablegen(MLIR ${output_file}.md ${command} "-I${MLIR_MAIN_INCLUDE_DIR}" "-I${MLIR_INCLUDE_DIR}")
@ -45,7 +40,7 @@ function(add_mlir_doc doc_filename command output_file output_directory)
endfunction()
# Declare an mlir library which can be compiled in libMLIR.so
# In addition to everything that llvm_add_library accepts, this
# In addition to everything that llvm_add_librar accepts, this
# also has the following option:
# EXCLUDE_FROM_LIBMLIR
# Don't include this library in libMLIR.so. This option should be used

View File

@ -31,17 +31,8 @@ list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
include(TableGen)
include(AddLLVM)
include(AddMLIR)
# Get a bunch of LLVM-style default options.
include(LLVMProjectOptions)
add_llvm_project_options(standalone)
include(HandleLLVMOptions)
# Get a bunch of default targets
include(LLVMProjectTargets)
add_llvm_project_targets(standalone)
include_directories(${LLVM_INCLUDE_DIRS})
include_directories(${MLIR_INCLUDE_DIRS})
include_directories(${PROJECT_SOURCE_DIR}/include)

View File

@ -6,7 +6,7 @@ set(LIBS
MLIROptLib
MLIRStandalone
)
add_standalone_tool(standalone-opt standalone-opt.cpp)
add_llvm_executable(standalone-opt standalone-opt.cpp)
llvm_update_compile_flags(standalone-opt)
target_link_libraries(standalone-opt PRIVATE ${LIBS})

View File

@ -5,7 +5,7 @@ set(LLVM_LINK_COMPONENTS
get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
get_property(translation_libs GLOBAL PROPERTY MLIR_TRANSLATION_LIBS)
add_standalone_tool(standalone-translate
add_llvm_executable(standalone-translate
standalone-translate.cpp
)
llvm_update_compile_flags(standalone-translate)

View File

@ -3,7 +3,7 @@ set_target_properties(Toy PROPERTIES FOLDER Examples)
macro(add_toy_chapter name)
add_dependencies(Toy ${name})
add_mlir_example(${name} ${ARGN})
add_llvm_example(${name} ${ARGN})
endmacro(add_toy_chapter name)
add_subdirectory(Ch1)

View File

@ -1,5 +1,4 @@
# RUN: %cmake %mlir_src_root/examples/standalone -DCMAKE_CXX_COMPILER=%host_cxx -DCMAKE_C_COMPILER=%host_cc -DMLIR_DIR=%llvm_lib_dir/cmake/mlir ; %cmake --build . --target check-standalone | tee %t | FileCheck %s
# RUN: %cmake --build . --target mlir-doc
# CHECK: Passed: 3
# UNSUPPORTED: windows, android

View File

@ -4,7 +4,7 @@ set(LLVM_LINK_COMPONENTS
nativecodegen
)
add_mlir_tool(mlir-cpu-runner
add_llvm_tool(mlir-cpu-runner
mlir-cpu-runner.cpp
)
llvm_update_compile_flags(mlir-cpu-runner)

View File

@ -68,7 +68,7 @@ if(MLIR_CUDA_RUNNER_ENABLED)
LIST(APPEND targets_to_link "LLVM${t}")
ENDFOREACH(t)
add_mlir_tool(mlir-cuda-runner
add_llvm_tool(mlir-cuda-runner
mlir-cuda-runner.cpp
DEPENDS

View File

@ -2,7 +2,7 @@ set(LLVM_LINK_COMPONENTS
Core
Support
)
add_mlir_tool(mlir-linalg-ods-gen
add_llvm_tool(mlir-linalg-ods-gen
mlir-linalg-ods-gen.cpp
)
llvm_update_compile_flags(mlir-linalg-ods-gen)

View File

@ -50,7 +50,7 @@ add_mlir_library(MLIRMlirOptMain
${LIBS}
)
add_mlir_tool(mlir-opt
add_llvm_tool(mlir-opt
mlir-opt.cpp
DEPENDS

View File

@ -43,7 +43,7 @@ set(LIBS
MLIRTransformUtils
)
add_mlir_tool(mlir-reduce
add_llvm_tool(mlir-reduce
OptReductionPass.cpp
Passes/OpReducer.cpp
ReductionNode.cpp

View File

@ -104,7 +104,7 @@ if(MLIR_ROCM_RUNNER_ENABLED)
LIST(APPEND targets_to_link "LLVM${t}")
ENDFOREACH(t)
add_mlir_tool(mlir-rocm-runner
add_llvm_tool(mlir-rocm-runner
mlir-rocm-runner.cpp
DEPENDS

View File

@ -5,7 +5,7 @@ set(LLVM_LINK_COMPONENTS
get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
get_property(translation_libs GLOBAL PROPERTY MLIR_TRANSLATION_LIBS)
add_mlir_tool(mlir-translate
add_llvm_tool(mlir-translate
mlir-translate.cpp
)
llvm_update_compile_flags(mlir-translate)

View File

@ -85,7 +85,7 @@ if (MLIR_VULKAN_RUNNER_ENABLED)
LIST(APPEND targets_to_link "LLVM${t}")
ENDFOREACH(t)
add_mlir_tool(mlir-vulkan-runner
add_llvm_tool(mlir-vulkan-runner
mlir-vulkan-runner.cpp
)
add_dependencies(mlir-vulkan-runner vulkan-runtime-wrappers)