<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/54621>54621</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [OpenMP][OMPD] Build error: 'hwloc.h' file not found at build time despite it being found during configure
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          s-sajid-ali
      </td>
    </tr>
</table>

<pre>
    Hi LLVM-developers, 

`llvm-14.0.0` fails to build due to an issue with the `ompd` library, specifically the `omp-icv.cpp` does not get the location of the `hwloc` header in the list of include paths. 

A full explanation is available at https://github.com/spack/spack/issues/29751, with a short summary included below.

### Error message

Relevant error message: 

```
  >> 26468    FAILED: openmp/libompd/src/CMakeFiles/ompd.dir/omp-icv.cpp.o
     26469    /tmp/sajid/spack-stage/spack-stage-llvm-14.0.0-lmdeejip2qzq4j4ntm7tbgx6pqua2z26/spack-build-lmdeeji/./bin/clang++ --target=x86_64-unknown-linux-gnu -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Dom
              pd_EXPORTS -I/tmp/sajid/spack-stage/spack-stage-llvm-14.0.0-lmdeejip2qzq4j4ntm7tbgx6pqua2z26/spack-src/openmp/libompd/src -I/tmp/sajid/spack-stage/spack-stage-llvm-14.0.0-lmdeejip2qzq4j4ntm7tbgx6pqua2z26/spack-build-lmdeej
              i/runtimes/runtimes-bins/openmp/runtime/src -I/tmp/sajid/spack-stage/spack-stage-llvm-14.0.0-lmdeejip2qzq4j4ntm7tbgx6pqua2z26/spack-src/openmp/runtime/src -std=c++11 -fPIC -fno-semantic-interposition -fvisibility-inlines-h
              idden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wn
              on-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion -Wmisleading-indentation -fdiagnostics-color -ffunction-sections -fdata-sections -Wall -Wcast-qual -Wformat-pedantic -Wimplicit-
              fallthrough -Wsign-compare -Wno-extra -Wno-pedantic -std=c++14 -std=c++11 -O3 -DNDEBUG -fPIC -MD -MT openmp/libompd/src/CMakeFiles/ompd.dir/omp-icv.cpp.o -MF openmp/libompd/src/CMakeFiles/ompd.dir/omp-icv.cpp.o.d -o openmp
              /libompd/src/CMakeFiles/ompd.dir/omp-icv.cpp.o -c /tmp/sajid/spack-stage/spack-stage-llvm-14.0.0-lmdeejip2qzq4j4ntm7tbgx6pqua2z26/spack-src/openmp/libompd/src/omp-icv.cpp
     26470    In file included from /tmp/sajid/spack-stage/spack-stage-llvm-14.0.0-lmdeejip2qzq4j4ntm7tbgx6pqua2z26/spack-src/openmp/libompd/src/omp-icv.cpp:21:
  >> 26471    /tmp/sajid/spack-stage/spack-stage-llvm-14.0.0-lmdeejip2qzq4j4ntm7tbgx6pqua2z26/spack-src/openmp/runtime/src/kmp.h:96:10: fatal error: 'hwloc.h' file not found
     26472    #include "hwloc.h"
     26473             ^~~~~~~~~
     26474    1 error generated.
```

This occurs, despite the fact that spack passes `'-DLIBOMP_USE_HWLOC:BOOL=ON' '-DLIBOMP_HWLOC_INSTALL_DIR:STRING=/home/sajid/packages/spack/opt/spack/linux-ubuntu20.04-zen2/gcc-11.2.0/hwloc-2.7.0-5ttjykgyd7bxnhegnydeesc53ufojjmb' ` and the fact that `hwloc` is indeed found during configuration (for `runtimes-bins`) : 
```
-- Looking for hwloc.h
-- Looking for hwloc.h - found
-- Looking for hwloc_topology_init in /home/sajid/packages/spack/opt/spack/linux-ubuntu20.04-zen2/gcc-11.2.0/hwloc-2.7.0-5ttjykgyd7bxnhegnydeesc53ufojjmb/lib/libhwloc.so
-- Looking for hwloc_topology_init in /home/sajid/packages/spack/opt/spack/linux-ubuntu20.04-zen2/gcc-11.2.0/hwloc-2.7.0-5ttjykgyd7bxnhegnydeesc53ufojjmb/lib/libhwloc.so - found
```

For reference, the generated build recipe (`spack-build-lmdeeji/runtimes/runtimes-bins/build.ninja`) for the failing file is: 
```
build openmp/libompd/src/CMakeFiles/ompd.dir/omp-icv.cpp.o: CXX_COMPILER__ompd_Release /tmp/sajid/spack-stage/spack-stage-llvm-14.0.0-lmdeejip2qzq4j4ntm7tbgx6pqua2z26/spack-src/openmp/libompd/src/omp-icv.cpp || cmake_object_order_depends_target_ompd
  DEFINES = -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Dompd_EXPORTS
  DEP_FILE = openmp/libompd/src/CMakeFiles/ompd.dir/omp-icv.cpp.o.d
  FLAGS = -std=c++11 -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion -Wmisleading-indentation -fdiagnostics-color -ffunction-sections -fdata-sections -Wall -Wcast-qual -Wformat-pedantic -Wimplicit-fallthrough -Wsign-compare -Wno-extra -Wno-pedantic -std=c++14 -std=c++11 -O3 -DNDEBUG -fPIC
  INCLUDES = -I/tmp/sajid/spack-stage/spack-stage-llvm-14.0.0-lmdeejip2qzq4j4ntm7tbgx6pqua2z26/spack-src/openmp/libompd/src -I/tmp/sajid/spack-stage/spack-stage-llvm-14.0.0-lmdeejip2qzq4j4ntm7tbgx6pqua2z26/spack-build-lmdeeji/runtimes/runtimes-bins/openmp/runtime/src -I/tmp/sajid/spack-stage/spack-stage-llvm-14.0.0-lmdeejip2qzq4j4ntm7tbgx6pqua2z26/spack-src/openmp/runtime/src
  OBJECT_DIR = openmp/libompd/src/CMakeFiles/ompd.dir
  OBJECT_FILE_DIR = openmp/libompd/src/CMakeFiles/ompd.dir
  TARGET_COMPILE_PDB = openmp/libompd/src/CMakeFiles/ompd.dir/
  TARGET_PDB = openmp/libompd/src/libompd.pdb
```

### Further diagnosis

The recipe for `ompd` has the following includes: 
```
include_directories (
        ${CMAKE_CURRENT_SOURCE_DIR}
        ${LIBOMP_INCLUDE_DIR}
        ${LIBOMP_SRC_DIR}
)
```

per [`openmp/libompd/src/CMakeLists.txt`](https://github.com/llvm/llvm-project/blob/main/openmp/libompd/src/CMakeLists.txt). 

Now, `LIBOMP_INCLUDE_DIR` is set in [`openmp/runtime/src/CMakeLists.txt`](https://github.com/llvm/llvm-project/blob/main/openmp/runtime/src/CMakeLists.txt) to be only that directory (via `CMAKE_CURRENT_BINARY_DIR`) and `LIBOMP_SRC_DIR` is set in [`/main/openmp/runtime/CMakeLists.txt`](https://github.com/llvm/llvm-project/blob/main/openmp/runtime/CMakeLists.txt) to be `${LIBOMP_BASE_DIR}/src`.

> perhaps a missing dependency in the cmake target for ompd?

In light of the above this is probably the cause of the issue as the includes set for `omp-icv.cpp` expand as they are programmed to, but they do not contain the path for `hwloc`. I think the set of includes for `ompd` (and hence `omp-icv.cpp`) should also include `LIBOMP_HWLOC_INSTALL_DIR/include`. 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzlWVtzozoS_jXOiwrKxrf4IQ--zvGuE6ccZ8_sEyVAgBKQGCSSeH79dguIIfFkzk7OpGZnUwQDarX6ptbXkieDw8UfnGw2_7q0AvbAEpmxXHWcOel0F53utLqPuknykFq9gd21u_BGQsoTRbQkXsGTgAQFwxcqCFcKnh-5jomOGQFamWYBdkm4l9P8gLxVxnwecp8myaFBZnH_wfazDKkDyRQRUpOIaUOSSJ9qLgWRYd0lfoSPSBwzGrCccFFScqWRigs_KQJGMqpjZbcUmpKwSBLCnrKEipItV4Q-gFbUSxihmsRaZ6rTn3acFVwRKFR4ti9TeFEZ9e8bv0ZnMNrKmY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