Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 37 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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}
)
7 changes: 2 additions & 5 deletions src/fs.h
Original file line number Diff line number Diff line change
@@ -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 <experimental/filesystem>
namespace fs = std::experimental::filesystem::v1;
#include <filesystem>
namespace fs = std::filesystem;
#else
#include "filesystem/filesystem_mini.h"
namespace fs = filesystem;
Expand Down
6 changes: 4 additions & 2 deletions vs2019/ccscript.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -82,9 +83,10 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand Down
1 change: 1 addition & 0 deletions vs2019/tests.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<PrecompiledHeader />
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
Expand Down