python-fcl icon indicating copy to clipboard operation
python-fcl copied to clipboard

Building on OSX Catalina - Resolving math.h errors

Open weshoke opened this issue 4 years ago • 1 comments

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}
)

weshoke avatar Oct 14 '21 17:10 weshoke

@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.

mjd3 avatar Jul 09 '22 04:07 mjd3