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

Building on OSX Catalina - Resolving math.h errors #37

Open
weshoke opened this issue Oct 14, 2021 · 1 comment
Open

Building on OSX Catalina - Resolving math.h errors #37

weshoke opened this issue Oct 14, 2021 · 1 comment

Comments

@weshoke
Copy link

weshoke commented Oct 14, 2021

FWIW, I had a lot of trouble building on OSX 10.15. The problem ended up being the include paths to the SDK included by setuptools in the CFLAGS variable. Here are my changes to setup.py to fix the issue:

import os
import sys

from setuptools.command.build_ext import build_ext
from setuptools import Extension, setup
from Cython.Build import cythonize

INSTALL_PREFIX_WIN = "deps\\install"


def is_nix_platform(platform):
    for prefix in ["darwin", "linux", "bsd"]:
        if prefix in sys.platform:
            return True
    return False


def get_include_dirs():
    if is_nix_platform(sys.platform):
        include_dirs = [
            "/usr/include",
            "/usr/local/include",
            "/usr/include/eigen3",
            "/usr/local/include/eigen3",
        ]

        if "CPATH" in os.environ:
            include_dirs += os.environ["CPATH"].split(":")

    elif sys.platform == "win32":
        include_dirs = [
            f"{INSTALL_PREFIX_WIN}\\include",
            f"{INSTALL_PREFIX_WIN}\\include\\eigen3",
        ]
    else:
        raise NotImplementedError(sys.platform)

    # get the numpy include path from numpy
    import numpy

    include_dirs.append(numpy.get_include())
    return include_dirs


def get_libraries_dir():
    if is_nix_platform(sys.platform):
        lib_dirs = ["/usr/lib", "/usr/local/lib"]

        if "LD_LIBRARY_PATH" in os.environ:
            lib_dirs += os.environ["LD_LIBRARY_PATH"].split(":")
        return lib_dirs
    if sys.platform == "win32":
        return [f"{INSTALL_PREFIX_WIN}\\lib"]

    raise NotImplementedError(sys.platform)


def get_libraries():
    libraries = ["fcl", "octomap"]
    if sys.platform == "win32":
        libraries.extend(["octomath", "ccd", "vcruntime"])
    return libraries


class custom_build_ext(build_ext):
    def build_extensions(self):
        compiler_so_new = []
        for v in self.compiler.compiler_so:
            if "MacOSX10.15" in v:
                pass
            else:
                compiler_so_new.append(v)

        self.compiler.compiler_so = compiler_so_new
        build_ext.build_extensions(self)


setup(
    ext_modules=cythonize(
        [
            Extension(
                "fcl.fcl",
                ["src/fcl/fcl.pyx"],
                include_dirs=get_include_dirs(),
                library_dirs=get_libraries_dir(),
                libraries=get_libraries(),
                language="c++",
                extra_compile_args=["-std=c++11"],
            )
        ],
    ),
    cmdclass={"build_ext": custom_build_ext}
)
@mjd3
Copy link

mjd3 commented Jul 9, 2022

@weshoke sorry for the delay in responding; hoping your issue would be resolved with the new macos wheels available on pypi? If not feel free to follow up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants