Skip to content

Commit 907e606

Browse files
committed
fix(scriptcompiler): add public allocateID API and FetchContent fallback for nlohmann-json
1 parent 929e8e1 commit 907e606

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

Core/Libraries/Include/DataChunk/DataChunk.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ class DataChunkOutput
138138

139139
/** Write an array of bytes. */
140140
void writeArrayOfBytes(const char* ptr, ChunkInt len);
141+
142+
/** Allocate or get existing ID for a chunk type name.
143+
@param name Chunk type name
144+
@return Integer ID (existing or newly allocated) */
145+
ChunkUInt allocateID(const ChunkString& name);
141146
};
142147

143148
//----------------------------------------------------------------------

Core/Libraries/Source/DataChunk/DataChunkOutput.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,5 +193,10 @@ void DataChunkOutput::writeArrayOfBytes(const char* ptr, ChunkInt len)
193193
}
194194
}
195195

196+
ChunkUInt DataChunkOutput::allocateID(const ChunkString& name)
197+
{
198+
return m_contents.allocateID(name);
199+
}
200+
196201
} // namespace DataChunk
197202

Core/Tools/ScriptCompiler/CMakeLists.txt

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,29 @@ set(SCRIPTCOMPILER_SRC
22
"ScriptCompiler.cpp"
33
)
44

5-
find_package(nlohmann_json CONFIG REQUIRED)
6-
75
add_executable(core_scriptcompiler)
86
set_target_properties(core_scriptcompiler PROPERTIES OUTPUT_NAME scriptcompiler)
97

108
target_sources(core_scriptcompiler PRIVATE ${SCRIPTCOMPILER_SRC})
119

10+
# Try to find nlohmann-json from vcpkg first
11+
find_package(nlohmann_json CONFIG)
12+
if(nlohmann_json_FOUND)
13+
# Use vcpkg version
14+
target_link_libraries(core_scriptcompiler PRIVATE nlohmann_json::nlohmann_json)
15+
else()
16+
# Fallback: fetch from GitHub (header-only library)
17+
include(FetchContent)
18+
FetchContent_Declare(json
19+
GIT_REPOSITORY https://github.com/nlohmann/json.git
20+
GIT_TAG v3.11.3
21+
GIT_SHALLOW TRUE
22+
)
23+
FetchContent_MakeAvailable(json)
24+
target_link_libraries(core_scriptcompiler PRIVATE nlohmann_json::nlohmann_json)
25+
endif()
26+
1227
target_link_libraries(core_scriptcompiler PRIVATE
13-
nlohmann_json::nlohmann_json
1428
core_datachunk
1529
)
1630

Core/Tools/ScriptCompiler/ScriptCompiler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ bool writeJsonToBinary(const json& input, const std::string& outFile)
863863
{
864864
if (!stringTable[i].empty())
865865
{
866-
chunkOutput.m_contents.allocateID(stringTable[i]);
866+
chunkOutput.allocateID(stringTable[i]);
867867
}
868868
}
869869

0 commit comments

Comments
 (0)