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