[OpenMP][OMPD] libompd must not link libomp (#83119)
Fixes a regression introduced in 91ccd8248.
The code for libompd includes kmp.h for enum kmp_sched. The dependency
to hwloc is not necessary. Avoid the dependency by skipping the
definitions in kmp.h using types from hwloc.h.
Fixes #80750
GitOrigin-RevId: 822142ffdfbe93f213c2c6b3f2aec7fe5f0af072
diff --git a/libompd/src/CMakeLists.txt b/libompd/src/CMakeLists.txt
index 0402a01..ba228d5 100644
--- a/libompd/src/CMakeLists.txt
+++ b/libompd/src/CMakeLists.txt
@@ -13,7 +13,8 @@
add_library (ompd SHARED TargetValue.cpp omp-debug.cpp omp-state.cpp omp-icv.cpp)
-target_link_libraries(ompd omp) # ensure generated import library is created first
+# libompd must not link against libomp, there is no code dependency.
+add_dependencies(ompd omp) # ensure generated import library is created first
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
diff --git a/libompd/src/omp-icv.cpp b/libompd/src/omp-icv.cpp
index 4a2c2b6..0288e96 100644
--- a/libompd/src/omp-icv.cpp
+++ b/libompd/src/omp-icv.cpp
@@ -18,7 +18,9 @@
#include "omp.h"
#include "ompd-private.h"
#include "TargetValue.h"
+#define OMPD_SKIP_HWLOC 1
#include "kmp.h"
+#undef OMPD_SKIP_HWLOC
#include <cstring>
/* The ICVs ompd-final-var and ompd-implicit-var below are for backward
diff --git a/runtime/src/kmp.h b/runtime/src/kmp.h
index 259c57b..121e7e9 100644
--- a/runtime/src/kmp.h
+++ b/runtime/src/kmp.h
@@ -103,7 +103,8 @@
#define KMP_USE_HIER_SCHED KMP_AFFINITY_SUPPORTED
#endif
-#if KMP_USE_HWLOC && KMP_AFFINITY_SUPPORTED
+// OMPD_SKIP_HWLOC used in libompd/omp-icv.cpp to avoid OMPD depending on hwloc
+#if KMP_USE_HWLOC && KMP_AFFINITY_SUPPORTED && !defined(OMPD_SKIP_HWLOC)
#include "hwloc.h"
#ifndef HWLOC_OBJ_NUMANODE
#define HWLOC_OBJ_NUMANODE HWLOC_OBJ_NODE
@@ -689,7 +690,7 @@
extern kmp_SetThreadGroupAffinity_t __kmp_SetThreadGroupAffinity;
#endif /* KMP_OS_WINDOWS */
-#if KMP_USE_HWLOC
+#if KMP_USE_HWLOC && !defined(OMPD_SKIP_HWLOC)
extern hwloc_topology_t __kmp_hwloc_topology;
extern int __kmp_hwloc_error;
#endif