cmake_minimum_required(VERSION 3.12) project(toyc) set(CMAKE_CXX_STANDARD 14) find_package(LLVM CONFIG PATHS "${MLIR_INSTALL_PREFIX}" NO_DEFAULT_PATH) if (LLVM_FOUND) message(STATUS "Using LLVM ${LLVM_PACKAGE_VERSION} at ${LLVM_INSTALL_PREFIX}") else() message(FATAL_ERROR "LLVM not found; it is derived from MLIR_INSTALL_PREFIX which has value of ${MLIR_INSTALL_PREFIX}") endif() function(whole_archive_link target) if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") set(link_flags "-L${CMAKE_BINARY_DIR}/lib ") FOREACH(LIB ${ARGN}) string(CONCAT link_flags ${link_flags} "-Wl,-force_load ${CMAKE_BINARY_DIR}/lib/lib${LIB}.a ") ENDFOREACH(LIB) else() set(link_flags "-L${CMAKE_BINARY_DIR}/lib -Wl,--whole-archive,") FOREACH(LIB ${ARGN}) string(CONCAT link_flags ${link_flags} "-l${LIB},") ENDFOREACH(LIB) string(CONCAT link_flags ${link_flags} "--no-whole-archive") endif() set_target_properties(${target} PROPERTIES LINK_FLAGS ${link_flags}) endfunction(whole_archive_link) llvm_map_components_to_libnames(llvm_libs support) if (NOT ${LLVM_ENABLE_RTTI}) set(CMAKE_CXX_FLAGS "-fno-rtti ${CMAKE_CXX_FLAGS}") endif() include_directories( include ${LLVM_INCLUDE_DIR}) link_directories(${LLVM_LIBRARY_DIR}) add_definitions(${LLVM_DEFINITIONS}) add_executable(toyc toyc.cpp parser/AST.cpp mlir/EarlyLowering.cpp mlir/LateLowering.cpp mlir/MLIRGen.cpp mlir/ShapeInferencePass.cpp mlir/ToyDialect.cpp mlir/ToyCombine.cpp ) target_link_libraries(toyc PRIVATE ${llvm_libs} Linalg3DialectConstruction Linalg3 Linalg2 Linalg1 MLIRAnalysis MLIREDSC MLIRExecutionEngine MLIRIR MLIRLLVMIR MLIRParser MLIRPass MLIRTargetLLVMIR MLIRTransforms MLIRSupport ) whole_archive_link(toyc MLIRStandardOps MLIRAffineOps)