File: make.py

package info (click to toggle)
nomacs 3.21.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 17,560 kB
  • sloc: cpp: 49,511; python: 718; sh: 241; xml: 175; makefile: 22
file content (402 lines) | stat: -rw-r--r-- 11,509 bytes parent folder | download
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
# Change following line to force rebuild of AppVeyor cache:
# Last rebuild: 2025-05-09

import os
from utils.config import Config

class NomacsConfig(Config):

    def __init__(self, params):
        super().__init__(params, "nomacs")

    def defaults(self):

        if not self.libpath:
            self.libpath = self.repopath + "/3rd-party/build"

        if "srcpath" not in self.__dict__ or not self.srcpath:
            self.srcpath = self.repopath + "/ImageLounge"

        # this is not called 'path' because it won't exist until we call cmake
        if "builddir" not in self.__dict__ or not self.builddir:
            self.builddir = self.repopath + "/build"

        super().defaults()

    def cmake_args(self):

        # tune cmake parameters here
        args = [
            "-DQT_VERSION_MAJOR=6",
            "-DCMAKE_PREFIX_PATH=" + self.qtpath,
            "-DDEPENDENCY_PATH=" + self.libpath,
            "-DENABLE_QUAZIP=ON",
            "-DENABLE_TRANSLATIONS=ON",
            "-DENABLE_HEIF=ON",
            "-DENABLE_AVIF=ON",
            "-DENABLE_JXL=ON",
            "-DENABLE_JXR=ON",
            "-DENABLE_INCREMENTER=OFF",
            "-B" + self.builddir,
            self.srcpath
        ]

        return args


class ExpatConfig(Config):

    def __init__(self, params):
        super().__init__(params, "expat")

        self.install = False

    def defaults(self):

        # this is not called 'path' because it won't exist until we call cmake
        if "builddir" not in self.__dict__ or not self.builddir:
            self.builddir = os.path.join(self.repopath, "build", self.name)

        super().defaults()

        self.binaryfile = os.path.join(self.builddir, "Release", "libexpat.dll")

    def cmake_args(self):

        # tune cmake parameters here
        args = [
            "-DBUILD_examples=OFF",
            "-DBUILD_tests=OFF",
            "-B" + self.builddir,
            self.srcpath + "/expat"
        ]

        return args


class ExifConfig(Config):

    def __init__(self, params):
        super().__init__(params, "exiv2")

        self.install = False

    def defaults(self):

        if "libpath" not in self.__dict__ or not self.libpath:
            self.libpath = os.path.join(self.repopath, "build")

        # this is not called 'path' because it won't exist until we call cmake
        if "builddir" not in self.__dict__ or not self.builddir:
            self.builddir = os.path.join(self.repopath, "build", self.name)

        super().defaults()

        self.binaryfile = os.path.join(
            self.builddir, "Release", "bin", "exiv2.dll")

    def cmake_args(self):

        # tune cmake parameters here
        args = self.additional_cmake_args + [
            "-DEXPAT_BUILD_PATH=" + self.libpath + "/expat",
            "-DEXPAT_INCLUDE_DIR=" + self.repopath + "/expat/expat/lib",
            "-DEXIV2_ENABLE_BMFF=ON",
            "-DEXIV2_ENABLE_BROTLI=OFF",
            "-DEXIV2_ENABLE_INIH=OFF",
            "-DEXIV2_BUILD_EXIV2_COMMAND=OFF",
            "-DEXIV2_BUILD_SAMPLES=OFF",
            "-B" + self.builddir,
            self.srcpath
        ]

        return args


class LibrawConfig(Config):

    def __init__(self, params):
        super().__init__(params, "libraw")

        self.install = False

    def defaults(self):

        # this is not called 'path' because it won't exist until we call cmake
        if "builddir" not in self.__dict__ or not self.builddir:
            self.builddir = os.path.join(self.repopath, "build", self.name)

        super().defaults()

        self.binaryfile = os.path.join(self.builddir, "Release", "raw.dll")

    def cmake_args(self):

        # tune cmake parameters here
        args = self.additional_cmake_args + [
            "-DENABLE_EXAMPLES=OFF",
            "-B" + self.builddir,
            self.srcpath
        ]

        return args


class QuazipConfig(Config):

    def __init__(self, params):
        super().__init__(params, "quazip")

        self.install = False

    def defaults(self):

        # this is not called 'path' because it won't exist until we call cmake
        if "builddir" not in self.__dict__ or not self.builddir:
            self.builddir = os.path.join(self.repopath, "build", self.name)

        if "libpath" not in self.__dict__ or not self.libpath:
            self.libpath = os.path.join(self.repopath, "build")

        super().defaults()

        self.binaryfile = os.path.join(self.builddir, "quazip", "Release", "quazip1-qt6.dll")

    def cmake_args(self):

        # tune cmake parameters here
        args = self.additional_cmake_args + [
            "-DCMAKE_PREFIX_PATH=" + self.qtpath,
            "-B" + self.builddir,
            "-DQUAZIP_BZIP2=OFF",
            "-DQUAZIP_BZIP2_STDIO=OFF",
            "-DQUAZIP_QT_MAJOR_VERSION=6",
            self.srcpath
        ]

        return args

    def cmake_build_args(self):

        # only build shared lib
        args = [
            "--target QuaZip"
        ]

        return args

class OpenCVConfig(Config):

    def __init__(self, params):
        super().__init__(params, "opencv")

        self.install = False

    def defaults(self):

        if "srcpath" not in self.__dict__ or not self.srcpath:
            self.srcpath = os.path.join(self.repopath, self.name)

        # this is not called 'path' because it won't exist until we call cmake
        if "builddir" not in self.__dict__ or not self.builddir:
            self.builddir = os.path.join(self.repopath, "build", self.name)

        super().defaults()

        # FIXME: release is generated by cmake - so this is not enough to ask for...
        self.binaryfile = os.path.join(
            self.builddir, "bin", "Release", "opencv_core4110.dll")

    def cmake_zlib(self):

        args = [
            "-DZLIB_INCLUDE_DIR=" + self.srcpath + "/3rdparty/zlib",
            "-DZLIB_BUILD_PATH=" + self.builddir + "/3rdparty",
            "-DZLIB_LIBRARY_RELEASE=" + self.builddir + "/3rdparty/lib/Release/zlib.lib",
        ]

        return args

    def cmake_args(self):

        # tune cmake parameters here
        args = [
            "-DBUILD_PERF_TESTS=OFF",
            "-DBUILD_TESTS=OFF",
            "-DBUILD_opencv_java=OFF",
            "-DBUILD_opencv_java_bindings_generator=OFF",
            "-DBUILD_opencv_python=OFF",
            "-DBUILD_opencv_apps=OFF",
            "-DBUILD_opencv_dnn=OFF",
            "-DBUILD_opencv_calib3d=OFF",
            "-DBUILD_opencv_highgui=OFF",
            "-DBUILD_opencv_photo=OFF",
            "-DBUILD_opencv_python2=OFF",
            "-DBUILD_opencv_python3=OFF",
            "-DBUILD_opencv_python_tests=OFF",
            "-DBUILD_opencv_python_bindings_generator=OFF",
            "-DBUILD_opencv_stitiching=OFF",
            "-DBUILD_opencv_video=OFF",
            "-DBUILD_opencv_videoio=OFF",
            "-B" + self.builddir,
            self.srcpath
        ]

        return args


class FormatsConfig(Config):

    def __init__(self, params, name: str):
        super().__init__(params, name)

    def defaults(self):

        if "libpath" not in self.__dict__ or not self.libpath:
            self.libpath = os.path.join(self.repopath, "build")

        # only build release for imageformats        
        self.buildconfig = "release"

        super().defaults()



    def cmake_args(self):

        # tune cmake parameters here
        args = [
            "-DQT_VERSION_MAJOR=6",
            "-DCMAKE_PREFIX_PATH=" +
            # os.path.join(self.libpath, "libde265") + ";" +
            # os.path.join(self.libpath, "libheif") + ";" +
            self.qtpath,
            "-DENABLE_QOI=ON",
            "-DENABLE_WEBP=OFF",
            "-DENABLE_DDS=ON",
            "-B" + self.builddir,
            self.srcpath
        ]

        return args


def make_libs(params):
    from utils.build import build

    params['install'] = False

    opencv = OpenCVConfig(params)
    # some script debugging options:
    # opencv.force = True
    print(opencv)
    build(opencv)

    # Exiv2
    expat = ExpatConfig(params)
    build(expat)

    exiv2 = ExifConfig(params)
    exiv2.additional_cmake_args = opencv.cmake_zlib()
    build(exiv2)

    # libraw
    libraw = LibrawConfig(params)
    build(libraw)

    # quazip
    quazip = QuazipConfig(params)
    quazip.additional_cmake_args = opencv.cmake_zlib()
    build(quazip)

    # uncomment for debugging
    # print(expat)

def make_imageformats(params):
    
    params['install'] = False

    # config libde265 which we need for libheif
    # libde265 = FormatsConfig(params, "libde265")
    # libde265.builddir = os.path.join(libde265.builddir, libde265.name)
    # libde265.binaryfile = os.path.join(libde265.builddir, libde265.name, "Release", libde265.name + ".dll")
    # build(libde265)
    
    # config libheif
    # libheif = FormatsConfig(params, "libheif")
    # libheif.builddir = os.path.join(libheif.builddir, libheif.name)
    # libheif.binaryfile = os.path.join(libheif.builddir, "libheif", "Release", "heif.dll")
    # build(libheif)
    
    # configure image formats
    params["srcpath"] = params["repopath"]
    params['install'] = True
    imageformats = FormatsConfig(params, "imageformats")
    build(imageformats)

    # uncomment for debugging
    # print(libde265)
    # print(libheif)
    # print(imageformats)

def configure_libs(p, config):
    # from makelibs import make as ml
    # from makeimageformats import make as mi

    p['repopath'] = config.repopath + "/3rd-party"

    make_libs(p)

    p['libpath']  = config.libpath + "/imageformats"
    p['repopath'] = config.repopath + "/3rd-party/imageformats"
    p['builddir'] = config.repopath + "/3rd-party/build/imageformats"

    make_imageformats(p)


if __name__ == "__main__":
    import argparse
    import sys
    
    from utils.fun import repopath
    from utils.build import build

    parser = argparse.ArgumentParser(
        description='packs nomacs portable.')

    parser.add_argument("qtpath", type=str,
                        help="""path to your Qt folder""")
    parser.add_argument('--lib-path', dest='libpath', type=str, default="",
                        help='additional cmake arguments')
    parser.add_argument('--repo-path', dest='repopath', type=str, default="",
                        help='path to the nomacs repository')
    parser.add_argument('--build-dir', dest='builddir', type=str, default="",
                        help='Specify the build directory')
    parser.add_argument('--build-config', dest='buildconfig', type=str, default="",
                        help='build configuration [debug|release]')
    parser.add_argument('--project', dest='project', type=str, default="all",
                        help='comma separated name of the project(s) to be built (i.e. project=opencv,expat)')
    parser.add_argument('--force', action='store_true',
                    help='forces building the project')
    parser.add_argument('--configure', action='store_true',
                        help='if set, projects are only configured rather than built')


    # make args a dict
    params = vars(parser.parse_args())

    # get the repository path
    if not params['repopath']:
        params['repopath'] = repopath(sys.argv[0])

    params['project'] = params['project'].split(',')

    c = NomacsConfig(params)

    if not params['libpath']:
        configure_libs(params, c)

    # uncomment for debugging
    print(c)

    build(c)