9 from setuptools
import setup, Extension
10 from setuptools.command.build_ext
import build_ext
22 module_name =
'wxcpppy' 26 wxcpppy_path = os.environ[
"PWD"] +
"/.." 27 """C'est la seul variable qui permet de retrouver par défaut le répertoire d'éxécution du script. Pip exécute le 28 tout dans un répertoire temporaire. 32 """Liste des chemins pour compiler le projet wxCppPy::API_Py""" 35 def get_includes_directories():
37 result = [Directories.wxcpppy_path +
"/API_Py/include",
38 Directories.wxcpppy_path +
"/API/include",
41 Directories.wxcpppy_config.pyenv_include_path,
42 Directories.wxcpppy_config.cppclay_path +
"/include",
43 Directories.wxcpppy_config.wxpython_path +
"/ext/wxWidgets/include",
44 Directories.wxcpppy_config.wxpython_path +
"/build/wxbld/gtk3/lib/wx/include/gtk3-unicode-3.0",
45 Directories.wxcpppy_config.wxpython_path +
"/sip/siplib",
46 Directories.wxcpppy_config.wxpython_path +
"/wx/include",
47 Directories.wxcpppy_config.pyenv_path,
48 Directories.wxcpppy_config.pyenv_sp_path,
49 Directories.wxcpppy_config.pyenv_include_path,
50 Directories.wxcpppy_config.pybind11_path,
51 Directories.wxcpppy_config.wxpython_path,
52 Directories.wxcpppy_config.cppclay_path,
53 Directories.wxcpppy_config.cppclaydll_path]
60 (
'PYTHONENV_PATH', Directories.wxcpppy_config.pyenv_path),
61 (
'PYTHONENV_SP_PATH', Directories.wxcpppy_config.pyenv_sp_path),
62 (
'PYTHONENV_INCLUDE_PATH', Directories.wxcpppy_config.pyenv_include_path),
63 (
'PYBIND11_PATH', Directories.wxcpppy_config.pybind11_path),
64 (
'WXPYTHON_PATH', Directories.wxcpppy_config.wxpython_path),
65 (
'CPPCLAY_PATH', Directories.wxcpppy_config.cppclay_path),
66 (
'CPPCLAYDLL_PATH', Directories.wxcpppy_config.cppclaydll_path),
67 (
'WXCPPPY_PATH', Directories.wxcpppy_path)]
69 for define
in Directories.get_defines():
70 result.append((define,
None))
76 path_wx_python = Directories.wxcpppy_config.pyenv_sp_path +
'/wx/' 78 prefix_wx = path_wx_python +
'lib' 81 prefix_wx_cpython = path_wx_python
82 suffix_wx_cpython = Directories.wxcpppy_config.pyenv_ext_suffix
84 wx_paths = [
'wx_gtk3u_xrc-3.0',
85 'wx_gtk3u_webview-3.0',
94 for i
in range(0, len(wx_paths)):
95 wx_paths[i] = prefix_wx + wx_paths[i] + suffix_wx
97 wx_cpython_path = [
'_aui',
113 for i
in range(0, len(wx_cpython_path)):
114 wx_cpython_path[i] = prefix_wx_cpython + wx_cpython_path[i] + suffix_wx_cpython
116 result = wx_paths.copy()
117 result.extend(wx_cpython_path)
119 for i
in range(0, len(result)):
121 assert os.path.exists(path), path +
" doesn't exist" 122 result[i] = os.path.normpath(path)
124 result.extend([Directories.wxcpppy_path +
"/API/bin/Debug/libAPI.so",
125 Directories.wxcpppy_config.cppclaydll_path +
'/libclay.so',
'pthread'])
130 def get_libraries_directories():
131 return [Directories.wxcpppy_config.cppclaydll_path,
132 Directories.wxcpppy_config.pyenv_sp_path +
"/wx",
133 Directories.wxcpppy_path +
"/API/bin/Debug"]
136 def get_compiler_options():
144 return [
'_FILE_OFFSET_BITS=64',
149 'wxUSE_CMDLINE_PARSER']
153 """Helper class to determine the pybind11 include path 155 The purpose of this class is to postpone importing pybind11 156 until it is actually installed, so that the ``get_include()`` 157 method can be invoked. """ 159 def __init__(self, user=False):
164 return pybind11.get_include(self.
user)
171 sources=[
'src/Module.cpp',
'src/Vector.cpp',
'src/wxAccess.cpp'],
172 define_macros=Directories.get_macros(),
173 include_dirs=Directories.get_includes_directories(),
174 libraries=Directories.get_libraries(),
175 library_dirs=Directories.get_libraries_directories(),
183 def has_flag(compiler, flag_name):
184 """Return a boolean indicating whether a flag name is supported on 185 the specified compiler. 188 with tempfile.NamedTemporaryFile(
'w', suffix=
'.cpp')
as f:
189 f.write(
'int main (int argc, char **argv) { return 0; }')
191 compiler.compile([f.name], extra_postargs=[flag_name])
192 except setuptools.distutils.errors.CompileError:
197 def cpp_flag(compiler):
198 """Return the -std=c++[11/14/17] compiler flag. 200 The c++17 is prefered over c++14/11 (when it is available). 202 if has_flag(compiler,
'-std=c++17'):
204 elif has_flag(compiler,
'-std=c++1z'):
206 elif has_flag(compiler,
'-std=c++1atest'):
208 elif has_flag(compiler,
'-std=c++11'):
210 elif has_flag(compiler,
'-std=c++14'):
212 elif has_flag(compiler,
'-std=c++11'):
215 raise RuntimeError(
'Unsupported compiler -- at least C++11 support is needed!')
219 """A custom build extension for adding compiler-specific options.""" 225 if sys.platform ==
'darwin':
226 c_opts[
'unix'] += [
'-stdlib=libc++',
'-mmacosx-version-min=10.7']
228 def build_extensions(self):
229 ct = self.compiler.compiler_type
230 opts = self.
c_opts.get(ct, [])
233 opts.append(
'-DVERSION_INFO="%s"' % self.distribution.get_version())
234 opts.append(cpp_flag(self.compiler))
236 if has_flag(self.compiler,
'-fvisibility=hidden'):
237 opts.append(
'-fvisibility=hidden')
240 opts.append(
'/DVERSION_INFO=\\"%s\\"' % self.distribution.get_version())
242 for option
in Directories.get_compiler_options():
245 for ext
in self.extensions:
246 ext.extra_compile_args = opts
248 build_ext.build_extensions(self)
254 author=
'Pierre Pontier',
255 author_email=
'http://www.suryavarman.fr/contact/',
256 url=
'http://www.suryavarman.fr/python_cpp_pybind_wx/',
258 description=
'A tutorial project using pybind11 and wxWidgets',
260 ext_modules=ext_modules,
261 install_requires=[
'pybind11>=2.2',
'wxPython>=4'],
262 setup_requires=[
'wxPython>=4'],
263 include_package_data=
True,
264 cmdclass={
'build_ext': BuildExt},