Commit f08372ba authored by Tomasz Socha's avatar Tomasz Socha Committed by Sang Ik Lee

[PY] Add flag to compile python API in debug mode (#4052)

* [PY] Add flag to compile python API in debug mode

* Move debug and release flags to helper function

* Add missing Docstring
Co-authored-by: 's avatarSang Ik Lee <sang.ik.lee@intel.com>
parent 6de4893b
......@@ -26,6 +26,7 @@ __version__ = os.environ.get('NGRAPH_VERSION', '0.0.0-dev')
PYNGRAPH_ROOT_DIR = os.path.abspath(os.path.dirname(__file__))
NGRAPH_DEFAULT_INSTALL_DIR = os.environ.get('HOME')
NGRAPH_ONNX_IMPORT_ENABLE = os.environ.get('NGRAPH_ONNX_IMPORT_ENABLE')
NGRAPH_PYTHON_DEBUG = os.environ.get('NGRAPH_PYTHON_DEBUG')
def find_ngraph_dist_dir():
......@@ -367,6 +368,13 @@ class BuildExt(build_ext):
return True
return False
def add_debug_or_release_flags(self):
"""Return compiler flags for Release and Debug build types."""
if NGRAPH_PYTHON_DEBUG in ['TRUE', 'ON', True]:
return ['-O0', '-g']
else:
return ['-O2', '-D_FORTIFY_SOURCE=2']
def build_extensions(self):
"""Build extension providing extra compiler flags."""
if sys.platform == 'win32':
......@@ -388,7 +396,8 @@ class BuildExt(build_ext):
add_platform_specific_link_args(ext.extra_link_args)
ext.extra_compile_args += ['-Wformat', '-Wformat-security']
ext.extra_compile_args += ['-O2', '-D_FORTIFY_SOURCE=2']
ext.extra_compile_args += self.add_debug_or_release_flags()
if sys.platform == 'darwin':
ext.extra_compile_args += ['-stdlib=libc++']
build_ext.build_extensions(self)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment