]> git.xonotic.org Git - xonotic/xonotic.git/blob - release.cmake
Makefile: avoid redundant script executions in d0_blind_id
[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/xonotic-common.cfg _contents REGEX "^gameversion ")
13 if (NOT _contents)
14     message(FATAL_ERROR "xonotic-common.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-dedicated.exe)
62     getbinary(Xonotic/xonotic.exe)
63     getbinary(Xonotic/xonotic-dedicated.exe)
64
65     getbinary(Xonotic/Xonotic.app/Contents/MacOS/xonotic-osx-sdl-bin) # +x
66     getbinary(Xonotic/xonotic-osx-dedicated) # +x
67
68     getbinary(Xonotic/xonotic-linux64-sdl) # +x
69     getbinary(Xonotic/xonotic-linux64-glx) # +x
70     getbinary(Xonotic/xonotic-linux64-dedicated) # +x
71 endif ()
72
73 function(buildpk3s src)
74     set(dir data/${src})
75     string(REGEX REPLACE "\\.pk3dir$" "" name ${src})
76     if (name MATCHES "^xonotic-")
77         string(REGEX REPLACE "^xonotic-" "xonotic-${stamp}-" name ${name})
78     else ()
79         set(name "${name}-${stamp}")
80     endif ()
81     file(GLOB_RECURSE files RELATIVE "${PROJECT_SOURCE_DIR}/${dir}" "${dir}/*")
82     string(REGEX REPLACE "\\.git/[^;]+;?" "" files "${files}")
83     #    string(REGEX REPLACE "[^;]+(qh|inc|txt|cfg|sh|po|pl|yml|cmake);?" "" files "${files}")
84     foreach (pair ${ARGN})
85         list(GET pair 0 filter)
86         list(GET pair 1 flavor)
87         buildpk3(${name}${flavor}.pk3)
88     endforeach ()
89 endfunction()
90
91 function(buildpk3 pk3)
92     message("registered pk3 ${pk3}")
93     set(deps)
94     foreach (file IN LISTS files)
95         set(marker "done.data/${pk3}dir/${file}")
96         string(REPLACE "#" "_" marker ${marker})  # OUTPUT cannot contain '#'
97         list(APPEND deps "${marker}")
98         get_filename_component(rel ${file} DIRECTORY)
99         add_custom_command(OUTPUT ${marker}
100                 DEPENDS "${dir}/${file}"
101                 COMMAND ${CMAKE_COMMAND}
102                 "-Dsrc=${PROJECT_SOURCE_DIR}/${dir}/${file}"
103                 "-Ddst=data/${pk3}dir/${rel}"
104                 "-Dconv=data/${pk3}dir/${file}"
105                 -P "transform-${filter}.cmake"
106                 VERBATIM)
107     endforeach ()
108     add_custom_target(${pk3}dir DEPENDS ${deps})
109     add_custom_target(${pk3}dir-zip DEPENDS ${pk3})
110     add_dependencies(release ${pk3}dir-zip)
111     add_custom_command(OUTPUT ${pk3}
112             DEPENDS ${pk3}dir
113             COMMAND ${CMAKE_COMMAND} -E tar cvf "../../${pk3}" --mtime=${filestamp} --format=zip -- *  # TODO: no wildcard
114             WORKING_DIRECTORY "data/${pk3}dir")
115 endfunction()
116
117 function(deftransform name)
118     file(WRITE ${PROJECT_BINARY_DIR}/transform-${name}.cmake "")
119     set(pairs "${ARGN}")
120     list(APPEND pairs "del_src\;true")
121     foreach (pair IN LISTS pairs)
122         list(GET pair 0 k)
123         list(GET pair 1 v)
124         file(APPEND ${PROJECT_BINARY_DIR}/transform-${name}.cmake "set(ENV{${k}} \"${v}\")\n")
125     endforeach ()
126     file(APPEND ${PROJECT_BINARY_DIR}/transform-${name}.cmake
127             "execute_process(\n"
128             "        COMMAND ${CMAKE_COMMAND} -E copy \${src} \${conv}\n"
129             "        COMMAND ${PROJECT_SOURCE_DIR}/misc/tools/cached-converter.sh \${conv}\n"
130             "        COMMAND ${CMAKE_COMMAND} -E make_directory done.\${conv}\n"
131             "        COMMAND ${CMAKE_COMMAND} -E touch done.\${conv}\n"
132             "        RESULT_VARIABLE res_var\n"
133             ")")
134 endfunction()
135 file(WRITE ${PROJECT_BINARY_DIR}/transform-raw.cmake
136         "execute_process(\n"
137         "        COMMAND ${CMAKE_COMMAND} -E copy \${src} \${conv}\n"
138         "        COMMAND ${CMAKE_COMMAND} -E make_directory done.\${conv}\n"
139         "        COMMAND ${CMAKE_COMMAND} -E touch done.\${conv}\n"
140         ")")
141
142 # default to "del_src\;true"
143 deftransform(normal
144         # texture: convert to jpeg and dds
145         "do_jpeg\;true"
146         "jpeg_qual_rgb\;97"
147         "jpeg_qual_a\;99"
148         "do_dds\;false"
149         "do_ogg\;true"
150         "ogg_ogg\;false")
151 deftransform(normaldds
152         # texture: convert to jpeg and dds
153         # music: reduce bitrate
154         "do_jpeg\;false"
155         "do_jpeg_if_not_dds\;true"
156         "jpeg_qual_rgb\;95"
157         "jpeg_qual_a\;99"
158         "do_dds\;true"
159         "dds_flags\;"
160         "do_ogg\;true"
161         "ogg_ogg\;false")
162 deftransform(low
163         # texture: convert to jpeg and dds
164         # music: reduce bitrate
165         "do_jpeg\;true"
166         "jpeg_qual_rgb\;80"
167         "jpeg_qual_a\;97"
168         "do_dds\;false"
169         "do_ogg\;true"
170         "ogg_qual\;1")
171 deftransform(webp
172         # texture: convert to jpeg and dds
173         "do_jpeg\;false"
174         "do_webp\;true"
175         "do_dds\;false"
176         "do_ogg\;false"
177         "ogg_ogg\;false")
178 deftransform(lowdds
179         # texture: convert to jpeg and dds
180         # music: reduce bitrate
181         "do_jpeg\;false"
182         "do_jpeg_if_not_dds\;true"
183         "jpeg_qual_rgb\;80"
184         "jpeg_qual_a\;99"
185         "do_dds\;true"
186         "dds_flags\;"
187         "do_ogg\;true"
188         "ogg_qual\;1")
189 deftransform(mapping
190         # texture: convert to jpeg and dds
191         # music: reduce bitrate
192         "do_jpeg\;true"
193         "jpeg_qual_rgb\;80"
194         "jpeg_qual_a\;97"
195         "do_dds\;false"
196         "do_ogg\;true"
197         "ogg_qual\;1"
198         )
199
200 ## remove stuff radiant has no use for
201 #verbose find . -name \*_norm.\* -exec rm -f {} \;
202 #verbose find . -name \*_bump.\* -exec rm -f {} \;
203 #verbose find . -name \*_glow.\* -exec rm -f {} \;
204 #verbose find . -name \*_gloss.\* -exec rm -f {} \;
205 #verbose find . -name \*_pants.\* -exec rm -f {} \;
206 #verbose find . -name \*_shirt.\* -exec rm -f {} \;
207 #verbose find . -name \*_reflect.\* -exec rm -f {} \;
208 #verbose find . -not \( -name \*.tga -o -name \*.png -o -name \*.jpg \) -exec rm -f {} \;
209
210 buildpk3s(font-unifont.pk3dir "raw\;")
211 buildpk3s(font-xolonium.pk3dir "raw\;")
212 buildpk3s(xonotic-data.pk3dir "low\;-low" "normaldds\;" "normal\;-high")
213 buildpk3s(xonotic-maps.pk3dir "low\;-low" "normaldds\;" "normal\;-high" "mapping\;-mapping")
214 buildpk3s(xonotic-music.pk3dir "raw\;" "low\;-low")
215 buildpk3s(xonotic-nexcompat.pk3dir "normaldds\;")
216
217 message("CMake may appear to halt at '-- Configuring done', this is not the case")