diff --git a/setup.py b/setup.py index 949c74f..ab08f02 100755 --- a/setup.py +++ b/setup.py @@ -1,17 +1,45 @@ #!/usr/bin/python3 import os -import platform +from distutils.ccompiler import get_default_compiler from setuptools import setup +from setuptools.command.build_ext import build_ext from setuptools.extension import Extension source_files = [os.path.join("src", x) for x in os.listdir("src") if x.lower().endswith(".cpp")] -extra_compile_args = [] -extra_link_args = [] +# As of July 2026, setuptools doesn't seem to include its own method to add compiler flags dependent +# on the specific compiler (I legitimately don't understand how extra_compile_args is supposed to +# work normally). But it does provide distutils' interface for checking what the compiler is, which +# should work in a stable way until they add their own way. +# See https://setuptools.pypa.io/en/latest/userguide/interfaces.html for info on stability tiers. +# See https://setuptools.pypa.io/en/latest/userguide/extension.html for the recommendation to +# inherit from existing commands to augment build functionality. +# See https://github.com/pypa/setuptools/issues/2806 for people asking for an upgrade path for many +# things related to creating and detecting compilers. +# Especially this comment: https://github.com/pypa/setuptools/issues/2806#issuecomment-1367674526 +class build_ext_with_compiler_flags(build_ext): + def finalize_options(self): + super().finalize_options() -if platform.system() == "Linux" or platform.system() == "Darwin": - extra_compile_args = ["-std=c++11"] + extra_compile_args = [] + extra_link_args = [] + + compiler_type = None + if self.compiler is None: + compiler_type = get_default_compiler() + else: + compiler_type = self.compiler + + if compiler_type == 'msvc': + extra_compile_args.append('/std:c++17') + extra_compile_args.append('/D_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING') + else: + extra_compile_args.append('-std=c++11') + + for ext in self.extensions: + ext.extra_compile_args.extend(extra_compile_args) + ext.extra_link_args.extend(extra_link_args) setup(name="ccscript", version="1.500", @@ -20,8 +48,8 @@ ext_modules=[ Extension("ccscript", source_files, - language="c++", - extra_compile_args=extra_compile_args, - extra_link_args=extra_link_args + language="c++" ) - ]) + ], + cmdclass={'build_ext': build_ext_with_compiler_flags} + ) \ No newline at end of file diff --git a/src/fs.h b/src/fs.h index 52f84a4..4d2aa0e 100644 --- a/src/fs.h +++ b/src/fs.h @@ -1,10 +1,7 @@ #pragma once #ifdef _WIN32 - #ifndef _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING - #define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING - #endif // !_SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING - #include - namespace fs = std::experimental::filesystem::v1; + #include + namespace fs = std::filesystem; #else #include "filesystem/filesystem_mini.h" namespace fs = filesystem; diff --git a/vs2019/ccscript.vcxproj b/vs2019/ccscript.vcxproj index 047d9d0..e3f375a 100644 --- a/vs2019/ccscript.vcxproj +++ b/vs2019/ccscript.vcxproj @@ -60,9 +60,10 @@ Level3 true - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + WIN32;_DEBUG;_CONSOLE;_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING;%(PreprocessorDefinitions) true MultiThreadedDebug + stdcpp17 Console @@ -82,9 +83,10 @@ true true true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + WIN32;NDEBUG;_CONSOLE;_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING;%(PreprocessorDefinitions) true MultiThreaded + stdcpp17 Console diff --git a/vs2019/tests.vcxproj b/vs2019/tests.vcxproj index 44f7b16..9543420 100644 --- a/vs2019/tests.vcxproj +++ b/vs2019/tests.vcxproj @@ -77,6 +77,7 @@ Level3 ProgramDatabase + stdcpp17 true