1818
1919MODULE_NAME = "ads"
2020SRC_PATH = "PyQtAds"
21-
21+
2222REQUIRE_PYQT = True
2323if "--conda-recipe" in sys .argv :
2424 REQUIRE_PYQT = False
@@ -40,7 +40,7 @@ def __init__(self):
4040 else :
4141 self .data_dir = sys .prefix + '/share'
4242 self .lib_dir = sys .prefix + '/lib'
43-
43+
4444
4545class TargetQtConfiguration (object ):
4646 def __init__ (self , qmake ):
@@ -63,12 +63,12 @@ def __init__(self, qmake):
6363 setattr (self , name , value )
6464
6565 pipe .close ()
66-
66+
6767
6868class build_ext (sipdistutils .build_ext ):
69-
69+
7070 description = "Builds the " + MODULE_NAME + " module."
71-
71+
7272 user_options = sipdistutils .build_ext .user_options + [
7373 ('qmake-bin=' , None , "Path to qmake binary" ),
7474 ('sip-bin=' , None , "Path to sip binary" ),
@@ -78,7 +78,7 @@ class build_ext(sipdistutils.build_ext):
7878 ('sip-dir=' , None , "Path to module's SIP files" ),
7979 ('inc-dir=' , None , "Path to module's include files" )
8080 ]
81-
81+
8282 def initialize_options (self ):
8383 super ().initialize_options ()
8484 self .qmake_bin = 'qmake'
@@ -92,16 +92,16 @@ def initialize_options (self):
9292 self .inc_dir = None
9393 self .pyconfig = HostPythonConfiguration ()
9494 self .qtconfig = TargetQtConfiguration (self .qmake_bin )
95- self .config = sipconfig .Configuration ()
95+ self .config = sipconfig .Configuration ()
9696 self .config .default_mod_dir = ("/usr/local/lib/python%i.%i/dist-packages" %
9797 (sys .version_info .major , sys .version_info .minor ))
98-
98+
9999 def finalize_options (self ):
100100 super ().finalize_options ()
101101
102102 if not self .qt_include_dir :
103103 self .qt_include_dir = self .qtconfig .QT_INSTALL_HEADERS
104-
104+
105105 if not self .qt_libinfix :
106106 try :
107107 with open (os .path .join (self .qtconfig .QT_INSTALL_PREFIX , 'mkspecs' , 'qconfig.pri' ), 'r' ) as f :
@@ -113,16 +113,16 @@ def finalize_options (self):
113113
114114 if not self .pyqt_sip_dir :
115115 self .pyqt_sip_dir = os .path .join (self .pyconfig .data_dir , 'sip' , 'PyQt5' )
116-
116+
117117 if not self .pyqt_sip_flags :
118118 self .pyqt_sip_flags = PYQT_CONFIGURATION .get ('sip_flags' , '' )
119-
119+
120120 if not self .sip_files_dir :
121121 self .sip_files_dir = os .path .abspath (os .path .join ("." , "sip" ))
122-
122+
123123 if not self .sip_inc_dir :
124124 self .sip_inc_dir = self .pyconfig .venv_inc_dir
125-
125+
126126 if not self .inc_dir :
127127 self .inc_dir = os .path .abspath (os .path .join ("." , "src" ))
128128
@@ -138,12 +138,12 @@ def finalize_options (self):
138138 if not self .pyqt_sip_flags :
139139 raise SystemExit ('Could not find PyQt SIP flags. '
140140 'Please specify via --pyqt-sip-flags=' )
141-
141+
142142 def _find_sip (self ):
143143 """override _find_sip to allow for manually speficied sip path."""
144144 return self .sip_bin or super ()._find_sip ()
145-
146- def _sip_compile (self , sip_bin , source , sbf ):
145+
146+ def _sip_compile (self , sip_bin , source , sbf ):
147147 cmd = [sip_bin ]
148148 if hasattr (self , 'sip_opts' ):
149149 cmd += self .sip_opts
@@ -157,11 +157,11 @@ def _sip_compile(self, sip_bin, source, sbf):
157157 "-c" , self ._sip_output_dir (),
158158 "-b" , sbf ,
159159 "-w" , "-o" ]
160-
160+
161161 cmd += shlex .split (self .pyqt_sip_flags ) # use same SIP flags as for PyQt5
162162 cmd .append (source )
163163 self .spawn (cmd )
164-
164+
165165 def swig_sources (self , sources , extension = None ):
166166 if not self .extensions :
167167 return
@@ -179,7 +179,7 @@ def swig_sources (self, sources, extension=None):
179179 extension .libraries += ['Qt5Core' + self .qt_libinfix ,
180180 'Qt5Gui' + self .qt_libinfix ,
181181 'Qt5Widgets' + self .qt_libinfix ]
182-
182+
183183 if sys .platform == 'win32' :
184184 extension .library_dirs += [self .qtconfig .QT_INSTALL_LIBS ,
185185 self .inc_dir , self ._sip_output_dir ()]
@@ -192,30 +192,42 @@ def swig_sources (self, sources, extension=None):
192192 extension .extra_compile_args += ['-std=c++11' ]
193193
194194 return super ().swig_sources (sources , extension )
195-
195+
196196 def build_extension (self , ext ):
197197 cppsources = [source for source in ext .sources if source .endswith (".cpp" )]
198-
198+
199199 dir_util .mkpath (self .build_temp , dry_run = self .dry_run )
200200
201+ def get_moc_args (out_file , source ):
202+ if sys .platform .startswith ('linux' ):
203+ return ["moc" , "-D" , "Q_OS_LINUX=1" , "-o" , out_file , source ]
204+ return ["moc" , "-o" , out_file , source ]
205+
201206 # Run moc on all header files.
202207 for source in cppsources :
208+ # *.cpp -> *.moc
209+ moc_file = os .path .basename (source ).replace (".cpp" , ".moc" )
210+ out_file = os .path .join (self .build_temp , moc_file )
211+
212+ if newer (source , out_file ) or self .force :
213+ spawn .spawn (get_moc_args (out_file , source ), dry_run = self .dry_run )
214+
203215 header = source .replace (".cpp" , ".h" )
204216 if os .path .exists (header ):
217+ # *.h -> moc_*.cpp
205218 moc_file = "moc_" + os .path .basename (header ).replace (".h" , ".cpp" )
206219 out_file = os .path .join (self .build_temp , moc_file )
207-
220+
208221 if newer (header , out_file ) or self .force :
209- call_arg = ["moc" , "-o" , out_file , header ]
210- spawn .spawn (call_arg , dry_run = self .dry_run )
211-
222+ spawn .spawn (get_moc_args (out_file , header ), dry_run = self .dry_run )
223+
212224 if os .path .getsize (out_file ) > 0 :
213225 ext .sources .append (out_file )
214226
215227 # Add the temp build directory to include path, for compiler to find
216228 # the created .moc files
217229 ext .include_dirs += [self ._sip_output_dir ()]
218-
230+
219231 sipdistutils .build_ext .build_extension (self , ext )
220232
221233
@@ -253,7 +265,7 @@ def run(self):
253265install_requires = ["PyQt5" ]
254266if sys .platform == 'win32' :
255267 install_requires .append ("pywin32" )
256-
268+
257269
258270with open ('README.md' , 'r' ) as f :
259271 LONG_DESCRIPTION = f .read ()
0 commit comments