Add cflags for msvc
@@ -14,6 +14,7 @@ from setuptools import Extension
from distutils.spawn import find_executable
from setuptools.command.build_ext import build_ext as _build_ext
from distutils.file_util import copy_file
+from distutils.ccompiler import get_default_compiler
from typing import List
@@ -26,6 +27,8 @@ _extra_cxx_compile_args = ["-std=c++11", "-fvisibility=hidden", "-fvisibility-in
if os.name != "nt":
_extra_cxx_compile_args += ["-flto"]
+_extra_cxx_compile_args_msvc = ["/permissive-"]
+
# Make PRI* format macros available with C++11 compiler but older libc, e.g. on RHEL6.
_extra_defines = [("__STDC_FORMAT_MACROS", "")]
@@ -159,6 +162,14 @@ def _get_lib_ext_name():
class build_ext(_build_ext):
+ def _uses_msvc(self):
+ if self.compiler == "msvc":
+ return True
+ if self.compiler is None:
+ return get_default_compiler() == "msvc"
+ else:
+ return "msvc" == getattr(self.compiler, "compiler_type", None)
+
def run(self):
if os.name == "nt":
create_sxs_appconfig(self.get_ext_fullpath(os.path.join("cocotb", "simulator")))
@@ -176,6 +187,13 @@ class build_ext(_build_ext):
def build_extensions(self):
if os.name == "nt":
+ if self._uses_msvc():
+ # Initialize the compiler now so that compiler/linker flags are populated
+ if not self.compiler.initialized:
+ self.compiler.initialize()
+
+ self.compiler.compile_options = [x for x in self.compiler.compile_options if not x.startswith("/W")] + ["/W4"]
+
def_dir = os.path.join(cocotb_share_dir, "def")
self._gen_import_libs(def_dir)
@@ -189,6 +207,9 @@ class build_ext(_build_ext):
A normal PEP 517 install still works as the temp directories are discarded anyway.
"""
+ if self._uses_msvc():
+ ext.extra_compile_args += _extra_cxx_compile_args_msvc
+ else:
ext.extra_compile_args += _extra_cxx_compile_args
if os.name == "nt":
