blob: da5e416c55fa5a40f1ce65b4d63be860171f6f81 (
plain)
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
|
# cmake/ParseWorkspace.cmake - Workspace configuration parser
function(parse_workspace_config WORKSPACE_DIR)
set(WORKSPACE_CFG "${WORKSPACE_DIR}/workspace.cfg")
if(NOT EXISTS ${WORKSPACE_CFG})
message(FATAL_ERROR "Workspace config not found: ${WORKSPACE_CFG}")
endif()
# Default values
set(WS_NAME "Unknown")
set(WS_TARGET "demo64k")
set(WS_TIMELINE "timeline.seq")
set(WS_MUSIC "music.track")
set(WS_ASSETS "assets.txt")
set(WS_ASSET_DIRS "")
set(WS_SHADER_DIRS "")
# Read and parse config file
file(STRINGS ${WORKSPACE_CFG} CONFIG_LINES)
foreach(LINE ${CONFIG_LINES})
# Skip comments and empty lines
string(STRIP "${LINE}" LINE)
if(LINE MATCHES "^#" OR LINE STREQUAL "" OR LINE MATCHES "^\\[")
continue()
endif()
# Parse key = value
if(LINE MATCHES "^([^=]+)=(.*)$")
string(STRIP "${CMAKE_MATCH_1}" KEY)
string(STRIP "${CMAKE_MATCH_2}" VALUE)
# Remove quotes
string(REGEX REPLACE "^\"(.*)\"$" "\\1" VALUE "${VALUE}")
# Set variables
if(KEY STREQUAL "name")
set(WS_NAME "${VALUE}")
elseif(KEY STREQUAL "target")
set(WS_TARGET "${VALUE}")
elseif(KEY STREQUAL "timeline")
set(WS_TIMELINE "${VALUE}")
elseif(KEY STREQUAL "music")
set(WS_MUSIC "${VALUE}")
elseif(KEY STREQUAL "assets")
set(WS_ASSETS "${VALUE}")
elseif(KEY STREQUAL "asset_dirs")
# Parse array: ["assets/", "../common/"]
string(REGEX REPLACE "\\[|\\]" "" VALUE "${VALUE}")
string(REPLACE "," ";" VALUE "${VALUE}")
set(WS_ASSET_DIRS "")
foreach(DIR ${VALUE})
string(STRIP "${DIR}" DIR)
string(REGEX REPLACE "^\"(.*)\"$" "\\1" DIR "${DIR}")
list(APPEND WS_ASSET_DIRS "${DIR}")
endforeach()
elseif(KEY STREQUAL "shader_dirs")
# Parse array: ["shaders/", "../common/shaders/"]
string(REGEX REPLACE "\\[|\\]" "" VALUE "${VALUE}")
string(REPLACE "," ";" VALUE "${VALUE}")
set(WS_SHADER_DIRS "")
foreach(DIR ${VALUE})
string(STRIP "${DIR}" DIR)
string(REGEX REPLACE "^\"(.*)\"$" "\\1" DIR "${DIR}")
list(APPEND WS_SHADER_DIRS "${DIR}")
endforeach()
endif()
endif()
endforeach()
# Export to parent scope
set(WORKSPACE_NAME "${WS_NAME}" PARENT_SCOPE)
set(WORKSPACE_TARGET "${WS_TARGET}" PARENT_SCOPE)
set(WORKSPACE_TIMELINE "${WORKSPACE_DIR}/${WS_TIMELINE}" PARENT_SCOPE)
set(WORKSPACE_MUSIC "${WORKSPACE_DIR}/${WS_MUSIC}" PARENT_SCOPE)
set(WORKSPACE_ASSETS "${WORKSPACE_DIR}/${WS_ASSETS}" PARENT_SCOPE)
# Convert relative asset dirs to absolute
set(ABS_ASSET_DIRS "")
foreach(DIR ${WS_ASSET_DIRS})
if(IS_ABSOLUTE "${DIR}")
list(APPEND ABS_ASSET_DIRS "${DIR}")
else()
list(APPEND ABS_ASSET_DIRS "${WORKSPACE_DIR}/${DIR}")
endif()
endforeach()
set(WORKSPACE_ASSET_DIRS "${ABS_ASSET_DIRS}" PARENT_SCOPE)
# Convert relative shader dirs to absolute
set(ABS_SHADER_DIRS "")
foreach(DIR ${WS_SHADER_DIRS})
if(IS_ABSOLUTE "${DIR}")
list(APPEND ABS_SHADER_DIRS "${DIR}")
else()
list(APPEND ABS_SHADER_DIRS "${WORKSPACE_DIR}/${DIR}")
endif()
endforeach()
set(WORKSPACE_SHADER_DIRS "${ABS_SHADER_DIRS}" PARENT_SCOPE)
message(STATUS "Loaded workspace: ${WS_NAME}")
message(STATUS " Timeline: ${WS_TIMELINE}")
message(STATUS " Music: ${WS_MUSIC}")
message(STATUS " Assets: ${WS_ASSETS}")
endfunction()
|