diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c09339aa..066f7df93 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,7 @@ target_include_directories(${TARGET_NAME} PUBLIC target_link_directories(${TARGET_NAME} PUBLIC ${ALL_LIB_DIR} + ${PYTHON_LIBRARIES} ) if (DEFINED ALL_EXT_OBJ) diff --git a/setup.py b/setup.py index 9e367e0fd..76b82ed1a 100644 --- a/setup.py +++ b/setup.py @@ -146,7 +146,7 @@ def __init__(self, self.sources = sources self.include_dirs = include_dirs self.include_dirs.append(sysconfig.get_paths()['include']) - if sys.platform.startswith('linux'): + 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 @@ -176,9 +176,14 @@ def build_cmake(self, ext): 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)) - py_lib = pathlib.Path(sysconfig.get_paths()['stdlib']).parent / 'libs' - 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()) @@ -187,12 +192,23 @@ def concat_paths(paths): all_src = concat_paths(all_files) all_defs = ''.join(mac[0] + ";" for mac in ext.define_macros) all_libs = ''.join(f"{lib};" for lib in ext.libraries) - all_ext_link = ''.join(f"{arg};" for arg in ext.extra_link_args) + 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" cmake_args = [ @@ -221,6 +237,7 @@ def concat_paths(paths): 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: @@ -625,10 +642,11 @@ def get_packages(base, parent='', r=None): extra_objects=ext_objects, ), - Extension( + CMakeExtension( name="chempy.champ._champ", sources=get_sources(['contrib/champ']), include_dirs=champ_inc_dirs, + library_dirs=lib_dirs, ), ]