storpipfugl / pykdtree

Fast kd-tree implementation in Python
GNU Lesser General Public License v3.0
221 stars 46 forks source link

Add logic to detect libomp installs in homebrew and macports on macOS #83

Closed rayg-ssec closed 1 year ago

rayg-ssec commented 1 year ago

When building using Clang, libomp is the preferred OpenMP library, though it's a separate build from the main compiler.

macOS defaults to clang (though GCC can be made available), but unless libomp is installed (often but not always through Homebrew or MacPorts), building without OMP is the baseline.

In a manual install of libomp, you need slightly different compile flags -Xpreprocessor -fopenmp and appropriate linkage to libomp, with include and library search paths set in CFLAGS and LDFLAGS environment variables.

This patch attempts to retain backward compatible behavior, but extend USE_OMP beyond 1/0 to "clang" or "omp", "gcc" or "gomp" to be more specific with respect to compiler options.

It also, on macOS, attempts to detect libomp if it is installed via brew or port by listing the manifest of the installed packages, and generating CFLAGS and LDFLAGS that would have been needed to satisfy -Xpreprocessor -fopenmp and -lomp compiler/linker directives. If USE_OMP is not specified, it will probe to see if USE_OMP=omp can be inferred by checking for libomp include and library paths.

This means pip install . on macOS systems with libomp available should succeed with OpenMP enabled by default, while permitting non-macOS systems using clang to set CFLAGS/LDFLAGS and USE_OMP=omp . USE_OMP=0 should also still be obeyed. A brief debug line is included when -v is enabled on the pip install.

rayg-ssec commented 1 year ago

The most recent commits refactor it down to a lot of what you've recommended. I also addressed the "I know what I'm doing and don't want args probed" expert user case - brew and ports checks are only done in probe mode.

djhoese commented 1 year ago

Did you see my pull request here: https://github.com/rayg-ssec/pykdtree/pull/1

rayg-ssec commented 1 year ago

Did you see my pull request here: https://github.com/rayg-ssec/pykdtree/pull/1

No, ironically I decided to add the GitHub app to my phone and tablet today in hopes of getting better notifications and work queue. Didn't see the PR until you pointed it out.

rayg-ssec commented 1 year ago

The merge of your changes ran with no issue through my 5 local test cases. The README update is much appreciated.

(I still think reads-like-a-novel is easier to follow than reads-like-a-newspaper however!)