forked from ROCm/HIPIFY
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
240 lines (205 loc) · 8.93 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
cmake_minimum_required(VERSION 3.16.8)
project(hipify-clang)
include(GNUInstallDirs)
find_package(LLVM REQUIRED CONFIG PATHS ${CMAKE_PREFIX_PATH})
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}:")
message(STATUS " - CMake module path: ${LLVM_CMAKE_DIR}")
message(STATUS " - Include path : ${LLVM_INCLUDE_DIRS}")
message(STATUS " - Binary path : ${LLVM_TOOLS_BINARY_DIR}")
option(HIPIFY_CLANG_TESTS "Build HIPIFY tests, if lit is installed" OFF)
option(HIPIFY_CLANG_TESTS_ONLY "Build HIPIFY tests only, if lit is installed and hipify-clang binary is already produced" OFF)
list(APPEND CMAKE_MODULE_PATH ${LLVM_CMAKE_DIR})
include(AddLLVM)
if (NOT HIPIFY_CLANG_TESTS_ONLY)
if(MSVC AND MSVC_VERSION VERSION_LESS "1900")
message(SEND_ERROR "hipify-clang could be built by Visual Studio 14 2015 or higher.")
return()
endif()
include_directories(${LLVM_INCLUDE_DIRS})
add_definitions(${LLVM_DEFINITIONS})
file(GLOB_RECURSE HIPIFY_SOURCES src/*.cpp)
file(GLOB_RECURSE HIPIFY_HEADERS src/*.h)
add_llvm_executable(hipify-clang ${HIPIFY_SOURCES} ${HIPIFY_HEADERS})
target_link_directories(hipify-clang PRIVATE ${LLVM_LIBRARY_DIRS})
set(CMAKE_CXX_COMPILER ${LLVM_TOOLS_BINARY_DIR}/clang++)
set(CMAKE_C_COMPILER ${LLVM_TOOLS_BINARY_DIR}/clang)
# Link against LLVM and CLANG libraries
target_link_libraries(hipify-clang PRIVATE
clangASTMatchers
clangFrontend
clangTooling
clangParse
clangSerialization
clangSema
clangEdit
clangFormat
clangLex
clangAnalysis
clangDriver
clangAST
clangToolingCore
clangRewrite
clangBasic
LLVMProfileData
LLVMSupport
LLVMMCParser
LLVMMC
LLVMBitReader
LLVMOption
LLVMCore)
if(LLVM_PACKAGE_VERSION VERSION_GREATER "6.0.1")
target_link_libraries(hipify-clang PRIVATE clangToolingInclusions)
endif()
if(LLVM_PACKAGE_VERSION VERSION_GREATER "9.0.1")
target_link_libraries(hipify-clang PRIVATE LLVMFrontendOpenMP)
endif()
if(LLVM_PACKAGE_VERSION VERSION_EQUAL "15.0.0" OR LLVM_PACKAGE_VERSION VERSION_GREATER "15.0.0")
target_link_libraries(hipify-clang PRIVATE LLVMWindowsDriver clangSupport)
endif()
if(LLVM_PACKAGE_VERSION VERSION_EQUAL "16.0.0" OR LLVM_PACKAGE_VERSION VERSION_GREATER "16.0.0")
if(MSVC)
set(STD "/std:c++17")
else()
set(STD "-std=c++17")
endif()
else()
if(MSVC)
set(STD "/std:c++14")
else()
set(STD "-std=c++14")
endif()
endif()
# [ToDo] Remove SWDEV_375013 related guards from CMakeLists.txt and HipifyAction.cpp along with the LLVM 16.0.0 official release
option (SWDEV_375013 "Enables SWDEV-375013 blocker workaround for the clang's change https://reviews.llvm.org/D140332" OFF)
if(SWDEV_375013)
add_definitions(-DSWDEV_375013)
endif()
if(MSVC)
target_link_libraries(hipify-clang PRIVATE version)
target_compile_options(hipify-clang PRIVATE ${STD} /Od /GR- /EHs- /EHc-)
set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} /SUBSYSTEM:WINDOWS")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${STD} -pthread -fno-rtti -fvisibility-inlines-hidden")
endif()
# Address Sanitize Flag
if(ADDRESS_SANITIZER)
set(addr_var -fsanitize=address)
else()
set(addr_var )
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${addr_var}")
# [ToDo] Remove D125860 related guards from CMakeLists.txt with the LLVM 16.0.0 official release
option (D125860 "Enables treating clang's resource dir as lib/clang/X.Y.Z, as it was before clang's change D125860, merged as e1b88c8a09be25b86b13f98755a9bd744b4dbf14" OFF)
if(D125860)
add_definitions(-D125860)
endif()
if((LLVM_PACKAGE_VERSION VERSION_EQUAL "16.0.0" OR LLVM_PACKAGE_VERSION VERSION_GREATER "16.0.0") AND (NOT D125860))
set(LIB_CLANG_RES ${LLVM_VERSION_MAJOR})
else()
set(LIB_CLANG_RES ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH})
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -DHIPIFY_CLANG_RES=\\\"${LLVM_LIBRARY_DIRS}/clang/${LIB_CLANG_RES}\\\" ${addr_var}")
set(INSTALL_PATH_DOC_STRING "hipify-clang Installation Path")
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${PROJECT_BINARY_DIR}/dist" CACHE PATH ${INSTALL_PATH_DOC_STRING} FORCE)
endif()
set(HIPIFY_INSTALL_PATH ${CMAKE_INSTALL_PREFIX})
install(TARGETS hipify-clang DESTINATION ${CMAKE_INSTALL_PREFIX})
install(
DIRECTORY ${CMAKE_SOURCE_DIR}/bin/
DESTINATION ${CMAKE_INSTALL_PREFIX}
USE_SOURCE_PERMISSIONS
PATTERN "hipify-perl"
PATTERN "*.sh")
install(
DIRECTORY ${LLVM_DIR}/../../clang/${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}/
DESTINATION ${CMAKE_INSTALL_PREFIX}
COMPONENT clang-resource-headers
FILES_MATCHING
PATTERN "*.h"
PATTERN "*.modulemap"
PATTERN "algorithm"
PATTERN "complex"
PATTERN "new"
PATTERN "ppc_wrappers" EXCLUDE
PATTERN "openmp_wrappers" EXCLUDE)
option(FILE_REORG_BACKWARD_COMPATIBILITY "Enable File Reorg with backward compatibility" ON)
if(UNIX)
#get rid of any RPATH definations already
set_target_properties(hipify-clang PROPERTIES INSTALL_RPATH "")
if(FILE_REORG_BACKWARD_COMPATIBILITY)
include(hipify-backward-compat.cmake)
endif()
set(CPACK_PACKAGING_INSTALL_PREFIX "/opt/rocm" CACHE PATH "HIP Package Installation Path")
set(BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/packages/hipify-clang)
configure_file(packaging/hipify-clang.txt ${BUILD_DIR}/CMakeLists.txt @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/LICENSE.txt ${BUILD_DIR}/LICENSE.txt @ONLY)
add_custom_target(package_hipify-clang COMMAND ${CMAKE_COMMAND} .
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
COMMAND rm -rf *.deb *.rpm *.tar.gz
COMMAND make package
COMMAND cp *.deb ${PROJECT_BINARY_DIR}
COMMAND cp *.rpm ${PROJECT_BINARY_DIR}
COMMAND cp *.tar.gz ${PROJECT_BINARY_DIR}
WORKING_DIRECTORY ${BUILD_DIR})
endif()
endif()
if(HIPIFY_CLANG_TESTS OR HIPIFY_CLANG_TESTS_ONLY)
find_package(PythonInterp 2.7 REQUIRED)
function (require_program PROGRAM_NAME)
find_program(FOUND_${PROGRAM_NAME} ${PROGRAM_NAME})
if(FOUND_${PROGRAM_NAME})
message(STATUS "Found ${PROGRAM_NAME}: ${FOUND_${PROGRAM_NAME}}")
else()
message(SEND_ERROR "Can't find ${PROGRAM_NAME}. Either set HIPIFY_CLANG_TESTS(_ONLY) to OFF to disable HIPIFY tests, or install the missing program.")
endif()
endfunction()
require_program(lit)
require_program(FileCheck)
find_package(CUDA REQUIRED)
if((CUDA_VERSION VERSION_LESS "7.0") OR (LLVM_PACKAGE_VERSION VERSION_LESS "3.8") OR
(CUDA_VERSION VERSION_GREATER "7.5" AND LLVM_PACKAGE_VERSION VERSION_LESS "4.0") OR
(CUDA_VERSION VERSION_GREATER "8.0" AND LLVM_PACKAGE_VERSION VERSION_LESS "6.0") OR
(CUDA_VERSION VERSION_GREATER "9.0" AND LLVM_PACKAGE_VERSION VERSION_LESS "7.0") OR
(CUDA_VERSION VERSION_GREATER "9.2" AND LLVM_PACKAGE_VERSION VERSION_LESS "8.0") OR
(CUDA_VERSION VERSION_GREATER "10.0" AND LLVM_PACKAGE_VERSION VERSION_LESS "9.0") OR
(CUDA_VERSION VERSION_GREATER "10.1" AND LLVM_PACKAGE_VERSION VERSION_LESS "10.0"))
message(SEND_ERROR "CUDA ${CUDA_VERSION} is not supported by LLVM ${LLVM_PACKAGE_VERSION}.")
if(CUDA_VERSION_MAJOR VERSION_LESS "7")
message(STATUS "Please install CUDA 7.0 or higher.")
elseif(CUDA_VERSION_MAJOR VERSION_LESS "8")
message(STATUS "Please install LLVM + clang 3.8 or higher.")
elseif(CUDA_VERSION_MAJOR VERSION_LESS "9")
message(STATUS "Please install LLVM + clang 4.0 or higher.")
elseif(CUDA_VERSION VERSION_EQUAL "9.0")
message(STATUS "Please install LLVM + clang 6.0 or higher.")
elseif(CUDA_VERSION_MAJOR VERSION_LESS "10")
message(STATUS "Please install LLVM + clang 7.0 or higher.")
elseif(CUDA_VERSION VERSION_EQUAL "10.0")
message(STATUS "Please install LLVM + clang 8.0 or higher.")
elseif(CUDA_VERSION VERSION_EQUAL "10.1")
message(STATUS "Please install LLVM + clang 9.0 or higher.")
elseif(CUDA_VERSION VERSION_EQUAL "10.2" OR CUDA_VERSION VERSION_EQUAL "11.0")
message(STATUS "Please install LLVM + clang 10.0 or higher.")
endif()
endif()
configure_file(
${CMAKE_CURRENT_LIST_DIR}/tests/lit.site.cfg.in
${CMAKE_CURRENT_BINARY_DIR}/tests/lit.site.cfg
@ONLY)
if(HIPIFY_CLANG_TESTS_ONLY)
add_lit_testsuite(test-hipify "Running HIPIFY regression tests"
${CMAKE_CURRENT_LIST_DIR}/tests
PARAMS site_config=${CMAKE_CURRENT_BINARY_DIR}/tests/lit.site.cfg
ARGS -v)
else()
add_lit_testsuite(test-hipify "Running HIPIFY regression tests"
${CMAKE_CURRENT_LIST_DIR}/tests
PARAMS site_config=${CMAKE_CURRENT_BINARY_DIR}/tests/lit.site.cfg
ARGS -v
DEPENDS hipify-clang)
endif()
add_custom_target(test-hipify-clang)
add_dependencies(test-hipify-clang test-hipify)
set_target_properties(test-hipify-clang PROPERTIES FOLDER "Tests")
endif()