mesonbuild / meson

The Meson Build System
http://mesonbuild.com
Apache License 2.0
5.3k stars 1.52k forks source link

Meson fails to configure OpenMP when using Clang from MacPorts #13145

Open lpsinger opened 3 weeks ago

lpsinger commented 3 weeks ago

Describe the bug Meson fails to detect OpenMP with Clang from MacPorts.

To Reproduce

  1. Install MacPorts.

  2. Install the MacPorts version of Clang by running sudo port install clang-18.

  3. Place the following in the file meson.build:

    project('example', 'c')
    dependency('openmp')
  4. Configure the project, and observe the failure:

    $ CC=clang-mp-18 meson setup build
    The Meson build system
    Version: 1.4.0
    Source dir: /private/tmp
    Build dir: /private/tmp/build
    Build type: native build
    Project name: example
    Project version: undefined
    C compiler for the host machine: clang-mp-18 (clang 18.1.4 "clang version 18.1.4")
    C linker for the host machine: clang-mp-18 ld64 1053.12
    Host machine cpu family: x86_64
    Host machine cpu: x86_64
    WARNING: OpenMP found but omp.h missing.
    Run-time dependency OpenMP found: NO (tried system)
    
    meson.build:2:0: ERROR: Dependency "openmp" not found, tried system
    
    A full log can be found at /private/tmp/build/meson-logs/meson-log.txt

Here is the log file: meson-log.txt

The check that is failing is a test compilation of the following testfile.c, compiled with the command clang-mp-18 testfile.c -E -P -P -O0 -Werror=implicit-function-declaration, i.e., without the command line option -fopenmp:

#ifdef __has_include
  #if !__has_include("omp.h")
    #error "Header 'omp.h' could not be found"
  #endif
#else
  #include <omp.h>
#endif

This test would have succeeded if Meson had added the flag -fopenmp; in some compilers such as this one, omp.h is not findable unless the command-line flag -fopenmp is present.

Expected behavior Meson should add the -fopenmp flag when doing this test, and the test should succeed.

system parameters

dcbaker commented 3 weeks ago

If the compiler is identifying itself as an Apple compiler (ie, if Apple is in the output of clang --version), then Meson considers OpenMP unsupported. See: https://github.com/mesonbuild/meson/issues/7435 for more information.

lpsinger commented 3 weeks ago

Indeed, it does:

$ clang-mp-18 --version
clang version 18.1.4
Target: x86_64-apple-darwin23.4.0
Thread model: posix
InstalledDir: /opt/local/libexec/llvm-18/bin
dcbaker commented 3 weeks ago

That looks like we're incorrectly identifying a "vanilla" clang as an "apple" clang. The latter of which really means "the Clang Apple ships with XCode", so we should fix our detection code to detect that as a vanilla clang and then OpenMP should just work.

edit: Strangly though we look for "Apple" (Case sensitive) in the output, and the output you have is reporting "apple", so OpenMP should just work