]> git.xonotic.org Git - xonotic/xonotic.git/blob - release.cmake
941282512a7c6655322a26b9a9754e89cb1e3cfe
[xonotic/xonotic.git] / release.cmake
1 # release requirements:
2 # a graphical environment
3 # vorbis-tools: vorbiscomment, oggdec, oggenc
4 # imagemagick: convert
5 # https://github.com/divVerent/s2tc.git: s2tc_compress
6
7 add_custom_target(release)
8
9 string(TIMESTAMP stamp "%Y%m%d")
10
11 file(STRINGS data/xonotic-data.pk3dir/defaultXonotic.cfg _contents REGEX "^gameversion ")
12 if (NOT _contents)
13     message(FATAL_ERROR "defaultXonotic.cfg does not contain gameversion")
14 else ()
15     string(REGEX REPLACE ".*gameversion ([0-9]+).*" "\\1" versionstr "${_contents}")
16     math(EXPR versionstr_major "${versionstr} / 10000")
17     math(EXPR versionstr_minor "${versionstr} / 100 - ${versionstr_major} * 100")
18     math(EXPR versionstr_patch "${versionstr} - ${versionstr_major} * 10000 - ${versionstr_minor} * 100")
19     set(versionstr "${versionstr_major}.${versionstr_minor}.${versionstr_patch}")
20     message("game version: ${versionstr}")
21 endif ()
22
23 # foreach repo: git tag "xonotic-v${versionstr}"
24
25 function(getbinary artifact)
26     find_package(Git REQUIRED)
27     get_filename_component(dpname ${artifact} NAME)
28     string(REGEX REPLACE "^xonotic" "darkplaces" dpname ${dpname})
29     execute_process(
30             COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
31             WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/darkplaces
32             OUTPUT_VARIABLE rev
33             OUTPUT_STRIP_TRAILING_WHITESPACE)
34     message(STATUS "Downloading http://beta.xonotic.org/autobuild-bin/${rev}/${dpname}")
35     file(DOWNLOAD "http://beta.xonotic.org/autobuild-bin/${rev}/${dpname}"
36             "${PROJECT_BINARY_DIR}/${artifact}"
37             SHOW_PROGRESS)
38 endfunction()
39
40 if (0)
41     # TODO: build from source
42     message(STATUS "Downloading NetRadiant")
43
44     file(DOWNLOAD http://www.icculus.org/netradiant/files/netradiant-1.5.0-20120301.tar.bz2
45             "${PROJECT_BINARY_DIR}/netradiant-1.5.0-20120301.tar.bz2"
46             SHOW_PROGRESS
47             EXPECTED_HASH SHA256=5e720cd8ebd2379ee5d388dfb8f2613bfd5798fb33d16bc7415d44a11fb4eadb)
48
49     file(DOWNLOAD http://www.icculus.org/netradiant/files/netradiant-1.5.0-20120301-win32-7z.exe
50             "${PROJECT_BINARY_DIR}/netradiant-1.5.0-20120301-win32-7z.exe"
51             SHOW_PROGRESS
52             EXPECTED_HASH SHA256=c4bb30b6f14c3f71f1ed29fa38cddac209a7bc2ab5b38e5bf5b442106279b5c4)
53 endif ()
54
55 if (0)
56     # TODO: build from source
57     message(STATUS "Downloading Darkplaces")
58
59     getbinary(Xonotic/xonotic-x86.exe)
60     getbinary(Xonotic/xonotic-x86-wgl.exe)
61     getbinary(Xonotic/xonotic-x86-dedicated.exe)
62     getbinary(Xonotic/xonotic.exe)
63     getbinary(Xonotic/xonotic-wgl.exe)
64     getbinary(Xonotic/xonotic-dedicated.exe)
65
66     getbinary(Xonotic/Xonotic.app/Contents/MacOS/xonotic-osx-sdl-bin) # +x
67     getbinary(Xonotic/xonotic-osx-dedicated) # +x
68
69     getbinary(Xonotic/xonotic-linux32-sdl) # +x
70     getbinary(Xonotic/xonotic-linux32-glx) # +x
71     getbinary(Xonotic/xonotic-linux32-dedicated) # +x
72
73     getbinary(Xonotic/xonotic-linux64-sdl) # +x
74     getbinary(Xonotic/xonotic-linux64-glx) # +x
75     getbinary(Xonotic/xonotic-linux64-dedicated) # +x
76 endif ()
77
78 function(buildpk3s src)
79     set(dir data/${src})
80     string(REGEX REPLACE "\\.pk3dir$" "" name ${src})
81     if (name MATCHES "^xonotic-")
82         string(REGEX REPLACE "^xonotic-" "xonotic-${stamp}-" name ${name})
83     else ()
84         set(name "${name}-${stamp}")
85     endif ()
86     file(GLOB_RECURSE files RELATIVE "${PROJECT_SOURCE_DIR}/${dir}" "${dir}/*")
87     string(REGEX REPLACE "\\.git/[^;]+;?" "" files "${files}")
88     #    string(REGEX REPLACE "[^;]+(qh|inc|txt|cfg|sh|po|pl|yml|cmake);?" "" files "${files}")
89     foreach (pair ${ARGN})
90         list(GET pair 0 filter)
91         list(GET pair 1 flavor)
92         buildpk3(${name}${flavor}.pk3)
93     endforeach ()
94 endfunction()
95
96 function(buildpk3 pk3)
97     message("registered pk3 ${pk3}")
98     set(deps)
99     foreach (file IN LISTS files)
100         get_filename_component(rel ${file} DIRECTORY)
101         set(marker "done.data/${pk3}/${file}")
102         string(REPLACE "#" "_" marker ${marker})  # OUTPUT cannot contain '#'
103         add_custom_command(OUTPUT ${marker}
104                 COMMAND ${CMAKE_COMMAND}
105                 "-Dsrc=${PROJECT_SOURCE_DIR}/${dir}/${file}"
106                 "-Ddst=data/${pk3}/${rel}"
107                 "-Dconv=data/${pk3}/${file}"
108                 -P "transform-${filter}.cmake"
109                 VERBATIM)
110         list(APPEND deps ${marker})
111     endforeach ()
112     add_custom_target(${pk3} DEPENDS ${deps})
113     add_custom_target(${pk3}-zip DEPENDS ${pk3}.zip)
114     add_dependencies(release ${pk3}-zip)
115     add_custom_command(OUTPUT ${pk3}.zip
116             DEPENDS ${pk3}
117             COMMAND ${CMAKE_COMMAND} -E tar "cfv" "../../${pk3}.zip" --format=zip *
118             WORKING_DIRECTORY "data/${pk3}")
119 endfunction()
120
121 function(deftransform name)
122     file(WRITE ${PROJECT_BINARY_DIR}/transform-${name}.cmake "")
123     set(pairs "${ARGN}")
124     list(APPEND pairs "del_src\;true")
125     foreach (pair IN LISTS pairs)
126         list(GET pair 0 k)
127         list(GET pair 1 v)
128         file(APPEND ${PROJECT_BINARY_DIR}/transform-${name}.cmake "set(ENV{${k}} \"${v}\")\n")
129     endforeach ()
130     file(APPEND ${PROJECT_BINARY_DIR}/transform-${name}.cmake
131             "execute_process(\n"
132             "        COMMAND ${CMAKE_COMMAND} -E copy \${src} \${conv}\n"
133             "        COMMAND ${PROJECT_SOURCE_DIR}/misc/tools/cached-converter.sh \${conv}\n"
134             "        COMMAND ${CMAKE_COMMAND} -E make_directory done.\${conv}\n"
135             "        RESULT_VARIABLE res_var\n"
136             ")")
137 endfunction()
138 file(WRITE ${PROJECT_BINARY_DIR}/transform-raw.cmake
139         "execute_process(\n"
140         "        COMMAND ${CMAKE_COMMAND} -E copy \${src} \${conv}\n"
141         "        COMMAND ${CMAKE_COMMAND} -E make_directory done.\${conv}\n"
142         ")")
143
144 # default to "del_src\;true"
145 deftransform(normal
146         # texture: convert to jpeg and dds
147         "do_jpeg\;true"
148         "jpeg_qual_rgb\;97"
149         "jpeg_qual_a\;99"
150         "do_dds\;false"
151         "do_ogg\;true"
152         "ogg_ogg\;false")
153 deftransform(normaldds
154         # texture: convert to jpeg and dds
155         # music: reduce bitrate
156         "do_jpeg\;false"
157         "do_jpeg_if_not_dds\;true"
158         "jpeg_qual_rgb\;95"
159         "jpeg_qual_a\;99"
160         "do_dds\;true"
161         "dds_flags\;"
162         "do_ogg\;true"
163         "ogg_ogg\;false")
164 deftransform(low
165         # texture: convert to jpeg and dds
166         # music: reduce bitrate
167         "do_jpeg\;true"
168         "jpeg_qual_rgb\;80"
169         "jpeg_qual_a\;97"
170         "do_dds\;false"
171         "do_ogg\;true"
172         "ogg_qual\;1")
173 deftransform(webp
174         # texture: convert to jpeg and dds
175         "do_jpeg\;false"
176         "do_webp\;true"
177         "do_dds\;false"
178         "do_ogg\;false"
179         "ogg_ogg\;false")
180 deftransform(lowdds
181         # texture: convert to jpeg and dds
182         # music: reduce bitrate
183         "do_jpeg\;false"
184         "do_jpeg_if_not_dds\;true"
185         "jpeg_qual_rgb\;80"
186         "jpeg_qual_a\;99"
187         "do_dds\;true"
188         "dds_flags\;"
189         "do_ogg\;true"
190         "ogg_qual\;1")
191 deftransform(mapping
192         # texture: convert to jpeg and dds
193         # music: reduce bitrate
194         "do_jpeg\;true"
195         "jpeg_qual_rgb\;80"
196         "jpeg_qual_a\;97"
197         "do_dds\;false"
198         "do_ogg\;true"
199         "ogg_qual\;1"
200         )
201
202 ## remove stuff radiant has no use for
203 #verbose find . -name \*_norm.\* -exec rm -f {} \;
204 #verbose find . -name \*_bump.\* -exec rm -f {} \;
205 #verbose find . -name \*_glow.\* -exec rm -f {} \;
206 #verbose find . -name \*_gloss.\* -exec rm -f {} \;
207 #verbose find . -name \*_pants.\* -exec rm -f {} \;
208 #verbose find . -name \*_shirt.\* -exec rm -f {} \;
209 #verbose find . -name \*_reflect.\* -exec rm -f {} \;
210 #verbose find . -not \( -name \*.tga -o -name \*.png -o -name \*.jpg \) -exec rm -f {} \;
211
212 buildpk3s(font-unifont.pk3dir "raw\;")
213 buildpk3s(font-xolonium.pk3dir "raw\;")
214 buildpk3s(xonotic-data.pk3dir "low\;-low" "normaldds\;" "normal\;-high")
215 buildpk3s(xonotic-maps.pk3dir "low\;-low" "normaldds\;" "normal\;-high" "mapping\;-mapping")
216 buildpk3s(xonotic-music.pk3dir "raw\;" "low\;-low")
217 buildpk3s(xonotic-nexcompat.pk3dir "normaldds\;")
218
219 message("CMake may appear to halt at '-- Configuring done', this is not the case")