-
Notifications
You must be signed in to change notification settings - Fork 1
/
rocsetup.cmake
76 lines (65 loc) · 2.11 KB
/
rocsetup.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
63
64
65
66
67
68
69
70
71
72
73
74
75
cmake_minimum_required(VERSION 3.25)
function(print_args)
math(EXPR LAST_INDEX "${CMAKE_ARGC}-1")
foreach(i RANGE 1 ${LAST_INDEX})
message("Argument ${i}: ${CMAKE_ARGV${i}}")
endforeach()
endfunction()
function(parse_args)
math(EXPR LAST_INDEX "${CMAKE_ARGC}-1")
set(options -p -a)
set(current_option "")
foreach(i RANGE 1 ${LAST_INDEX})
# message("Argument ${i}: ${CMAKE_ARGV${i}}")
set(arg "${CMAKE_ARGV${i}}")
if(${arg} IN_LIST options)
set(current_option "${arg}")
else()
if(current_option STREQUAL "-p")
set(ROCBUILD_PLATFORM "${arg}" PARENT_SCOPE)
elseif(current_option STREQUAL "-a")
set(ROCBUILD_ARCH "${arg}" PARENT_SCOPE)
endif()
set(current_option "")
endif()
endforeach()
endfunction()
function(set_generator)
if(ROCBUILD_PLATFORM STREQUAL "vs2022")
set(ROCBUILD_GENERATOR "Visual Studio 17 2022")
elseif(ROCBUILD_ARCH STREQUAL "vs2019")
set(ROCBUILD_GENERATOR "Visual Studio 16 2019")
endif()
if(ROCBUILD_GENERATOR MATCHES "Visual Studio")
if(ROCBUILD_ARCH MATCHES "x64")
set(ROCBUILD_GENERATOR_EXTRA -A x64)
elseif(ROCBUILD_ARCH MATCHES "x86")
set(ROCBUILD_GENERATOR_EXTRA -A win32)
endif()
endif()
set(ROCBUILD_GENERATOR ${ROCBUILD_GENERATOR} PARENT_SCOPE)
set(ROCBUILD_GENERATOR_EXTRA ${ROCBUILD_GENERATOR_EXTRA} PARENT_SCOPE)
endfunction()
#print_args()
parse_args()
set_generator()
message(STATUS "ROCBUILD_PLATFORM: ${ROCBUILD_PLATFORM}")
message(STATUS "ROCBUILD_ARCH: ${ROCBUILD_ARCH}")
message(STATUS "ROCBUILD_GENERATOR: ${ROCBUILD_GENERATOR}")
set(cmake_arguments
-S . -B build
-G ${ROCBUILD_GENERATOR} ${ROCBUILD_GENERATOR_EXTRA}
-DROCBUILD_PLATFORM=${ROCBUILD_PLATFORM} -DROCBUILD_ARCH=${ROCBUILD_ARCH}
)
string(REPLACE ";" " " cmake_arguments_str "${cmake_arguments}")
message(STATUS "CMake arguments: ${cmake_arguments_str}")
execute_process(
COMMAND cmake ${cmake_arguments}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE result
OUTPUT_VARIABLE output
ERROR_VARIABLE error_output
)
message("${result}")
message("${output}")
message("${error_output}")