Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve compiler flags for Windows #706

Merged
merged 7 commits into from
Aug 20, 2024
Merged
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
48 changes: 18 additions & 30 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,37 +34,36 @@
# Add it to the requirements automatically for intel computers.
install_reqs.append('tbb')

# This will determine which compiler is being used to build the C modules
# Determine which compiler is being used to build the C/C++ modules
compiler_type = distutils.ccompiler.get_default_compiler()
if compiler_type in ("unix", "mingw32"):
compiler_optimize_flags = ['-O3', '-ftree-vectorize']
compiler_flags = ['-O3', '-ftree-vectorize', '-Wall', '-funroll-loops']
if not sys.platform.startswith('win'):
compiler_flags.append('-fPIC')
elif compiler_type == "msvc":
compiler_optimize_flags = ['/Ox', '/GL']
compiler_flags = ['/Ox', '/GL', '/std:c++14']
else:
compiler_optimize_flags = []

compiler_flags = []

# extension for convolution from astropy
# Extension for convolution from astropy
def get_convolution_extensions():
c_convolve_pkgdir = Path('hexrd') / 'convolution'

src_files = [str(c_convolve_pkgdir / 'src/convolve.c')]

extra_compile_args = ['-UNDEBUG']
if not sys.platform.startswith('win'):
extra_compile_args.append('-fPIC')
extra_compile_args += compiler_optimize_flags
extra_compile_args = ['-UNDEBUG'] + compiler_flags
# Add '-Rpass-missed=.*' to ``extra_compile_args`` when compiling with
# clang to report missed optimizations
_convolve_ext = Extension(name='hexrd.convolution._convolve',
sources=src_files,
extra_compile_args=extra_compile_args,
include_dirs=[numpy.get_include()],
language='c')
_convolve_ext = Extension(
name='hexrd.convolution._convolve',
sources=src_files,
extra_compile_args=extra_compile_args,
include_dirs=[numpy.get_include()],
language='c'
)

return [_convolve_ext]


def get_include_path(library_name):
env_var_hint = os.getenv(f"{library_name.upper()}_INCLUDE_DIR")
if env_var_hint is not None and os.path.exists(env_var_hint):
Expand Down Expand Up @@ -97,7 +96,6 @@ def get_include_path(library_name):
# It should exist now
return full_path


def get_pybind11_include_path():
# If we can import pybind11, use that include path
try:
Expand All @@ -110,16 +108,10 @@ def get_pybind11_include_path():
# Otherwise, we will download the source and include that
return get_include_path('pybind11')


def get_cpp_extensions():
cpp_transform_pkgdir = Path('hexrd') / 'transforms/cpp_sublibrary'
src_files = [str(cpp_transform_pkgdir / 'src/inverse_distortion.cpp')]

extra_compile_args = ['-O3', '-Wall', '-shared', '-std=c++14',
'-funroll-loops']
if not sys.platform.startswith('win'):
extra_compile_args.append('-fPIC')

# Define include directories
include_dirs = [
get_include_path('xsimd'),
Expand All @@ -131,14 +123,13 @@ def get_cpp_extensions():
inverse_distortion_ext = Extension(
name='hexrd.extensions.inverse_distortion',
sources=src_files,
extra_compile_args=extra_compile_args,
extra_compile_args=compiler_flags+['-std=c++14'],
include_dirs=include_dirs,
language='c++',
)

return [inverse_distortion_ext]


def get_old_xfcapi_extension_modules():
# for transforms
srclist = ['transforms_CAPI.c', 'transforms_CFUNC.c']
Expand All @@ -147,23 +138,21 @@ def get_old_xfcapi_extension_modules():
'hexrd.extensions._transforms_CAPI',
sources=srclist,
include_dirs=[np_include_dir],
extra_compile_args=compiler_optimize_flags,
extra_compile_args=compiler_flags,
)

return [transforms_mod]


def get_new_xfcapi_extension_modules():
transforms_mod = Extension(
'hexrd.extensions._new_transforms_capi',
sources=['hexrd/transforms/new_capi/module.c'],
include_dirs=[np_include_dir],
extra_compile_args=compiler_optimize_flags,
extra_compile_args=compiler_flags,
)

return [transforms_mod]


def get_extension_modules():
# Flatten the lists
return [item for sublist in (
Expand All @@ -173,7 +162,6 @@ def get_extension_modules():
get_cpp_extensions(),
) for item in sublist]


ext_modules = get_extension_modules()

# use entry_points, not scripts:
Expand Down
Loading