Skip to content

Commit 170d9fc

Browse files
committed
Fix string too long on Windows
Signed-off-by: David Laseca Perez <davidlaseca@eprosima.com>
1 parent 6f635ce commit 170d9fc

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

ddsrouter_yaml/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,18 @@ compile_test_library(
8080
file(READ "${PROJECT_SOURCE_DIR}/../resources/configurations/ddsrouter_config_schema.json"
8181
DDSROUTER_CONFIG_SCHEMA_CONTENT)
8282

83+
# Split into <=16000-char chunks to work around MSVC C2026 string literal size limit.
84+
# Adjacent string literals are concatenated by the compiler.
85+
string(LENGTH "${DDSROUTER_CONFIG_SCHEMA_CONTENT}" _schema_len)
86+
set(_chunk_size 16000)
87+
set(DDSROUTER_CONFIG_SCHEMA_CHUNKS "")
88+
set(_offset 0)
89+
while(_offset LESS _schema_len)
90+
string(SUBSTRING "${DDSROUTER_CONFIG_SCHEMA_CONTENT}" ${_offset} ${_chunk_size} _chunk)
91+
string(APPEND DDSROUTER_CONFIG_SCHEMA_CHUNKS " R\"json(${_chunk})json\"\n")
92+
math(EXPR _offset "${_offset} + ${_chunk_size}")
93+
endwhile()
94+
8395
configure_file(
8496
"${PROJECT_SOURCE_DIR}/include/ddsrouter_yaml/DdsRouterConfigSchema.hpp.in"
8597
"${CMAKE_CURRENT_BINARY_DIR}/include/ddsrouter_yaml/DdsRouterConfigSchema.hpp"

ddsrouter_yaml/include/ddsrouter_yaml/DdsRouterConfigSchema.hpp.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@
1414

1515
#pragma once
1616

17-
static const char* DDSROUTER_CONFIG_SCHEMA = R"json(@DDSROUTER_CONFIG_SCHEMA_CONTENT@)json";
17+
static const char* DDSROUTER_CONFIG_SCHEMA =
18+
@DDSROUTER_CONFIG_SCHEMA_CHUNKS@;

0 commit comments

Comments
 (0)