From 61fc7ea7d2b41ed52dd578bea90aa20b781e9fed Mon Sep 17 00:00:00 2001 From: Jarrett Johnson Date: Fri, 10 May 2024 20:50:43 -0400 Subject: [PATCH] mac --- CMakeLists.txt | 5 +++- layer1/CGO.cpp | 2 +- layer1/CGO.h | 2 +- layer2/RepCartoon.cpp | 8 +++---- setup.py | 54 +++++++++++++++---------------------------- 5 files changed, 28 insertions(+), 43 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 066f7df93..22a699711 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,9 @@ add_library(${TARGET_NAME} SHARED if (MSVC) target_compile_options(${TARGET_NAME} PRIVATE "/MP") set_target_properties(${TARGET_NAME} PROPERTIES SUFFIX ".pyd") +elseif (APPLE) + set_target_properties(${TARGET_NAME} PROPERTIES SUFFIX ${SHARED_SUFFIX}) + target_compile_options(${TARGET_NAME} PRIVATE ${ALL_COMP_ARGS}) else() target_compile_options(${TARGET_NAME} PRIVATE ${ALL_COMP_ARGS}) endif() @@ -24,7 +27,6 @@ target_include_directories(${TARGET_NAME} PUBLIC target_link_directories(${TARGET_NAME} PUBLIC ${ALL_LIB_DIR} - ${PYTHON_LIBRARIES} ) if (DEFINED ALL_EXT_OBJ) @@ -42,6 +44,7 @@ else() target_link_libraries(${TARGET_NAME} ${ALL_LIB} ${ALL_EXT_LINK} + "-undefined dynamic_lookup" ) endif() diff --git a/layer1/CGO.cpp b/layer1/CGO.cpp index ff9dbf543..e5aaa0594 100644 --- a/layer1/CGO.cpp +++ b/layer1/CGO.cpp @@ -145,7 +145,7 @@ void AssignNewPickColor(CGO* cgo, PickColorManager* pickmgr, pickmgr->colorNext(color, context, index, bond); } -int CGO_sz[] = { +std::size_t CGO_sz[] = { CGO_NULL_SZ, CGO_NULL_SZ, CGO_BEGIN_SZ, diff --git a/layer1/CGO.h b/layer1/CGO.h index 023ed6817..e3146f429 100644 --- a/layer1/CGO.h +++ b/layer1/CGO.h @@ -272,7 +272,7 @@ inline uchar CLIP_NORMAL_VALUE(float cv){ return ((cv>1.f) ? 127 : #define CGO_ACCESSIBILITY_ARRAY 0x10 #define CGO_TEX_COORD_ARRAY 0x20 -extern int CGO_sz[]; +extern std::size_t CGO_sz[]; size_t CGO_sz_size(); // I think CGO rendering functions should not modify CGO's, so the diff --git a/layer2/RepCartoon.cpp b/layer2/RepCartoon.cpp index a2c89b454..813d3af3c 100644 --- a/layer2/RepCartoon.cpp +++ b/layer2/RepCartoon.cpp @@ -1001,7 +1001,7 @@ static void do_ring(PyMOLGlobals * G, nuc_acid_data *ndata, int n_atom, color2 = ColorGet(G, g2_ai->color); } CGOPickColor(cgo, g1, g1_ai->masked ? cPickableNoPick : cPickableAtom); - Pickable pickcolor2 = { g2, g2_ai->masked ? cPickableNoPick : cPickableAtom }; + Pickable pickcolor2 = { static_cast(g2), g2_ai->masked ? cPickableNoPick : cPickableAtom }; float axis[3]; subtract3f(g2p, g1p, axis); CGOColorv(cgo, color1); @@ -1046,7 +1046,7 @@ static void do_ring(PyMOLGlobals * G, nuc_acid_data *ndata, int n_atom, color2 = ColorGet(G, bas_ai->color); } CGOPickColor(cgo, sugar_at, sug_ai->masked ? cPickableNoPick : cPickableAtom); - Pickable pickcolor2 = { base_at, bas_ai->masked ? cPickableNoPick : cPickableAtom }; + Pickable pickcolor2 = { static_cast(base_at), bas_ai->masked ? cPickableNoPick : cPickableAtom }; float axis[3]; subtract3f(cs->coordPtr(bas), cs->coordPtr(sug), axis); CGOColorv(cgo, color1); @@ -1103,7 +1103,7 @@ static void do_ring(PyMOLGlobals * G, nuc_acid_data *ndata, int n_atom, } CGOPickColor(cgo, sugar_at, sug_ai->masked ? cPickableNoPick : cPickableAtom); - Pickable pickcolor2 = { base_at, bas_ai->masked ? cPickableNoPick : cPickableAtom }; + Pickable pickcolor2 = { static_cast(base_at), bas_ai->masked ? cPickableNoPick : cPickableAtom }; float axis[3]; subtract3f(cs->coordPtr(bas), v_outer, axis); CGOColorv(cgo, color1); @@ -1347,7 +1347,7 @@ static void do_ring(PyMOLGlobals * G, nuc_acid_data *ndata, int n_atom, color1 = color2 = color; } CGOPickColor(cgo, atix[i], ai_i[i]->masked ? cPickableNoPick : cPickableAtom); - Pickable pickcolor2 = { atix[ii], ai_i[ii]->masked ? cPickableNoPick : cPickableAtom }; + Pickable pickcolor2 = { static_cast(atix[ii]), ai_i[ii]->masked ? cPickableNoPick : cPickableAtom }; float axis[3]; subtract3f(v_i[ii], v_i[i], axis); CGOColorv(cgo, color1); diff --git a/setup.py b/setup.py index 76b82ed1a..ea5fa310c 100644 --- a/setup.py +++ b/setup.py @@ -145,9 +145,6 @@ def __init__(self, super().__init__(name, sources=[]) self.sources = sources self.include_dirs = include_dirs - self.include_dirs.append(sysconfig.get_paths()['include']) - if sys.platform.startswith('linux') or sys.platform.startswith('darwin'): - self.include_dirs.append(sysconfig.get_paths()['platinclude']) self.libraries = libraries self.library_dirs = library_dirs self.define_macros = define_macros @@ -157,6 +154,11 @@ def __init__(self, class build_ext_pymol(build_ext): + def initialize_options(self) -> None: + super().initialize_options() + if DEBUG and not WIN: + self.debug = False + def run(self): for ext in self.extensions: self.build_cmake(ext) @@ -169,25 +171,16 @@ def build_cmake(self, ext): name_split = ext.name.split('.') target_name = name_split[-1] build_temp = pathlib.Path(self.build_temp) / target_name - print(f"BUILDTMP {build_temp}") build_temp.mkdir(parents=True, exist_ok=True) extdir = pathlib.Path(self.get_ext_fullpath(ext.name)) - extdir.mkdir(parents=True, exist_ok=True) + if not sys.platform == "darwin": + extdir.mkdir(parents=True, exist_ok=True) def concat_paths(paths): return ''.join(path.replace('\\', '/') + ";" for path in paths) - if not MAC: - py_lib = pathlib.Path(sysconfig.get_paths()['stdlib']).parent / 'libs' - else: - py_lib = pathlib.Path(sysconfig.get_paths()['stdlib']) - #ext.library_dirs.append(str(py_lib)) - - if MAC: - ext.libraries.append('python' + sysconfig.get_config_var('VERSION')) config = 'Debug' if DEBUG else 'Release' lib_output_dir = str(extdir.parent.absolute()) - print(f"LIB OUTPUT DIR: {lib_output_dir}") all_files = ext.sources all_src = concat_paths(all_files) all_defs = ''.join(mac[0] + ";" for mac in ext.define_macros) @@ -195,22 +188,13 @@ def concat_paths(paths): all_ext_link = ' '.join(ext.extra_link_args) all_comp_args = ''.join(f"{arg};" for arg in ext.extra_compile_args) all_lib_dirs = concat_paths(ext.library_dirs) - #all_lib_dirs = ' '.join(ext.library_dirs) - #all_lib_dirs = [] - #for lib_dir in ext.library_dirs: - # all_lib_dirs.append('-L"{}"'.format(lib_dir)) - # all_lib_dirs.append('-Wl,-rpath,"{}"'.format(lib_dir)) - #all_lib_dirs = ' '.join(all_lib_dirs) all_inc_dirs = concat_paths(ext.include_dirs) all_ext_objs = concat_paths(ext.extra_objects) - print(all_lib_dirs) - print(all_libs) - #print(pathlib.Path(sysconfig.get_paths()['stdlib']).parent) - #exit(1) - lib_mode = "RUNTIME" if WIN else "LIBRARY" + shared_suffix = sysconfig.get_config_var('EXT_SUFFIX') + cmake_args = [ f"-DTARGET_NAME={target_name}", f"-DCMAKE_{lib_mode}_OUTPUT_DIRECTORY={lib_output_dir}", @@ -222,10 +206,8 @@ def concat_paths(paths): f"-DALL_LIB={all_libs}", f"-DALL_COMP_ARGS={all_comp_args}", f"-DALL_EXT_LINK={all_ext_link}", + f"-DSHARED_SUFFIX={shared_suffix}" ] - # print(sys.platform) - # print(f"ALL INC DIR: {all_inc_dirs}") - # print(sysconfig.get_paths()['platinclude']) if all_ext_objs: cmake_args.append("-DALL_EXT_OBJ=" + all_ext_objs) @@ -236,8 +218,6 @@ def concat_paths(paths): cpu_count = os.cpu_count() or 1 build_args += [f'-j{cpu_count}'] - print(cmake_args) - #exit(1) os.chdir(str(build_temp)) self.spawn(['cmake', str(cwd)] + cmake_args) if not self.dry_run: @@ -478,9 +458,9 @@ def make_launch_script(self): if options.osx_frameworks: ext_link_args += [ - "-framework", "OpenGL", + "-framework OpenGL", ] + (not options.no_glut) * [ - "-framework", "GLUT", + "-framework GLUT", ] def_macros += [ ("_PYMOL_OSX", None), @@ -623,11 +603,14 @@ def get_packages(base, parent='', r=None): for base in ['modules'] for x in get_packages(base)) +# Python includes +inc_dirs.append(sysconfig.get_paths()['include']) +inc_dirs.append(sysconfig.get_paths()['platinclude']) + champ_inc_dirs = ['contrib/champ'] +champ_inc_dirs.append(sysconfig.get_paths()['include']) +champ_inc_dirs.append(sysconfig.get_paths()['platinclude']) -if sys.platform == 'linux': - inc_dirs.append(sysconfig.get_paths()['platinclude']) - champ_inc_dirs.append(sysconfig.get_paths()['platinclude']) ext_modules += [ CMakeExtension( @@ -646,7 +629,6 @@ def get_packages(base, parent='', r=None): name="chempy.champ._champ", sources=get_sources(['contrib/champ']), include_dirs=champ_inc_dirs, - library_dirs=lib_dirs, ), ]