-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
149 lines (117 loc) · 4.97 KB
/
CMakeLists.txt
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
cmake_minimum_required(VERSION 3.22)
project(ComponentExplorer
VERSION 1.58.5
HOMEPAGE_URL "https://github.com/dextercd/Noita-Component-Explorer"
LANGUAGES
)
set(PROJECT_WIKI "https://noita.wiki.gg/wiki/Mod:Component_Explorer")
set(COMPONENT_EXPLORER_DEV OFF CACHE BOOL "Extra build functionality")
find_package(Python REQUIRED Interpreter)
add_custom_command(
OUTPUT component_explorer_python_packages
DEPENDS ${CMAKE_SOURCE_DIR}/requirements.txt
VERBATIM
COMMAND Python::Interpreter -m pip install -r ${CMAKE_SOURCE_DIR}/requirements.txt
COMMAND ${CMAKE_COMMAND} -E touch component_explorer_python_packages
)
add_custom_target(install_component_explorer_python_packages
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/component_explorer_python_packages
)
function(render_jinja_template)
set(options)
set(one_value_args OUTPUT TEMPLATE)
set(multi_value_args JSON)
cmake_parse_arguments(RJINJA "${options}" "${one_value_args}" "${multi_value_args}" ${ARGN})
set(COMMAND_LIST
${CMAKE_COMMAND} -E env
"VERSION=${PROJECT_VERSION}"
"HOMEPAGE=${PROJECT_HOMEPAGE_URL}"
"WIKI=${PROJECT_WIKI}" --
${Python_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/codegen/gen.py" --output ${RJINJA_OUTPUT}
)
# Aliases are in the form of <path>@<alias>
# To setup dependencies properly we collect the paths in here
set(JSON_PATHS)
foreach(JSON IN LISTS RJINJA_JSON)
list(APPEND COMMAND_LIST --json ${JSON})
if (JSON MATCHES "(.*)@")
list(APPEND JSON_PATHS ${CMAKE_MATCH_1})
else()
list(APPEND JSON_PATHS ${JSON})
endif()
endforeach()
cmake_path(ABSOLUTE_PATH RJINJA_TEMPLATE BASE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
add_custom_command(
OUTPUT "${RJINJA_OUTPUT}"
DEPENDS install_component_explorer_python_packages
"${CMAKE_CURRENT_SOURCE_DIR}/codegen/gen.py"
${JSON_PATHS} ${RJINJA_TEMPLATE}
VERBATIM
COMMAND ${COMMAND_LIST} ${RJINJA_TEMPLATE}
)
message(STATUS ${COMMAND_LIST} ${RJINJA_TEMPLATE})
endfunction()
if (COMPONENT_EXPLORER_DEV)
find_path(NOITA_INSTALL_DIR
NAMES noita.exe
PATHS
"C:/Program Files (x86)/Steam/steamapps/common/Noita"
"$ENV{HOME}/.steam/steam/steamapps/common/Noita"
)
set(NOITA_COMPONENT_DOC ${NOITA_INSTALL_DIR}/tools_modding/component_documentation.txt)
foreach(FILE_VERSION main beta)
add_custom_target(update_${FILE_VERSION}_repo_components_file
DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/component_parser/parse.py
${NOITA_COMPONENT_DOC}
VERBATIM
COMMAND Python::Interpreter ${CMAKE_CURRENT_SOURCE_DIR}/component_parser/parse.py
--output ${CMAKE_CURRENT_SOURCE_DIR}/data/component_${FILE_VERSION}_documentation.json
${NOITA_COMPONENT_DOC}
)
endforeach()
endif()
foreach(FILE_VERSION main beta)
render_jinja_template(OUTPUT components_${FILE_VERSION}.lua
TEMPLATE components.lua
JSON
${CMAKE_CURRENT_SOURCE_DIR}/data/component_${FILE_VERSION}_documentation.json@component_documentation
${CMAKE_CURRENT_SOURCE_DIR}/data/field_infos.json
)
render_jinja_template(OUTPUT serialise_component_${FILE_VERSION}.lua
TEMPLATE serialise_component.lua
JSON ${CMAKE_CURRENT_SOURCE_DIR}/data/component_${FILE_VERSION}_documentation.json@component_documentation
)
render_jinja_template(OUTPUT configs_${FILE_VERSION}.lua
TEMPLATE configs.lua
JSON
${CMAKE_CURRENT_SOURCE_DIR}/data/configs_${FILE_VERSION}.json@configs
)
add_custom_target(components_${FILE_VERSION}_lua ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/components_${FILE_VERSION}.lua)
add_custom_target(serialise_component_${FILE_VERSION}_lua ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/serialise_component_${FILE_VERSION}.lua)
add_custom_target(configs_${FILE_VERSION}_lua ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/configs_${FILE_VERSION}.lua)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/serialise_component_${FILE_VERSION}.lua
${CMAKE_CURRENT_BINARY_DIR}/components_${FILE_VERSION}.lua
${CMAKE_CURRENT_BINARY_DIR}/configs_${FILE_VERSION}.lua
DESTINATION "component-explorer"
COMPONENT ComponentExplorer
)
endforeach()
render_jinja_template(OUTPUT version.lua
TEMPLATE version.lua
)
add_custom_target(version_lua ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/version.lua)
configure_file(mod.xml.in mod.xml @ONLY)
# Installing
install(DIRECTORY component-explorer DESTINATION "." COMPONENT ComponentExplorer)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/version.lua
${CMAKE_CURRENT_BINARY_DIR}/mod.xml
DESTINATION "component-explorer"
COMPONENT ComponentExplorer
)
install(DIRECTORY unsafe-explorer DESTINATION "." COMPONENT ComponentExplorer-Unsafe)
include(packaging/CMakeLists.txt)