forked from ROCm/HIPIFY
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
196 lines (170 loc) · 7.46 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
cmake_minimum_required(VERSION 3.6.3)
project(hipify-clang)
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()
if (NOT UNIX)
find_package(LLVM REQUIRED CONFIG PATHS ${CMAKE_PREFIX_PATH})
else()
find_package(LLVM REQUIRED CONFIG PATHS ${CMAKE_PREFIX_PATH} /opt/rocm )
endif()
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)
list(APPEND CMAKE_MODULE_PATH ${LLVM_CMAKE_DIR})
include(AddLLVM)
include_directories(${LLVM_INCLUDE_DIRS})
link_directories(${LLVM_LIBRARY_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})
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 (MSVC)
target_link_libraries(hipify-clang PRIVATE version)
target_compile_options(hipify-clang PRIVATE /Od /GR- /EHs- /EHc-)
set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} /SUBSYSTEM:WINDOWS")
set(StdCpp "/std:c++")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -fno-rtti -fvisibility-inlines-hidden")
set(StdCpp "-std=c++")
endif()
if (LLVM_PACKAGE_VERSION VERSION_GREATER "9.0")
string(APPEND StdCpp "14")
# MSVC starting from 1900 (VS 2015) supports only the following c++ std values: c++14|c++17|c++latest
elseif (MSVC)
set(StdCpp "")
else()
string(APPEND StdCpp "11")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} ${StdCpp} -DHIPIFY_CLANG_RES=\\\"${LLVM_LIBRARY_DIRS}/clang/${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}\\\"")
set(INSTALL_PATH_DOC_STRING "hipify-clang Installation Path")
set(HIPIFY_INSTALL_PATH ${CMAKE_INSTALL_PREFIX})
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
if(CMAKE_BUILD_TYPE MATCHES Debug)
set(HIPIFY_INSTALL_PATH "${CMAKE_CURRENT_SOURCE_DIR}/bin" CACHE PATH ${INSTALL_PATH_DOC_STRING} FORCE)
elseif(CMAKE_BUILD_TYPE MATCHES Release)
if (BIN_INSTALL_DIR)
set(HIPIFY_INSTALL_PATH "${BIN_INSTALL_DIR}" CACHE PATH ${INSTALL_PATH_DOC_STRING} FORCE)
else()
set(HIPIFY_INSTALL_PATH "${PROJECT_BINARY_DIR}/bin" CACHE PATH ${INSTALL_PATH_DOC_STRING} FORCE)
endif()
else()
message(FATAL_ERROR "Invalid CMAKE_BUILD_TYPE specified. Valid values are 'Debug' and 'Release'.")
endif()
elseif(BIN_INSTALL_DIR)
set(HIPIFY_INSTALL_PATH "${BIN_INSTALL_DIR}" CACHE PATH ${INSTALL_PATH_DOC_STRING} FORCE)
endif()
install(TARGETS hipify-clang DESTINATION ${HIPIFY_INSTALL_PATH})
install(
DIRECTORY ${LLVM_DIR}/../../clang/${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}/
DESTINATION ${HIPIFY_INSTALL_PATH}
COMPONENT clang-resource-headers
FILES_MATCHING
PATTERN "*.h"
PATTERN "*.modulemap"
PATTERN "algorithm"
PATTERN "complex"
PATTERN "new"
PATTERN "ppc_wrappers" EXCLUDE
PATTERN "openmp_wrappers" EXCLUDE)
if (UNIX)
set(CPACK_PACKAGING_INSTALL_PREFIX "/opt/rocm/hip" 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)
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()
if (HIPIFY_CLANG_TESTS)
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 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)
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)
add_custom_target(test-hipify-clang)
add_dependencies(test-hipify-clang test-hipify)
set_target_properties(test-hipify-clang PROPERTIES FOLDER "Tests")
endif()