forked from intel/workload-services-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
186 lines (162 loc) · 6.79 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
#
# Apache v2 license
# Copyright (C) 2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
#
cmake_minimum_required (VERSION 2.8...3.24)
Project(workloads NONE)
STRING(ASCII 27 esc)
set(red "${esc}[31m")
set(green "${esc}[32m")
set(strikethrough "${esc}[9m")
set(reset "${esc}[0m")
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/script/")
include(prerequisite)
add_custom_target(bom)
enable_testing()
set(PLATFORM_CONV_FROM "")
include(platform OPTIONAL)
if(EXISTS "${CMAKE_SOURCE_DIR}/workload/platforms")
set(platforms "${CMAKE_SOURCE_DIR}/workload/platforms")
else()
set(platforms "${CMAKE_SOURCE_DIR}/platforms")
endif()
if(NOT DEFINED PLATFORM)
execute_process(COMMAND bash -c "head -n 1 '${platforms}'" OUTPUT_VARIABLE PLATFORM OUTPUT_STRIP_TRAILING_WHITESPACE)
else()
execute_process(COMMAND bash -c "grep -E '^${PLATFORM}$' '${platforms}' | head -n 1" OUTPUT_VARIABLE platform OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT platform)
message(FATAL_ERROR "Platform ${PLATFORM} not recognized!")
endif()
set(PLATFORM "${platform}")
endif()
include(registry OPTIONAL)
execute_process(COMMAND bash -c "GIT_SSH_COMMAND='ssh -o BatchMode=yes' GIT_ASKPASS=echo git fetch --tags > /dev/null;GIT_ASKPASS=echo git tag | sort -V" TIMEOUT 5 OUTPUT_VARIABLE tmp RESULT_VARIABLE status OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
if (RELEASE MATCHES "^:?v?[0-9]+[.][0-9]+[.]*[0-9]*$")
string(REPLACE ":" "" release1 "${RELEASE}")
if ((status EQUAL 0) AND (tmp MATCHES "${release1}"))
if((NOT DEFINED REGISTRY) OR (NOT REGISTRY))
set(REGISTRY "${DEFAULT_REGISTRY}")
endif()
endif()
endif()
string(REGEX REPLACE ".*\n" "" tmp "${tmp}")
string(REGEX REPLACE "(v?[0-9]*[.][0-9]*)[.].*" "\\1" mtmp "${tmp}")
if (tmp AND (status EQUAL 0))
if ((NOT RELEASE STREQUAL ":${tmp}") AND (NOT RELEASE STREQUAL "${tmp}"))
message("")
message("*************************************************************")
message("")
if (tmp STREQUAL mtmp)
message("${green}INFO:${reset} Detected major release ${mtmp}.")
else()
message("${green}INFO:${reset} Detected major release ${mtmp} and minor releases up to ${tmp}.")
message("${green}INFO:${reset} Minor releases do not cover all workloads. See workload README.")
endif()
message("${green}INFO:${reset} Switch to a major/minor release as follows:")
message("${green}INFO:${reset} git checkout tags/${mtmp}")
message("${green}INFO:${reset} cmake -DRELEASE=${mtmp} ..")
message("")
message("*************************************************************")
message("")
endif()
else()
message("")
message("****************************************************************************")
message("")
message("${red}WARNING:${reset} Failed to detect any official release.")
message(" Switch to any release as follows:")
message("")
message("git checkout <VERSION>")
message("cmake -DREGISTRY=${DEFAULT_REGISTRY} -DRELEASE=v<VERSION> ..")
message("")
message("****************************************************************************")
endif()
if (NOT ${REGISTRY} MATCHES "/$")
set(REGISTRY "${REGISTRY}/")
endif()
set(BUILDSH_OPTIONS "")
if (REGISTRY STREQUAL "${DEFAULT_REGISTRY}/")
execute_process(COMMAND bash -c "grep -q -F $(echo ${REGISTRY} | cut -f1 -d/) ~/.docker/config.json" RESULT_VARIABLE disable_build OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
if(disable_build)
set(BUILDSH_OPTIONS "--read-only-registry")
endif()
endif()
if ((NOT DEFINED TIMEOUT) OR (TIMEOUT STREQUAL ""))
set(TIMEOUT "28800,600")
endif()
if ((NOT DEFINED RELEASE) OR (RELEASE STREQUAL ""))
set(RELEASE ":latest")
elseif (NOT ${RELEASE} MATCHES "^:")
set(RELEASE ":${RELEASE}")
endif()
string(TOLOWER "${RELEASE}" RELEASE)
if ((NOT DEFINED BENCHMARK) AND (EXISTS "${CMAKE_SOURCE_DIR}/workload/dummy"))
set(BENCHMARK "dummy")
message("${green}INFO:${reset} Default to the dummy workload for quick evaluation.")
message(" Enable specific workload with cmake -DBENCHMARK=<name> .. or")
message(" Enable all workloads with cmake -DBENCHMARK= ..")
message("")
endif()
if (NOT DEFINED BACKEND)
if(EXISTS "${PROJECT_SOURCE_DIR}/script/terraform.cmake")
set(BACKEND "terraform")
endif()
endif()
if(BACKEND)
include(${BACKEND} OPTIONAL)
endif()
set(IMAGEARCH "linux/amd64")
set(IMAGESUFFIX "")
include(multi-arch OPTIONAL)
foreach(subdir image stack workload dist)
if(EXISTS "${PROJECT_SOURCE_DIR}/${subdir}")
add_subdirectory(${subdir})
endif()
endforeach()
message("")
message("-- Setting: PLATFORM=${PLATFORM}${PLATFORM_CONV_FROM}, ARCH=${IMAGEARCH}")
if(NOT DEFINED REGISTRY_AUTH)
message("-- Setting: REGISTRY=${REGISTRY}")
else()
message("-- Setting: REGISTRY=${REGISTRY}, AUTH=${REGISTRY_AUTH}")
endif()
message("-- Setting: RELEASE=${RELEASE}")
if(BACKEND)
message("-- Setting: TIMEOUT=${TIMEOUT}")
endif()
if(ACCEPT_LICENSE)
message("-- Setting: ACCEPT_LICENSE=${ACCEPT_LICENSE}")
endif()
if(BACKEND)
message("-- Setting: BENCHMARK=${BENCHMARK}")
message("-- Setting: BACKEND=${BACKEND}")
endif()
if(COMMAND show_backend_settings)
show_backend_settings()
endif()
message("")
if(BUILDSH_OPTIONS MATCHES "--read-only-registry")
message("${green}INFO:${reset} Build is disabled as ${DEFAULT_REGISTRY} is a readonly docker registry")
endif()
if(COMMAND detect_backend_warnings)
detect_backend_warnings()
endif()
if (RELEASE MATCHES "^:v[0-9]+[.][0-9]+[.]*[0-9]*$")
string(REPLACE ":" "" release1 "${RELEASE}")
if((NOT REGISTRY STREQUAL "${DEFAULT_REGISTRY}") AND (NOT REGISTRY STREQUAL "${DEFAULT_REGISTRY}/") AND DEFAULT_REGISTRY)
message("${red}WARNING:${reset} Issue 'cmake -DREGISTRY=${DEFAULT_REGISTRY} ..' to use official ${release1} images")
endif()
execute_process(COMMAND bash -c "GIT_SSH_COMMAND='ssh -o BatchMode=yes' GIT_ASKPASS=echo git show-ref -s refs/tags/${release1}" TIMEOUT 5 OUTPUT_VARIABLE tag_commit_id RESULT_VARIABLE status OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
if (status EQUAL 0)
execute_process(COMMAND bash -c "GIT_SSH_COMMAND='ssh -o BatchMode=yes' GIT_ASKPASS=echo git log -1 | head -n1 | cut -f2 -d' '" TIMEOUT 5 OUTPUT_VARIABLE head_commit_id RESULT_VARIABLE head_status OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
if (NOT tag_commit_id STREQUAL head_commit_id)
message("${red}WARNING:${reset} Issue 'git checkout tags/${release1}' to match codebase with release ${release1}")
endif()
endif()
endif()
if(EXISTS "${PROJECT_SOURCE_DIR}/script/benchmark")
execute_process(COMMAND bash -c "ln -s -r -f '${PROJECT_SOURCE_DIR}'/script/benchmark/*.sh ." WORKING_DIRECTORY "${CMAKE_BINARY_DIR}")
endif()
message("")
include(legalnotice OPTIONAL)