|
18 | 18 | cmake_minimum_required(VERSION 3.20)
|
19 | 19 | project(GraphCompiler VERSION "0.1.0" LANGUAGES C CXX)
|
20 | 20 |
|
21 |
| -set(CMAKE_CXX_STANDARD 17) |
| 21 | +############################# Cmake options #################################### |
| 22 | +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
22 | 23 | set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
23 | 24 | set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0")
|
24 |
| - |
25 |
| -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) |
26 |
| - |
27 | 25 | list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
|
28 | 26 |
|
| 27 | +# Silence a false positive GCC -Wunused-but-set-parameter warning in constexpr |
| 28 | +# cases, by marking SelectedCase as used. See |
| 29 | +# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85827 for details. The issue is |
| 30 | +# fixed in GCC 10. |
| 31 | +if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "10.0") |
| 32 | + check_cxx_compiler_flag("-Wno-unused-but-set-parameter" CXX_SUPPORTS_WNO_UNUSED_BUT_SET_PARAMETER) |
| 33 | + append_if(CXX_SUPPORTS_WNO_UNUSED_BUT_SET_PARAMETER "-Wno-unused-but-set-parameter" CMAKE_CXX_FLAGS) |
| 34 | +endif() |
| 35 | +################################################################################ |
| 36 | + |
| 37 | +############################ Build options ##################################### |
29 | 38 | option(GC_ENABLE_LEGACY ON)
|
30 | 39 | option(GC_ENABLE_DNNL "Enable the oneDNN library integration" ON)
|
31 | 40 | option(GC_ENABLE_TEST "Build the tests" ON)
|
32 | 41 | option(GC_ENABLE_TEST_DNNL "Build the dnnl tests" ${GC_ENABLE_DNNL})
|
33 | 42 | option(GC_ENABLE_TEST_MLIR "Build the mlir tests" ON)
|
34 |
| -option(GC_ENABLE_OPT "Build gc-opt" ON) |
| 43 | +option(GC_ENABLE_TOOLS "Build the tools" ON) |
| 44 | +option(GC_ENABLE_OPT "Build gc-opt" ${GC_ENABLE_TOOLS}) |
35 | 45 | option(GC_ENABLE_GPU "Enable GPU backend" OFF)
|
36 | 46 | option(GC_ENABLE_IMEX "Intel® Extension for MLIR" OFF)
|
37 | 47 | option(GC_ENABLE_BINDINGS_PYTHON "Enable Graph Complier Python Binding" ON)
|
38 | 48 | option(GC_DEV_LINK_LLVM_DYLIB "Link dynamic libraries of LLVM and MLIR. For developers only. Do not use it in packing the library." OFF)
|
39 | 49 |
|
40 | 50 | if(GC_ENABLE_LEGACY)
|
41 |
| - add_subdirectory(legacy/core) |
| 51 | + add_subdirectory(legacy/core) |
42 | 52 | endif()
|
43 | 53 |
|
44 |
| -find_package(MLIR REQUIRED CONFIG) |
45 |
| - |
46 |
| -message(STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR}") |
47 |
| -message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") |
48 |
| - |
49 |
| -set(LLVM_RUNTIME_OUTPUT_INTDIR ${PROJECT_BINARY_DIR}/bin) |
50 |
| -set(LLVM_LIBRARY_OUTPUT_INTDIR ${PROJECT_BINARY_DIR}/lib) |
51 |
| -set(MLIR_BINARY_DIR ${PROJECT_BINARY_DIR}) |
52 |
| - |
53 |
| -list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}") |
54 |
| -list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}") |
55 |
| - |
56 |
| -include(TableGen) |
57 |
| -include(AddLLVM) |
58 |
| -include(AddMLIR) |
59 |
| -include(HandleLLVMOptions) |
60 |
| - |
61 | 54 | if(GC_ENABLE_DNNL)
|
62 |
| - add_definitions(-DGC_HAS_ONEDNN_DIALECT) |
63 | 55 | set(GC_ONEDNN_DIALECT_LIB_NAME MLIROneDNNGraph)
|
64 |
| -endif () |
65 |
| - |
66 |
| -if(GC_ENABLE_GPU) |
67 |
| - add_definitions(-DGC_USE_GPU) |
68 |
| -endif () |
69 |
| - |
70 |
| -if(GC_ENABLE_IMEX) |
71 |
| - include(imex) |
72 |
| - if(GC_DEV_LINK_LLVM_DYLIB) |
73 |
| - message(WARN "GPU backend may not be compatible with dynamic linking to LLVM") |
74 |
| - endif() |
75 |
| -endif() |
76 |
| - |
77 |
| -if (GC_ENABLE_OPT) |
78 |
| - set(GC_OPT_EXE_NAME gc-opt) |
79 |
| -endif () |
80 |
| - |
81 |
| -if(GC_ENABLE_BINDINGS_PYTHON AND NOT MLIR_ENABLE_BINDINGS_PYTHON) |
82 |
| - message(STATUS "Failed to enable Python API due to the 'MLIR_ENABLE_BINDINGS_PYTHON' for LLVM is not ON.") |
83 |
| - set(GC_ENABLE_BINDINGS_PYTHON OFF CACHE BOOL "" FORCE) |
84 |
| -endif() |
85 |
| - |
86 |
| -if(GC_ENABLE_BINDINGS_PYTHON) |
87 |
| - include(MLIRDetectPythonEnv) |
88 |
| - mlir_configure_python_dev_packages() |
89 | 56 | endif()
|
| 57 | +################################################################################ |
90 | 58 |
|
91 |
| -include_directories( |
92 |
| - ${LLVM_INCLUDE_DIRS} |
93 |
| - ${MLIR_INCLUDE_DIRS} |
94 |
| - ${PROJECT_BINARY_DIR}/include |
95 |
| - ${PROJECT_SOURCE_DIR}/include |
| 59 | +############################## Targets ######################################### |
| 60 | +# All common options, includes etc. are added to this interface target. |
| 61 | +add_library(GcInterface INTERFACE) |
| 62 | +target_compile_features(GcInterface INTERFACE cxx_std_17) |
| 63 | +target_include_directories(GcInterface INTERFACE |
| 64 | + $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include> |
| 65 | + $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> |
| 66 | + $<INSTALL_INTERFACE:include> |
96 | 67 | )
|
97 | 68 |
|
98 |
| -add_definitions(${LLVM_DEFINITIONS}) |
99 |
| - |
100 |
| -set(GC_MLIR_CXX_FLAGS "") |
101 |
| -# Silence a false positive GCC -Wunused-but-set-parameter warning in constexpr |
102 |
| -# cases, by marking SelectedCase as used. See |
103 |
| -# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85827 for details. The issue is |
104 |
| -# fixed in GCC 10. |
105 |
| -if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "10.0") |
106 |
| - check_cxx_compiler_flag("-Wno-unused-but-set-parameter" CXX_SUPPORTS_WNO_UNUSED_BUT_SET_PARAMETER) |
107 |
| - append_if(CXX_SUPPORTS_WNO_UNUSED_BUT_SET_PARAMETER "-Wno-unused-but-set-parameter" GC_MLIR_CXX_FLAGS) |
108 |
| -endif() |
109 |
| -include("cmake/version.cmake") |
| 69 | +include(functions) |
| 70 | +include(version) |
| 71 | +include(mlir) |
110 | 72 |
|
111 | 73 | add_subdirectory(include)
|
112 | 74 | add_subdirectory(lib)
|
113 | 75 | add_subdirectory(src)
|
114 |
| -if(GC_ENABLE_BINDINGS_PYTHON) |
115 |
| - message(STATUS "Enabling Python API") |
116 |
| - add_subdirectory(python) |
117 |
| -endif() |
| 76 | +add_subdirectory(python) |
118 | 77 | add_subdirectory(test)
|
| 78 | +################################################################################ |
119 | 79 |
|
120 |
| -# Export the targets |
121 |
| -add_library(GcInterface INTERFACE) |
122 |
| -target_include_directories(GcInterface INTERFACE |
123 |
| - $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include> |
124 |
| - $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> |
125 |
| - $<INSTALL_INTERFACE:include> |
126 |
| -) |
| 80 | +############################### Install ######################################## |
127 | 81 | install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/ TYPE INCLUDE)
|
128 | 82 | install(DIRECTORY ${PROJECT_BINARY_DIR}/include/ TYPE INCLUDE
|
129 |
| - PATTERN "CMake*" EXCLUDE PATTERN "*.cmake" EXCLUDE) |
130 |
| -install(TARGETS |
131 |
| - GcCpuRuntime |
132 |
| - GcGpuPasses |
133 |
| - GcInterface |
134 |
| - GcJitWrapper |
135 |
| - GcPasses |
136 |
| - GcUtilsIR |
137 |
| - MLIRCPURuntimeDialect |
138 |
| - MLIRCPURuntimeTransforms |
139 |
| - MLIRLinalgx |
140 |
| - MLIRMicrokernel |
141 |
| - ${GC_OPT_EXE_NAME} |
142 |
| - ${GC_ONEDNN_DIALECT_LIB_NAME} |
| 83 | + REGEX "CMake.*|.*cmake" EXCLUDE) |
143 | 84 |
|
144 |
| - EXPORT ${PROJECT_NAME}Targets |
145 |
| - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
146 |
| - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
147 |
| - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} |
148 |
| - INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} |
149 |
| - PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} |
| 85 | +# Export the targets |
| 86 | +get_property(GC_TOOLS GLOBAL PROPERTY GC_TOOLS) |
| 87 | +get_property(GC_MLIR_LIBS GLOBAL PROPERTY GC_MLIR_LIBS) |
| 88 | +get_property(GC_PASS_LIBS GLOBAL PROPERTY GC_PASS_LIBS) |
| 89 | +get_property(GC_DIALECT_LIBS GLOBAL PROPERTY GC_DIALECT_LIBS) |
| 90 | +install(TARGETS |
| 91 | + GcInterface |
| 92 | + ${GC_TOOLS} |
| 93 | + ${GC_MLIR_LIBS} |
| 94 | + ${GC_PASS_LIBS} |
| 95 | + ${GC_DIALECT_LIBS} |
| 96 | + EXPORT ${PROJECT_NAME}Targets |
| 97 | + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 98 | + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 99 | + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} |
| 100 | + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} |
| 101 | + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} |
150 | 102 | )
|
151 | 103 | export(EXPORT ${PROJECT_NAME}Targets
|
152 |
| - FILE "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake" |
| 104 | + FILE "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake" |
153 | 105 | )
|
154 | 106 | install(EXPORT ${PROJECT_NAME}Targets
|
155 |
| - FILE ${PROJECT_NAME}Targets.cmake |
156 |
| - DESTINATION lib/cmake/${PROJECT_NAME} |
| 107 | + FILE ${PROJECT_NAME}Targets.cmake |
| 108 | + DESTINATION lib/cmake/${PROJECT_NAME} |
157 | 109 | )
|
158 | 110 |
|
159 | 111 | # Generate the config files
|
160 | 112 | include(CMakePackageConfigHelpers)
|
161 | 113 | configure_package_config_file(
|
162 |
| - ${PROJECT_SOURCE_DIR}/cmake/Config.cmake.in |
163 |
| - "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" |
164 |
| - INSTALL_DESTINATION "lib/cmake/${PROJECT_NAME}" |
165 |
| - NO_SET_AND_CHECK_MACRO |
166 |
| - NO_CHECK_REQUIRED_COMPONENTS_MACRO |
| 114 | + ${PROJECT_SOURCE_DIR}/cmake/Config.cmake.in |
| 115 | + "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" |
| 116 | + INSTALL_DESTINATION "lib/cmake/${PROJECT_NAME}" |
| 117 | + NO_SET_AND_CHECK_MACRO |
| 118 | + NO_CHECK_REQUIRED_COMPONENTS_MACRO |
167 | 119 | )
|
168 | 120 | write_basic_package_version_file(
|
169 |
| - "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" |
170 |
| - COMPATIBILITY AnyNewerVersion |
| 121 | + "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" |
| 122 | + COMPATIBILITY AnyNewerVersion |
171 | 123 | )
|
172 | 124 | install(FILES
|
173 |
| - ${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake |
174 |
| - ${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake |
175 |
| - DESTINATION "lib/cmake/${PROJECT_NAME}" |
| 125 | + ${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake |
| 126 | + ${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake |
| 127 | + DESTINATION "lib/cmake/${PROJECT_NAME}" |
176 | 128 | )
|
| 129 | +################################################################################ |
0 commit comments