44import os
55import config
66
7- def make_x265 (src_dir , lib_dir , build_type ):
8- if not base .is_dir ("x265_git" ):
9- base .cmd ("git" , ["clone" , "https://bitbucket.org/multicoreware/x265_git.git" ])
10- cmake_dir = src_dir + "/x265_git/build"
7+ def make_x265 (base_dir , build_type ):
8+ # clones repo
9+ def fetch (version_major , version_minor ):
10+ branch_name = f"Release_{ version_major } .{ version_minor } "
11+ base .cmd ("git" , ["clone" , "--depth" , "1" , "--branch" , branch_name , "https://bitbucket.org/multicoreware/x265_git.git" ])
12+
13+ # gets build directory
14+ def get_build_dir (platform ):
15+ return os .path .join (base_dir , "build" , platform , build_type , "x265" )
16+
17+ # set versions here
18+ x265_major = "4"
19+ x265_minor = "1"
20+ if not base .is_dir ("x265_git" ):
21+ fetch (x265_major , x265_minor )
22+
23+ cmake_dir = base_dir + "/x265_git/build"
24+ cmake_args = [
25+ "../../source" ,
26+ "-DCMAKE_BUILD_TYPE=" + build_type ,
27+ "-DENABLE_CLI=OFF" , # do not build standalone CLI app
28+ "-DENABLE_SHARED=OFF" # do not build shared libs
29+ ]
30+
31+ # if "windows" == base.host_platform():
32+ # # TODO: separate win32 and win64 builds
33+ # cmake_args.extend(["-G", "Visual Studio 16 2019", "-A", "x64"])
34+ # base.cmd("cmake", cmake_args)
35+ # base.cmd("cmake", ["--build", ".", "--config", build_type])
36+ # base.copy_files(cmake_dir + "/" + build_type + "/*.lib", lib_dir)
37+
38+ # if "linux" == base.host_platform():
39+ # cmake_args.extend(["-G", "Unix Makefiles", "-DCMAKE_POSITION_INDEPENDENT_CODE=ON"])
40+ # base.cmd("cmake", cmake_args)
41+ # base.cmd("make", ["-j4"])
42+ # base.copy_files(cmake_dir + "/*.a", lib_dir)
43+
44+ if "mac" == base .host_platform ():
45+ # change directory
46+ cmake_dir += "/linux"
1147 os .chdir (cmake_dir )
12-
13- cmake_args = [
14- "-DCMAKE_BUILD_TYPE=" + build_type , "-DBUILD_SHARED_LIBS=OFF" ,
15- "-DENABLE_SHARED=OFF" , "../source"
16- ]
17-
18- if "windows" == base .host_platform ():
19- cmake_args .extend (["-G" , "Visual Studio 16 2019" , "-A" , "x64" ])
20- base .cmd ("cmake" , cmake_args )
21- base .cmd ("cmake" , ["--build" , "." , "--config" , build_type ])
22- base .copy_files (cmake_dir + "/" + build_type + "/*.lib" , lib_dir )
23-
24- if "linux" == base .host_platform ():
25- cmake_args .extend (["-G" , "Unix Makefiles" , "-DCMAKE_POSITION_INDEPENDENT_CODE=ON" ])
26- base .cmd ("cmake" , cmake_args )
27- base .cmd ("make" , ["-j$(nproc)" ])
28- base .copy_files (cmake_dir + "/*.a" , lib_dir )
29-
30- base .copy_files (cmake_dir + "/*.h" , src_dir + "/x265_git/source" )
31- os .chdir (src_dir )
32-
33- return
48+ # extend cmake args
49+ cmake_args += ["-G" , "Unix Makefiles" ]
50+
51+ # mac_64
52+ if config .check_option ("platform" , "mac_64" ) and not base .is_dir (get_build_dir ("mac_64" )):
53+ build_dir = get_build_dir ("mac_64" )
54+ base .create_dir (build_dir )
55+ if base .is_os_arm ():
56+ # disable assembly optimizations for cross-arch build
57+ cmake_args += ["-DENABLE_ASSEMBLY=OFF" ]
58+ base .cmd ("cmake" , cmake_args )
59+ base .cmd ("make" , ["-j4" ])
60+ base .copy_files ("*.a" , build_dir )
61+ base .create_dir (build_dir + "/include" )
62+ base .copy_file (base_dir + "/x265_git/source/x265.h" , build_dir + "/include" )
63+
64+ # mac_arm64
65+ if config .check_option ("platform" , "mac_arm64" ) and not base .is_dir (get_build_dir ("mac_arm64" )):
66+ build_dir = get_build_dir ("mac_arm64" )
67+ base .create_dir (build_dir )
68+ base .cmd ("cmake" , cmake_args )
69+ base .cmd ("make" , ["-j4" ])
70+ base .copy_files ("*.a" , build_dir )
71+ base .create_dir (build_dir + "/include" )
72+ base .copy_file (base_dir + "/x265_git/source/x265.h" , build_dir + "/include" )
73+
74+ os .chdir (base_dir )
75+ return
3476
3577def make_de265 (src_dir , lib_dir , build_type ):
36- if not base .is_dir ("libde265" ):
37- base .cmd ("git" , ["clone" , "https://github.com/strukturag/libde265.git" ])
38- cmake_dir = src_dir + "/libde265"
39- os .chdir (cmake_dir )
40-
41- cmake_args = [
42- "./" , "-DCMAKE_BUILD_TYPE=" + build_type , "-DBUILD_SHARED_LIBS=OFF" ,
43- "-DENABLE_SHARED=OFF" , "-DENABLE_DECODER=ON" , "-DENABLE_ENCODER=ON"
44- ]
45-
46- if "windows" == base .host_platform ():
47- base .cmd ("cmake" , cmake_args )
48- base .cmd ("cmake" , ["--build" , "." , "--config" , build_type ])
49- base .copy_files (cmake_dir + "/libde265/" + build_type + "/*.lib" , lib_dir )
50-
51- if "linux" == base .host_platform ():
52- cmake_args .extend (["-DCMAKE_POSITION_INDEPENDENT_CODE=ON" ])
53- base .cmd ("cmake" , cmake_args )
54- base .cmd ("make" , ["-j$(nproc)" ])
55- base .copy_files (cmake_dir + "/libde265/*.a" , lib_dir )
56-
57- os .chdir (src_dir )
58-
59- return
60-
78+ if not base .is_dir ("libde265" ):
79+ base .cmd ("git" , ["clone" , "https://github.com/strukturag/libde265.git" ])
80+ cmake_dir = src_dir + "/libde265"
81+ os .chdir (cmake_dir )
6182
62- def make_heif (src_dir , lib_dir , build_type ):
63- if not base .is_dir ("libheif" ):
64- base .cmd ("git" , ["clone" , "https://github.com/strukturag/libheif.git" ])
83+ cmake_args = [
84+ "./" , "-DCMAKE_BUILD_TYPE=" + build_type , "-DBUILD_SHARED_LIBS=OFF" ,
85+ "-DENABLE_SHARED=OFF" , "-DENABLE_DECODER=ON" , "-DENABLE_ENCODER=ON"
86+ ]
6587
66- src_str = "option(BUILD_SHARED_LIBS \" Build shared libraries\" ON)"
67- rep_str = "option(BUILD_SHARED_LIBS \" Build shared libraries\" ON)\n \n " \
68- "if(NOT BUILD_SHARED_LIBS)\n " \
69- "\t add_definitions(-DLIBDE265_STATIC_BUILD)\n " \
70- "endif()"
71- base .replaceInFile (src_dir + "/libheif/CmakeLists.txt" , src_str , rep_str )
88+ if "windows" == base .host_platform ():
89+ base .cmd ("cmake" , cmake_args )
90+ base .cmd ("cmake" , ["--build" , "." , "--config" , build_type ])
91+ base .copy_files (cmake_dir + "/libde265/" + build_type + "/*.lib" , lib_dir )
7292
73- cmake_dir = src_dir + "/libheif/libheif/api/libheif"
74- os .chdir (cmake_dir )
93+ if "linux" == base .host_platform ():
94+ cmake_args .extend (["-DCMAKE_POSITION_INDEPENDENT_CODE=ON" ])
95+ base .cmd ("cmake" , cmake_args )
96+ base .cmd ("make" , ["-j$(nproc)" ])
97+ base .copy_files (cmake_dir + "/libde265/*.a" , lib_dir )
7598
76- cmake_args = [
77- "../../../" , "-DCMAKE_BUILD_TYPE=" + build_type , "--preset=release-noplugins" ,
78- "-DENABLE_PLUGIN_LOADING=OFF" , "-DWITH_X265=ON" , "-DWITH_LIBDE265=ON" ,
79- "-DBUILD_SHARED_LIBS=OFF"
80- ]
81-
82- if "windows" == base .host_platform ():
83- cmake_args .extend (["-DLIBDE265_INCLUDE_DIR=" + src_dir + "/libde265" ,
84- "-DLIBDE265_LIBRARY=" + lib_dir + "/libde265.lib" ,
85- "-DX265_INCLUDE_DIR=" + src_dir + "/x265_git/source" ,
86- "-DX265_LIBRARY=" + lib_dir + "/x265-static.lib" ,])
87- base .cmd ("cmake" , cmake_args )
88- base .cmd ("cmake" , ["--build" , "." , "--config" , build_type ])
89- base .copy_files (cmake_dir + "/libheif/" + build_type + "/*.lib" , lib_dir )
90-
91- if "linux" == base .host_platform ():
92- cmake_args .extend (["-DCMAKE_POSITION_INDEPENDENT_CODE=ON" ,
93- "-DWITH_GDK_PIXBUF=OFF" , "-DWITH_GNOME=OFF" ,
94- "-DLIBDE265_INCLUDE_DIR=" + src_dir + "/libde265" ,
95- "-DLIBDE265_LIBRARY=" + lib_dir + "/libde265.a" ,
96- "-DX265_INCLUDE_DIR=" + src_dir + "/x265_git/source" ,
97- "-DX265_LIBRARY=" + lib_dir + "/libx265.a" ])
98- base .cmd ("cmake" , cmake_args )
99- base .cmd ("make" , ["-j$(nproc)" ])
100- base .copy_files (cmake_dir + "/libheif/*.a" , lib_dir )
101-
102- base .copy_files (cmake_dir + "/libheif/*.h" , cmake_dir )
103- os .chdir (src_dir )
104-
105- return
99+ os .chdir (src_dir )
100+
101+ return
102+
103+
104+ def make_heif (src_dir , lib_dir , build_type ):
105+ if not base .is_dir ("libheif" ):
106+ base .cmd ("git" , ["clone" , "https://github.com/strukturag/libheif.git" ])
107+
108+ src_str = "option(BUILD_SHARED_LIBS \" Build shared libraries\" ON)"
109+ rep_str = "option(BUILD_SHARED_LIBS \" Build shared libraries\" ON)\n \n " \
110+ "if(NOT BUILD_SHARED_LIBS)\n " \
111+ "\t add_definitions(-DLIBDE265_STATIC_BUILD)\n " \
112+ "endif()"
113+ base .replaceInFile (src_dir + "/libheif/CmakeLists.txt" , src_str , rep_str )
114+
115+ cmake_dir = src_dir + "/libheif/libheif/api/libheif"
116+ os .chdir (cmake_dir )
117+
118+ cmake_args = [
119+ "../../../" , "-DCMAKE_BUILD_TYPE=" + build_type , "--preset=release-noplugins" ,
120+ "-DENABLE_PLUGIN_LOADING=OFF" , "-DWITH_X265=ON" , "-DWITH_LIBDE265=ON" ,
121+ "-DBUILD_SHARED_LIBS=OFF"
122+ ]
123+
124+ if "windows" == base .host_platform ():
125+ cmake_args .extend (["-DLIBDE265_INCLUDE_DIR=" + src_dir + "/libde265" ,
126+ "-DLIBDE265_LIBRARY=" + lib_dir + "/libde265.lib" ,
127+ "-DX265_INCLUDE_DIR=" + src_dir + "/x265_git/source" ,
128+ "-DX265_LIBRARY=" + lib_dir + "/x265-static.lib" ,])
129+ base .cmd ("cmake" , cmake_args )
130+ base .cmd ("cmake" , ["--build" , "." , "--config" , build_type ])
131+ base .copy_files (cmake_dir + "/libheif/" + build_type + "/*.lib" , lib_dir )
132+
133+ if "linux" == base .host_platform ():
134+ cmake_args .extend (["-DCMAKE_POSITION_INDEPENDENT_CODE=ON" ,
135+ "-DWITH_GDK_PIXBUF=OFF" , "-DWITH_GNOME=OFF" ,
136+ "-DLIBDE265_INCLUDE_DIR=" + src_dir + "/libde265" ,
137+ "-DLIBDE265_LIBRARY=" + lib_dir + "/libde265.a" ,
138+ "-DX265_INCLUDE_DIR=" + src_dir + "/x265_git/source" ,
139+ "-DX265_LIBRARY=" + lib_dir + "/libx265.a" ])
140+ base .cmd ("cmake" , cmake_args )
141+ base .cmd ("make" , ["-j$(nproc)" ])
142+ base .copy_files (cmake_dir + "/libheif/*.a" , lib_dir )
143+
144+ base .copy_files (cmake_dir + "/libheif/*.h" , cmake_dir )
145+ os .chdir (src_dir )
146+
147+ return
106148
107149def make ():
108- print ("[fetch & build]: heif" )
109- new_dir = base .get_script_dir () + "/../../core/Common/3dParty/heif"
110- base .create_dir (new_dir )
111- old_dir = os .getcwd ()
112- os .chdir (new_dir )
150+ print ("[fetch & build]: heif" )
113151
114- build_type = "Release "
115- if ( - 1 != config . option ( "config" ). lower (). find ( "debug" )):
116- build_type = "Debug"
152+ base_dir = base . get_script_dir () + "/../../core/Common/3dParty/heif "
153+ old_dir = os . getcwd ()
154+ os . chdir ( base_dir )
117155
118- lib_dir = new_dir + "/lib/" + build_type
119- base .create_dir (lib_dir )
156+ # TODO: do we really need debug libheif libraries ???
157+ build_type = "Release"
158+ if (- 1 != config .option ("config" ).lower ().find ("debug" )):
159+ build_type = "Debug"
120160
121- if not base . is_dir ( "heif" ):
122- make_x265 (new_dir , lib_dir , build_type )
123- make_de265 ( new_dir , lib_dir , build_type )
124- make_heif ( new_dir , lib_dir , build_type )
161+ # build encoder libraries
162+ make_x265 (base_dir , build_type )
163+ # build decoder libraries
164+ # make_de265(base_dir , build_type)
125165
126- os .chdir (old_dir )
166+ # build libheif
167+ # make_heif(base_dir, build_type)
127168
128- return
169+ os .chdir (old_dir )
170+ return
129171
130172if __name__ == '__main__' :
131- make ()
173+ make ()
0 commit comments