Skip to content

Commit 58cfe7b

Browse files
authored
build: support to build pymol with mingw-w64 on Windows (#486)
Signed-off-by: Zhou Qiankang <wszqkzqk@qq.com>
1 parent 0a53de0 commit 58cfe7b

File tree

5 files changed

+61
-28
lines changed

5 files changed

+61
-28
lines changed

contrib/uiuc/plugins/molfile_plugin/src/dtrplugin.hxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4242
#ifndef MOLFILE_DTRPLUGIN_HXX
4343
#define MOLFILE_DTRPLUGIN_HXX
4444

45-
#if defined(_MSC_VER)
45+
#if defined(_WIN32)
4646
#ifndef DESRES_WIN32
4747
#define DESRES_WIN32
4848
#endif

contrib/uiuc/plugins/molfile_plugin/src/ply_c.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3121,7 +3121,7 @@ void *get_new_props_ply(PlyFile *ply)
31213121
}
31223122

31233123
/* in case we need a random choice */
3124-
#if defined(_MSC_VER)
3124+
#if defined(_WIN32)
31253125
random_pick = 0;
31263126
#else
31273127
random_pick = (int) floor (rules->nprops * drand48());

layer0/strcasecmp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#pragma once
66

7-
#ifdef _WIN32
7+
#if defined(_WIN32) && defined(_MSC_VER)
88
#include <string.h>
99
#define strcasecmp(s1, s2) _stricmp(s1, s2)
1010
#define strncasecmp(s1, s2, n) _strnicmp(s1, s2, n)

ov/src/ov_types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ extern "C" {
6060
typedef unsigned int ov_uint32;
6161
typedef float ov_float32;
6262
typedef double ov_float64;
63-
#ifdef WIN32
63+
#ifdef _MSC_VER
6464
typedef __int64 ov_int64;
6565
typedef unsigned __int64 ov_uint64;
6666
#else

setup.py

Lines changed: 57 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@
3131
MAC = sys.platform.startswith("darwin")
3232

3333

34+
# check for mingw compiler on windows
35+
is_mingw = False
36+
if WIN:
37+
from setuptools._distutils import ccompiler
38+
is_mingw = ccompiler.get_default_compiler() == 'mingw32'
39+
40+
3441
# Have to copy from "create_shadertext.py" script due to the use of pyproject.toml
3542
# Full explanation:
3643
# https://github.com/pypa/setuptools/issues/3939
@@ -269,6 +276,10 @@ def get_prefix_path() -> list[str]:
269276

270277
paths += [sys.prefix] + paths
271278

279+
if WIN and is_mingw:
280+
if os.path.isdir(sys.prefix):
281+
paths.append(os.path.normpath(sys.prefix))
282+
272283
paths += ["/usr"]
273284

274285
return paths
@@ -566,8 +577,9 @@ def make_launch_script(self):
566577

567578
libs = ["png", "freetype"]
568579
lib_dirs = []
569-
ext_comp_args = (
570-
[
580+
ext_comp_args = []
581+
if is_mingw or not WIN:
582+
ext_comp_args.extend([
571583
"-Werror=return-type",
572584
"-Wunused-variable",
573585
"-Wno-switch",
@@ -576,27 +588,27 @@ def make_launch_script(self):
576588
"-Wno-char-subscripts",
577589
# optimizations
578590
"-Og" if DEBUG else "-O3",
579-
]
580-
if not WIN
581-
else ["/MP"]
582-
)
591+
])
592+
else: # MSVC
593+
ext_comp_args.extend([
594+
"/MP",
595+
"/std:c++17",
596+
])
583597
ext_link_args = []
584598
ext_objects = []
585599
data_files = []
586600
ext_modules = []
587601

588602
if options.use_openmp == "yes":
589-
def_macros += [
590-
("PYMOL_OPENMP", None),
591-
]
592-
if MAC:
593-
ext_comp_args += ["-Xpreprocessor", "-fopenmp"]
594-
libs += ["omp"]
595-
elif WIN:
596-
ext_comp_args += ["/openmp"]
597-
else:
598-
ext_comp_args += ["-fopenmp"]
599-
ext_link_args += ["-fopenmp"]
603+
def_macros += [("PYMOL_OPENMP", None)]
604+
if WIN and not is_mingw: # MSVC
605+
ext_comp_args.append("/openmp")
606+
elif MAC: # macOS Clang
607+
ext_comp_args.extend(["-Xpreprocessor", "-fopenmp"])
608+
libs.append("omp")
609+
else: # GCC/Clang on Linux, and MinGW on Windows
610+
ext_comp_args.append("-fopenmp")
611+
ext_link_args.append("-fopenmp")
600612

601613
if options.vmd_plugins:
602614
# VMD plugin support
@@ -701,14 +713,18 @@ def make_launch_script(self):
701713
)
702714

703715
if DEBUG:
704-
ext_comp_args += ["/Z7"]
705-
ext_link_args += ["/DEBUG"]
716+
if is_mingw:
717+
ext_comp_args += ["-g"]
718+
else:
719+
ext_comp_args += ["/Z7"]
720+
ext_link_args += ["/DEBUG"]
706721

707722
libs += [
708723
"opengl32",
709724
]
710-
# TODO: Remove when we move to setup-CMake
711-
ext_comp_args += ["/std:c++17"]
725+
if not is_mingw:
726+
# TODO: Remove when we move to setup-CMake
727+
ext_comp_args += ["/std:c++17"]
712728

713729
if not (MAC or WIN):
714730
libs += [
@@ -814,10 +830,26 @@ def get_packages(base, parent="", r=None):
814830
champ_inc_dirs.append(sysconfig.get_paths()["include"])
815831
champ_inc_dirs.append(sysconfig.get_paths()["platinclude"])
816832

833+
champ_libs = []
834+
817835
if WIN:
818-
# pyconfig.py forces linking against pythonXY.lib on MSVC
819-
py_lib = pathlib.Path(sysconfig.get_paths()["stdlib"]).parent / "libs"
820-
lib_dirs.append(str(py_lib))
836+
if not is_mingw:
837+
# pyconfig.py forces linking against pythonXY.lib on MSVC
838+
py_lib = pathlib.Path(sysconfig.get_paths()["stdlib"]).parent / "libs"
839+
lib_dirs.append(str(py_lib))
840+
else:
841+
ldversion = (
842+
sysconfig.get_config_var("LDVERSION")
843+
or f"{sys.version_info.major}.{sys.version_info.minor}"
844+
)
845+
libs.append(f"python{ldversion}")
846+
champ_libs.append(f"python{ldversion}")
847+
mingw_libdir = (
848+
sysconfig.get_config_var("LIBDIR")
849+
or os.path.join(sys.prefix, "lib")
850+
)
851+
if mingw_libdir and os.path.isdir(mingw_libdir):
852+
lib_dirs.append(mingw_libdir)
821853

822854
ext_modules += [
823855
CMakeExtension(
@@ -834,6 +866,7 @@ def get_packages(base, parent="", r=None):
834866
name="chempy.champ._champ",
835867
sources=get_sources(["contrib/champ"]),
836868
include_dirs=champ_inc_dirs,
869+
libraries=champ_libs,
837870
library_dirs=lib_dirs,
838871
),
839872
]

0 commit comments

Comments
 (0)