aboutsummaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorMarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>2024-09-03 15:33:08 +0200
committerMarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>2024-09-05 10:57:19 +0200
commitfaecca9a85c1c1917d024f55cca34d19cc94f3b9 (patch)
tree2c40587ad90ba98ce784e33a8873ef3278e7373e /cmake
parentfac973647d69dd14089cee9972e8dfa0074c8a97 (diff)
test: Use span for raw data
This change allows to drop brittle sizeof calls in favor of the std::span::size method. Other improvements include: * Use of a namespace to mark test and bench data * Use of the modern std::byte * Drop of a no longer used std::vector copy and the bench/data module
Diffstat (limited to 'cmake')
-rw-r--r--cmake/module/GenerateHeaders.cmake4
-rw-r--r--cmake/script/GenerateHeaderFromRaw.cmake13
2 files changed, 11 insertions, 6 deletions
diff --git a/cmake/module/GenerateHeaders.cmake b/cmake/module/GenerateHeaders.cmake
index 35dc54eebb..c69007acb6 100644
--- a/cmake/module/GenerateHeaders.cmake
+++ b/cmake/module/GenerateHeaders.cmake
@@ -11,10 +11,10 @@ function(generate_header_from_json json_source_relpath)
)
endfunction()
-function(generate_header_from_raw raw_source_relpath)
+function(generate_header_from_raw raw_source_relpath raw_namespace)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${raw_source_relpath}.h
- COMMAND ${CMAKE_COMMAND} -DRAW_SOURCE_PATH=${CMAKE_CURRENT_SOURCE_DIR}/${raw_source_relpath} -DHEADER_PATH=${CMAKE_CURRENT_BINARY_DIR}/${raw_source_relpath}.h -P ${PROJECT_SOURCE_DIR}/cmake/script/GenerateHeaderFromRaw.cmake
+ COMMAND ${CMAKE_COMMAND} -DRAW_SOURCE_PATH=${CMAKE_CURRENT_SOURCE_DIR}/${raw_source_relpath} -DHEADER_PATH=${CMAKE_CURRENT_BINARY_DIR}/${raw_source_relpath}.h -DRAW_NAMESPACE=${raw_namespace} -P ${PROJECT_SOURCE_DIR}/cmake/script/GenerateHeaderFromRaw.cmake
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${raw_source_relpath} ${PROJECT_SOURCE_DIR}/cmake/script/GenerateHeaderFromRaw.cmake
VERBATIM
)
diff --git a/cmake/script/GenerateHeaderFromRaw.cmake b/cmake/script/GenerateHeaderFromRaw.cmake
index 18c5b4bef2..18a6c2b407 100644
--- a/cmake/script/GenerateHeaderFromRaw.cmake
+++ b/cmake/script/GenerateHeaderFromRaw.cmake
@@ -5,18 +5,23 @@
file(READ ${RAW_SOURCE_PATH} hex_content HEX)
string(REGEX MATCHALL "([A-Za-z0-9][A-Za-z0-9])" bytes "${hex_content}")
+file(WRITE ${HEADER_PATH} "#include <cstddef>\n")
+file(APPEND ${HEADER_PATH} "#include <span>\n")
+file(APPEND ${HEADER_PATH} "namespace ${RAW_NAMESPACE} {\n")
get_filename_component(raw_source_basename ${RAW_SOURCE_PATH} NAME_WE)
-file(WRITE ${HEADER_PATH} "static unsigned const char ${raw_source_basename}_raw[] = {\n")
+file(APPEND ${HEADER_PATH} "inline constexpr std::byte detail_${raw_source_basename}_raw[]{\n")
set(i 0)
foreach(byte ${bytes})
math(EXPR i "${i} + 1")
math(EXPR remainder "${i} % 8")
if(remainder EQUAL 0)
- file(APPEND ${HEADER_PATH} "0x${byte},\n")
+ file(APPEND ${HEADER_PATH} "std::byte{0x${byte}},\n")
else()
- file(APPEND ${HEADER_PATH} "0x${byte}, ")
+ file(APPEND ${HEADER_PATH} "std::byte{0x${byte}}, ")
endif()
endforeach()
-file(APPEND ${HEADER_PATH} "\n};")
+file(APPEND ${HEADER_PATH} "\n};\n")
+file(APPEND ${HEADER_PATH} "inline constexpr std::span ${raw_source_basename}{detail_${raw_source_basename}_raw};\n")
+file(APPEND ${HEADER_PATH} "}")