forked from ROCm/rocm-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrocm-core-backward-compat.cmake
63 lines (54 loc) · 2.84 KB
/
rocm-core-backward-compat.cmake
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
# Copyright (c) 2023 Advanced Micro Devices, Inc. All Rights Reserved.
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
cmake_minimum_required(VERSION 3.16.8)
set(ROCM_CORE_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR})
set(ROCM_CORE_WRAPPER_DIR ${ROCM_CORE_BUILD_DIR}/wrapper_dir)
set(ROCM_CORE_WRAPPER_INC_DIR ${ROCM_CORE_WRAPPER_DIR}/include)
set(headerfile_dir "rocm-core")
#Function to set actual file contents in wrapper files
#Some components grep for the contents in the file
function(set_file_contents input_file)
set(hashzero_check "#if 0
/* The following is a copy of the original file for the benefit of build systems which grep for values
* in this file rather than preprocess it. This is just for backward compatibility */")
file(READ ${input_file} file_contents)
set(hash_endif "#endif")
get_filename_component(file_name ${input_file} NAME)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/header_template.hpp.in ${ROCM_CORE_WRAPPER_INC_DIR}/${file_name})
endfunction()
#use header template file and generate wrapper header files
function(generate_wrapper_header)
file(MAKE_DIRECTORY ${ROCM_CORE_WRAPPER_INC_DIR})
#find all header files
file(GLOB include_files ${ROCM_CORE_BUILD_DIR}/*.h)
#Create wrapper files
foreach(header_file ${include_files})
# set include guard
get_filename_component(INC_GAURD_NAME ${header_file} NAME_WE)
string(TOUPPER ${INC_GAURD_NAME} INC_GAURD_NAME)
set(include_guard "ROCM_CORE_WRAPPER_INCLUDE_${INC_GAURD_NAME}_H")
#set #include statement
get_filename_component(file_name ${header_file} NAME)
set(include_statements "#include \"${headerfile_dir}/${file_name}\"\n")
set_file_contents(${header_file})
endforeach()
endfunction()
#Use template header file and generater wrapper header files
generate_wrapper_header()
install(DIRECTORY ${ROCM_CORE_WRAPPER_INC_DIR} DESTINATION . COMPONENT runtime)