Skip to content

Commit

Permalink
Clean up C/C++ std specifications
Browse files Browse the repository at this point in the history
  • Loading branch information
kovidgoyal committed Jan 26, 2023
1 parent 58c9ca9 commit d6a0f4b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 29 deletions.
42 changes: 21 additions & 21 deletions setup/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ def __init__(self, name, sources, **kwargs):
self.libraries = d['libraries'] = kwargs.get('libraries', [])
self.cflags = d['cflags'] = kwargs.get('cflags', [])
self.uses_icu = 'icuuc' in self.libraries
if self.needs_cxx and kwargs.get('needs_c++'):
std_prefix = '/std:' if iswindows else '-std='
self.cflags.insert(0, std_prefix + 'c++' + kwargs['needs_c++'])

if iswindows:
self.cflags.append('/DCALIBRE_MODINIT_FUNC=PyMODINIT_FUNC')
if self.needs_cxx and kwargs.get('needs_c++14'):
self.cflags.insert(0, '/std:c++14')
else:
return_type = 'PyObject*'
extern_decl = 'extern "C"' if self.needs_cxx else ''
Expand All @@ -61,14 +63,8 @@ def __init__(self, name, sources, **kwargs):
'-DCALIBRE_MODINIT_FUNC='
'{} __attribute__ ((visibility ("default"))) {}'.format(extern_decl, return_type))

if self.needs_cxx:
if kwargs.get('needs_c++11'):
self.cflags.insert(0, '-std=c++11')
elif kwargs.get('needs_c++14'):
self.cflags.insert(0, '-std=c++14')
else:
if kwargs.get('needs_c99'):
self.cflags.insert(0, '-std=c99')
if kwargs.get('needs_c'):
self.cflags.insert(0, '-std=c' + kwargs['needs_c'])

self.ldflags = d['ldflags'] = kwargs.get('ldflags', [])
self.optional = d['options'] = kwargs.get('optional', False)
Expand Down Expand Up @@ -182,6 +178,20 @@ def gp(x):
is_macos_universal_build = ismacos and 'universal2' in sysconfig.get_platform()


def basic_windows_flags(debug=False):
cflags = '/c /nologo /W3 /EHsc /utf-8'.split()
cflags.append('/Zi' if debug else '/DNDEBUG')
suffix = ('d' if debug else '')
cflags.append('/MD' + suffix)
ldflags = f'/DLL /nologo /INCREMENTAL:NO /NODEFAULTLIB:libcmt{suffix}.lib'.split()
if debug:
ldflags.append('/DEBUG')
# cflags = '/c /nologo /Ox /MD /W3 /EHsc /Zi'.split()
# ldflags = '/DLL /nologo /INCREMENTAL:NO /DEBUG'.split()
cflags.append('/GS-')
return cflags, ldflags


def init_env(debug=False, sanitize=False):
from setup.build_environment import win_ld, win_inc, win_lib, NMAKE, win_cc
linker = None
Expand Down Expand Up @@ -236,17 +246,7 @@ def init_env(debug=False, sanitize=False):

if iswindows:
cc = cxx = win_cc
cflags = '/c /nologo /W3 /EHsc /utf-8'.split()
cflags.append('/Zi' if debug else '/DNDEBUG')
suffix = ('d' if debug else '')
cflags.append('/MD' + suffix)
ldflags = f'/DLL /nologo /INCREMENTAL:NO /NODEFAULTLIB:libcmt{suffix}.lib'.split()
if debug:
ldflags.append('/DEBUG')
# cflags = '/c /nologo /Ox /MD /W3 /EHsc /Zi'.split()
# ldflags = '/DLL /nologo /INCREMENTAL:NO /DEBUG'.split()
cflags.append('/GS-')

cflags, ldflags = basic_windows_flags(debug)
for p in win_inc:
cflags.append('-I'+p)
for p in win_lib:
Expand Down
17 changes: 9 additions & 8 deletions setup/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
"lib_dirs": "!hunspell_lib_dirs",
"libraries": "hunspell-1.7",
"windows_libraries": "libhunspell",
"needs_c++11": true
"needs_c++": "11"
},
{
"name": "hyphen",
"sources": "calibre/utils/hyphenation/hyphen.c",
"libraries": "hyphen",
"inc_dirs": "!hyphen_inc_dirs",
"lib_dirs": "!hyphen_lib_dirs",
"needs_c99": true
"needs_c": "99"
},
{
"name": "uchardet",
Expand All @@ -27,7 +27,7 @@
"name": "unicode_names",
"headers": "unicode_names/names.h unicode_names/data-types.h",
"sources": "unicode_names/unicode_names.c",
"needs_c99": true
"needs_c": "99"
},
{
"name": "speedup",
Expand Down Expand Up @@ -82,7 +82,7 @@
"name": "sqlite_extension",
"headers": "calibre/utils/cpp_binding.h",
"sources": "calibre/db/sqlite_extension.cpp",
"needs_c++14": true,
"needs_c++": "14",
"libraries": "icudata icui18n icuuc icuio stemmer",
"windows_libraries": "icudt icuin icuuc icuio libstemmer",
"lib_dirs": "!icu_lib_dirs",
Expand Down Expand Up @@ -124,19 +124,19 @@
"lib_dirs": "!podofo_lib",
"inc_dirs": "!podofo_inc",
"error": "!podofo_error",
"needs_c++11": true
"needs_c++": "11"
},
{
"name": "html_as_json",
"sources": "calibre/srv/html_as_json.cpp",
"needs_c++11": true
"needs_c++": "11"
},
{
"name": "fast_css_transform",
"headers": "calibre/utils/cpp_binding.h calibre/utils/stb_sprintf.h",
"sources": "calibre/srv/fast_css_transform.cpp",
"inc_dirs": "perfect-hashing",
"needs_c++14": true
"needs_c++": "14"
},
{
"name": "rcc_backend",
Expand Down Expand Up @@ -190,7 +190,8 @@
"headers": "calibre/utils/cpp_binding.h calibre/utils/windows/common.h",
"sources": "calibre/utils/windows/winspeech.cpp",
"libraries": "WindowsApp",
"cflags": "/X /std:c++17 /Zc:__cplusplus /bigobj /await /permissive- /WX /Zc:twoPhase-"
"needs_c++": "17",
"cflags": "/X /Zc:__cplusplus /bigobj /await /permissive- /WX /Zc:twoPhase-"
},
{
"name": "wpd",
Expand Down

0 comments on commit d6a0f4b

Please sign in to comment.