-
Notifications
You must be signed in to change notification settings - Fork 8
/
tsl.cmake
173 lines (155 loc) · 7.29 KB
/
tsl.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
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
cmake_minimum_required(VERSION 3.15)
set(Python_FIND_VIRTUALENV FIRST)
find_package(Python3 REQUIRED)
message(STATUS "Found python at ${Python3_EXECUTABLE}")
function(create_tsl)
set(options WORKAROUND_WARNINGS USE_CONCEPTS CREATE_TESTS DRAW_TEST_DEPENDENCIES)
set(oneValueArgs TSLGENERATOR_DIRECTORY DESTINATION)
set(multiValueArgs TARGETS_FLAGS APPEND_TARGETS_FLAGS PRIMITIVES_FILTER DATATYPES_FILTER LINK_OPTIONS GENERATOR_OPTIONS)
cmake_parse_arguments(CREATE_TSL_ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(NOT DEFINED CREATE_TSL_ARGS_TSLGENERATOR_DIRECTORY)
set(TSLGENERATOR_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
else()
set(TSLGENERATOR_DIRECTORY "${CREATE_TSL_ARGS_TSLGENERATOR_DIRECTORY}")
endif()
if (CREATE_TSL_ARGS_TARGETS_FLAGS STREQUAL "" OR NOT DEFINED CREATE_TSL_ARGS_TARGETS_FLAGS)
set(TARGETS_FLAGS "") # STRING "space separated lscpu flags for --targets, will attempt to call lscpu if empty"
execute_process(
COMMAND "${Python3_EXECUTABLE}" "${TSLGENERATOR_DIRECTORY}/detect_flags.py"
OUTPUT_VARIABLE TARGETS_FLAGS
RESULT_VARIABLE TSLHardwareReturnValue
)
# Remove trailing newline from the Python output
string(REGEX REPLACE "\n$" "" TARGETS_FLAGS "${TARGETS_FLAGS}")
if(NOT TSLHardwareReturnValue EQUAL 0)
message(FATAL_ERROR "Could not determine hardware flags. Please specify them manually.")
endif()
message(STATUS "lscpu flags: ${TARGETS_FLAGS}")
else()
set(TARGETS_FLAGS "${CREATE_TSL_ARGS_TARGETS_FLAGS}")
endif()
string(REGEX REPLACE "[ \t]+" ";" TARGETS_FLAGS_LIST "${TARGETS_FLAGS}")
list(APPEND TARGETS_FLAGS_LIST ${CREATE_TSL_ARGS_APPEND_TARGETS_FLAGS})
set(TSL_TARGETS_SWITCH "--targets" ${TARGETS_FLAGS_LIST})
if(NOT DEFINED CREATE_TSL_ARGS_PRIMITIVES_FILTER)
# message(STATUS "No primitive filtering.")
set(TSL_PRIMITIVE_SWITCH "")
else()
message(STATUS "relevant primitives: ${CREATE_TSL_ARGS_PRIMITIVES_FILTER}")
string(REGEX MATCHALL "([a-zA-Z\_])+" PRIMITIVE_LIST "${CREATE_TSL_ARGS_PRIMITIVES_FILTER}")
set(TSL_PRIMITIVE_SWITCH "--primitives" ${PRIMITIVE_LIST})
endif()
if(NOT DEFINED CREATE_TSL_ARGS_DATATYPES_FILTER)
# message(STATUS "No primitive filtering.")
set(TSL_TYPES_SWITCH "")
else()
message(STATUS "relevant data types: ${CREATE_TSL_ARGS_DATATYPES_FILTER}")
string(REGEX MATCHALL "([a-zA-Z\_0-9])+" TYPE_LIST "${CREATE_TSL_ARGS_DATATYPES_FILTER}")
set(TSL_TYPES_SWITCH "--types" ${TYPE_LIST})
endif()
if(NOT DEFINED CREATE_TSL_ARGS_LINK_OPTIONS)
# message(STATUS "No additional link options.")
unset(TSL_LINK_OPTIONS)
else()
# string(REPLACE ";" " " link_options_list "${CREATE_TSL_ARGS_LINK_OPTIONS}")
set(TSL_LINK_OPTIONS ${CREATE_TSL_ARGS_LINK_OPTIONS} CACHE STRING "linker options")
endif()
if(CREATE_TSL_ARGS_DESTINATION STREQUAL "" OR NOT DEFINED CREATE_TSL_ARGS_DESTINATION)
set(TSL_GENERATOR_DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/generator_output")
else()
set(TSL_GENERATOR_DESTINATION ${CREATE_TSL_ARGS_DESTINATION})
endif()
file(GLOB_RECURSE TSL_GENERATOR_SOURCES CONFIGURE_DEPENDS
"${TSLGENERATOR_DIRECTORY}/generator/config/*.template"
"${TSLGENERATOR_DIRECTORY}/generator/config/*.yaml"
"${TSLGENERATOR_DIRECTORY}/generator/static_files/*.yaml"
"${TSLGENERATOR_DIRECTORY}/generator/core/*.py"
"${TSLGENERATOR_DIRECTORY}/generator/expansions/*.py"
"${TSLGENERATOR_DIRECTORY}/generator/utils/*.py"
"${TSLGENERATOR_DIRECTORY}/primitive_data/extensions/*.yaml"
"${TSLGENERATOR_DIRECTORY}/primitive_data/primitives/*.yaml"
)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${TSL_GENERATOR_SOURCES})
if(NOT DEFINED CREATE_TSL_ARGS_GENERATOR_OPTIONS)
set(CURRENT_GENERATOR_OPTIONS "")
else()
set(CURRENT_GENERATOR_OPTIONS "${CREATE_TSL_ARGS_GENERATOR_OPTIONS}")
endif()
if(CREATE_TSL_ARGS_WORKAROUND_WARNINGS)
set(CURRENT_GENERATOR_OPTIONS "${CURRENT_GENERATOR_OPTIONS}" "--workaround-warnings")
else()
set(CURRENT_GENERATOR_OPTIONS "${CURRENT_GENERATOR_OPTIONS}" "--no-workaround-warnings")
endif()
if(CREATE_TSL_ARGS_CREATE_TESTS)
set(CURRENT_GENERATOR_OPTIONS "${CURRENT_GENERATOR_OPTIONS}" "--testing")
else()
set(CURRENT_GENERATOR_OPTIONS "${CURRENT_GENERATOR_OPTIONS}" "--no-testing")
endif()
if(CREATE_TSL_ARGS_DRAW_TEST_DEPENDENCIES)
set(CURRENT_GENERATOR_OPTIONS "${CURRENT_GENERATOR_OPTIONS}" "--draw-test-dependencies")
else()
set(CURRENT_GENERATOR_OPTIONS "${CURRENT_GENERATOR_OPTIONS}" "--no-draw-test-dependencies")
endif()
if(CREATE_TSL_ARGS_USE_CONCEPTS)
if("cxx_std_20" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
set(CMAKE_CXX_STANDARD 20)
#set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++20")
INCLUDE(CheckCXXSourceCompiles)
CHECK_CXX_SOURCE_COMPILES(
[[
#include <concepts>
struct test_struct {};
template<std::copyable T>
void test_concepts(T) {};
int main(void) {
test_concepts(test_struct{});
return 0;
}
]] SUPPORTS_CONCEPTS)
if(SUPPORTS_CONCEPTS)
message(STATUS "Compiler does support C++20 and concepts.")
else()
message(STATUS "Compiler does support C++20 but not concepts.")
set(CURRENT_GENERATOR_OPTIONS ${CURRENT_GENERATOR_OPTIONS} "--no-concepts")
endif()
else()
message(STATUS "Compiler does not support C++20.")
set(CURRENT_GENERATOR_OPTIONS ${CURRENT_GENERATOR_OPTIONS} "--no-concepts")
endif()
else()
set(CURRENT_GENERATOR_OPTIONS ${CURRENT_GENERATOR_OPTIONS} "--no-concepts")
endif()
set(TSL_GENERATOR_OPTIONS ${CURRENT_GENERATOR_OPTIONS}) #STRING "additonal cli options for the generator, semicolon separated"
message(STATUS "=== SUMMARY: TSL Generation ===")
message(STATUS "Script path : ${TSLGENERATOR_DIRECTORY}/main.py")
message(STATUS "Generation path : ${TSL_GENERATOR_DESTINATION}")
message(STATUS "Switches : ")
if(TSL_TARGETS_SWITCH STREQUAL "")
message(STATUS " all targets")
else()
message(STATUS " ${TSL_TARGETS_SWITCH}")
endif()
if(TSL_PRIMITIVE_SWITCH STREQUAL "")
message(STATUS " all primitives")
else()
message(STATUS " ${TSL_PRIMITIVE_SWITCH}")
endif()
if(TSL_TYPES_SWITCH STREQUAL "")
message(STATUS " all types")
else()
message(STATUS " ${TSL_TYPES_SWITCH}")
endif()
message(STATUS "Generator Options: ${TSL_GENERATOR_OPTIONS}")
message(STATUS "Target Options : ${TSL_LINK_OPTIONS}")
message(STATUS "===============================")
message(STATUS "Running TSL Generator...")
message(STATUS "Executing command: ${Python3_EXECUTABLE} ${TSLGENERATOR_DIRECTORY}/main.py ${TSL_GENERATOR_OPTIONS} -o ${TSL_GENERATOR_DESTINATION} ${TSL_TARGETS_SWITCH} ${TSL_PRIMITIVE_SWITCH} ${TSL_TYPES_SWITCH}")
execute_process(
COMMAND "${Python3_EXECUTABLE}" "${TSLGENERATOR_DIRECTORY}/main.py"
${TSL_GENERATOR_OPTIONS} -o "${TSL_GENERATOR_DESTINATION}"
${TSL_TARGETS_SWITCH} ${TSL_PRIMITIVE_SWITCH} ${TSL_TYPES_SWITCH}
)
set(TSL_INCLUDE_DIRECTORY "${TSL_GENERATOR_DESTINATION}/include" CACHE STRING "include path of TSL")
set(TSL_INCLUDE_DIRECTORY_ROOT "${TSL_GENERATOR_DESTINATION}/" CACHE STRING "root path of TSL")
add_subdirectory("${TSL_GENERATOR_DESTINATION}" "${TSL_GENERATOR_DESTINATION}/build")
endfunction()