-
Notifications
You must be signed in to change notification settings - Fork 32
/
CMakeLists.txt
executable file
·270 lines (235 loc) · 8.82 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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#
# GCC 4.8 or higher compiler required.
#
# Required Defines on cmake command line
#
# 1) Set location of ROCR header files (required)
#
# ROCM_DIR="Root for RocM install"
#
# 2) Set ROCRTST_BLD_TYPE to either "Debug" or "Release".
# If not set, the default value is "Debug" is bound.
#
# ROCRTST_BLD_TYPE=Debug or ROCRTST_BLD_TYPE=Release
#
# 3) Set ROCRTST_BLD_BITS to either "32" or "64"
# If not set, the default value of "64" is bound.
#
# ROCRTST_BLD_BITS=32 or ROCRTST_BLD_BITS=64
#
# Building rocminfo
#
# 1) Create build folder e.g. "rocminfo/build" - any name will do
# 2) Cd into build folder
# 3) Run cmake, passing in the above defines, as needed/required:
# "cmake -DROCM_DIR=<path to rocm root> <other defines if needed> .."
# 4) Run "make"
#
# Upon a successful build, the executable "rocminfo" will be in the
# build directory.
#
# Currently support for Windows platform is not present
#
#
# Minimum version of cmake required
#
cmake_minimum_required(VERSION 3.6.3)
set(ROCMINFO_EXE "rocminfo")
set(PROJECT_NAME ${ROCMINFO_EXE})
project (${PROJECT_NAME})
include ( GNUInstallDirs )
if(WIN32)
message("This sample is not supported on Windows platform")
return()
endif()
# Generate static package, when BUILD_SHARED_LIBS is set to OFF.
# Default to ON
option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
## Set default module path if not already set
if(NOT DEFINED CMAKE_MODULE_PATH)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/")
endif()
## Include common cmake modules
include(utils)
#
# Process input variables
#
find_package(hsa-runtime64 1.0 REQUIRED )
string(TOLOWER "${ROCRTST_BLD_TYPE}" tmp)
if("${tmp}" STREQUAL release)
set(BUILD_TYPE "Release")
set(ISDEBUG 0)
else()
set(BUILD_TYPE "Debug")
set(ISDEBUG 1)
endif()
# The following default version values should be updated as appropriate for
# ABI breaks (update MAJOR and MINOR), and ABI/API additions (update MINOR).
# Until ABI stabilizes VERSION_MAJOR will be 0. This should be over-ridden
# by git tags (through "git describe") when they are present.
set(PKG_VERSION_MAJOR 1)
set(PKG_VERSION_MINOR 0)
set(PKG_VERSION_PATCH 0)
set(PKG_VERSION_NUM_COMMIT 0)
################# Determine the library version #########################
## Setup the package version based on git tags.
set(PKG_VERSION_GIT_TAG_PREFIX "rocminfo_pkg_ver")
find_program (GIT NAMES git)
get_package_version_number("1.0.0" ${PKG_VERSION_GIT_TAG_PREFIX} GIT)
# VERSION_* variables should be set by get_version_from_tag
message("Package version: ${PKG_VERSION_STR}")
#
# Print out the build configuration being used:
#
# Build Src directory
# Build Binary directory
# Build Type: Debug Vs Release, 32 Vs 64
# Compiler Version, etc
#
message("")
message("Build Configuration:")
message("-----------BuildType: " ${BUILD_TYPE})
message("------------Compiler: " ${CMAKE_CXX_COMPILER})
message("-------------Version: " ${CMAKE_CXX_COMPILER_VERSION})
message("--------Proj Src Dir: " ${PROJECT_SOURCE_DIR})
message("--------Proj Bld Dir: " ${PROJECT_BINARY_DIR})
message("--------Proj Lib Dir: " ${PROJECT_BINARY_DIR}/lib)
message("--------Proj Exe Dir: " ${PROJECT_BINARY_DIR}/bin)
message("")
#
# Set the build type based on user input
#
set(CMAKE_BUILD_TYPE ${BUILD_TYPE})
#
# Flag to enable / disable verbose output.
#
SET( CMAKE_VERBOSE_MAKEFILE on )
#
# Compiler pre-processor definitions.
#
# Define MACRO "DEBUG" if build type is "Debug"
if(${BUILD_TYPE} STREQUAL "Debug")
add_definitions(-DDEBUG)
endif()
add_definitions(-DLITTLEENDIAN_CPU=1)
#
# Linux Compiler options
#
set(ROCMINFO_CXX_FLAGS -std=c++11)
set(ROCMINFO_CXX_FLAGS ${ROCMINFO_CXX_FLAGS} -fexceptions)
set(ROCMINFO_CXX_FLAGS ${ROCMINFO_CXX_FLAGS} -fno-rtti)
set(ROCMINFO_CXX_FLAGS ${ROCMINFO_CXX_FLAGS} -fno-math-errno)
set(ROCMINFO_CXX_FLAGS ${ROCMINFO_CXX_FLAGS} -fno-threadsafe-statics)
set(ROCMINFO_CXX_FLAGS ${ROCMINFO_CXX_FLAGS} -fmerge-all-constants)
set(ROCMINFO_CXX_FLAGS ${ROCMINFO_CXX_FLAGS} -fms-extensions)
set(ROCMINFO_CXX_FLAGS ${ROCMINFO_CXX_FLAGS} -Werror)
set(ROCMINFO_CXX_FLAGS ${ROCMINFO_CXX_FLAGS} -Wall)
#
# Extend the compiler flags for 64-bit builds
#
if((${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "x86_64") OR (${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "AMD64"))
set(ROCMINFO_CXX_FLAGS ${ROCMINFO_CXX_FLAGS} -m64 -msse -msse2)
endif()
#
# Add compiler flags to include symbol information for debug builds
#
if(ISDEBUG)
set(ROCMINFO_CXX_FLAGS ${ROCMINFO_CXX_FLAGS} -ggdb -O0)
endif()
###########################
# rocm_agent_enumerator
###########################
configure_file(rocm_agent_enumerator rocm_agent_enumerator COPYONLY)
###########################
# RocR Info
###########################
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} ROCMINFO_SOURCES)
add_executable(${ROCMINFO_EXE} ${ROCMINFO_SOURCES})
target_link_libraries(${ROCMINFO_EXE} hsa-runtime64::hsa-runtime64)
target_compile_options(${ROCMINFO_EXE} PRIVATE ${ROCMINFO_CXX_FLAGS})
###########################
# Install directives
###########################
install (
TARGETS ${ROCMINFO_EXE}
DESTINATION ${CMAKE_INSTALL_BINDIR} )
install (
PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/rocm_agent_enumerator
DESTINATION ${CMAKE_INSTALL_BINDIR} )
###########################
# Packaging directives
###########################
if(BUILD_SHARED_LIBS)
set(CPACK_PACKAGE_NAME "${PROJECT_NAME}")
else()
set(CPACK_RPM_PACKAGE_NAME "${PROJECT_NAME}-static-devel")
set(CPACK_DEBIAN_PACKAGE_NAME "${PROJECT_NAME}-static-dev")
endif()
set(CPACK_PACKAGE_VENDOR "Advanced Micro Devices, Inc.")
set(CPACK_PACKAGE_VERSION_MAJOR "${PKG_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${PKG_VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${PKG_VERSION_PATCH}")
set(CPACK_PACKAGE_CONTACT "AMD Rocminfo Support <[email protected]>")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/License.txt")
set( CPACK_RPM_PACKAGE_LICENSE "NCSA" )
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Radeon Open Compute (ROCm) Runtime rocminfo tool")
#Install license file
install(FILES ${CPACK_RESOURCE_FILE_LICENSE} DESTINATION ${CMAKE_INSTALL_DOCDIR})
#Make proper version for appending
#Default Value is 99999, setting it first
set(ROCM_VERSION_FOR_PACKAGE "99999")
if(DEFINED ENV{ROCM_LIBPATCH_VERSION})
set(ROCM_VERSION_FOR_PACKAGE $ENV{ROCM_LIBPATCH_VERSION})
endif()
#Debian package specific variables
set(CPACK_DEBIAN_PACKAGE_DEPENDS "hsa-rocr, pciutils, python3, libc6, libgcc-s1, libstdc++6")
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE ${CPACK_DEBIAN_PACKAGE_HOMEPAGE} CACHE STRING "https://github.com/RadeonOpenCompute/ROCm")
if (DEFINED ENV{CPACK_DEBIAN_PACKAGE_RELEASE})
set(CPACK_DEBIAN_PACKAGE_RELEASE $ENV{CPACK_DEBIAN_PACKAGE_RELEASE})
else()
set(CPACK_DEBIAN_PACKAGE_RELEASE "local")
endif()
if ( ROCM_DEP_ROCMCORE )
string ( APPEND CPACK_DEBIAN_PACKAGE_DEPENDS ", rocm-core" )
endif()
#RPM package specific variables
execute_process(COMMAND rpm --eval %{?dist}
RESULT_VARIABLE PROC_RESULT
OUTPUT_VARIABLE EVAL_RESULT
OUTPUT_STRIP_TRAILING_WHITESPACE)
message("RESULT_VARIABLE ${PROC_RESULT} OUTPUT_VARIABLE: ${EVAL_RESULT}")
if(PROC_RESULT EQUAL "0" AND "${EVAL_RESULT}" STREQUAL ".el7")
# In Centos using parentheses is causing cpack errors.
# Set the dependencies specifically for centos
set(CPACK_RPM_PACKAGE_REQUIRES "hsa-rocr, pciutils, python3, glibc, libgcc, libstdc++")
else()
set(CPACK_RPM_PACKAGE_REQUIRES "hsa-rocr, pciutils, python3, glibc, (libgcc or libgcc_s1), (libstdc++ or libstdc++6)")
endif() # End EVAL_RESULT
if(DEFINED CPACK_PACKAGING_INSTALL_PREFIX)
set ( CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "${CPACK_PACKAGING_INSTALL_PREFIX} ${CPACK_PACKAGING_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}" )
endif()
if(DEFINED ENV{CPACK_RPM_PACKAGE_RELEASE})
set(CPACK_RPM_PACKAGE_RELEASE $ENV{CPACK_RPM_PACKAGE_RELEASE})
else()
set(CPACK_RPM_PACKAGE_RELEASE "local")
endif()
if ( ROCM_DEP_ROCMCORE )
string ( APPEND CPACK_RPM_PACKAGE_REQUIRES " rocm-core" )
endif()
# Cpack converts !/usr/bin/env python3 to /usr/libexec/platform-python in RHEL8.
# prevent the BRP(buildroot policy) script from checking and modifying interpreter directives
set(CPACK_RPM_SPEC_MORE_DEFINE "%undefine __brp_mangle_shebangs")
#Set rpm distro
if(CPACK_RPM_PACKAGE_RELEASE)
set(CPACK_RPM_PACKAGE_RELEASE_DIST ON)
endif()
#Prepare final version for the CPACK use
set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}.${ROCM_VERSION_FOR_PACKAGE}")
#Set the names now using CPACK utility
set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT")
set(CPACK_RPM_FILE_NAME "RPM-DEFAULT")
if(NOT BUILD_SHARED_LIBS)
string(REPLACE "hsa-rocr" "hsa-rocr-static-dev" CPACK_DEBIAN_PACKAGE_DEPENDS ${CPACK_DEBIAN_PACKAGE_DEPENDS})
string(REPLACE "hsa-rocr" "hsa-rocr-static-devel" CPACK_RPM_PACKAGE_REQUIRES ${CPACK_RPM_PACKAGE_REQUIRES})
endif()
include ( CPack )