From a2d577dce5ac43d0178025361c460d32e96dd2d9 Mon Sep 17 00:00:00 2001
From: Alexis Montoison <alexis.montoison@polymtl.ca>
Date: Fri, 26 Jan 2024 01:57:48 -0500
Subject: [PATCH 1/2] [Meson] Update the detection of HWLOC

---
 README.meson      |  3 +++
 meson.build       | 13 ++++++++-----
 meson_options.txt | 15 +++++++++++++++
 3 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/README.meson b/README.meson
index 98594c05b8..b69d1b58c2 100644
--- a/README.meson
+++ b/README.meson
@@ -35,6 +35,7 @@ Currently supported options with their default value:
 * `-Dlibspmf=spmf`: SPMF library against which to link;
 * `-Dlibpastix=pastix`: PASTIX library against which to link;
 * `-Dlibampl=ampl`: AMPL library against which to link;
+* `-Dlibhwloc=hwloc`: HWLOC library against which to link;
 * `-Dlibblas_path=[]`: additional directories to search for the BLAS library;
 * `-Dliblapack_path=[]`: additional directories to search for the LAPACK library;
 * `-Dlibmetis_path=[]`: additional directories to search for the METIS library;
@@ -46,6 +47,8 @@ Currently supported options with their default value:
 * `-Dlibpastix_path=[]`: additional directories to search for the PASTIX library;
 * `-Dlibmumps_path=[]`: additional directories to search for the MUMPS libraries;
 * `-Dlibampl_path=[]`: additional directories to search for the AMPL library library;
+* `-Dlibhwloc_path=[]`: Additional directory to search for the HWLOC library;
+* `-Dlibhwloc_include=[]`: Additional directories to search for the HWLOC header files;
 * `-Dlibhsl_modules[]`: additional directories to search for the HSL modules;
 * `-Dlibmetis_version=5`: version of the METIS library;
 * `-Dgalahad_int64=false`: compile GALAHAD with 64-bit integer.
diff --git a/meson.build b/meson.build
index 4e2cb97781..a3859e9e5d 100644
--- a/meson.build
+++ b/meson.build
@@ -93,6 +93,7 @@ libpastix_name = get_option('libpastix')
 libampl_name = get_option('libampl')
 libcutest_single_name = get_option('libcutest_single')
 libcutest_double_name = get_option('libcutest_double')
+libhwloc_name = get_option('libhwloc')
 
 libmumps_path = get_option('libmumps_path')
 libblas_path = get_option('libblas_path')
@@ -106,9 +107,11 @@ libpastix_path = get_option('libpastix_path')
 libampl_path = get_option('libampl_path')
 libcutest_single_path = get_option('libcutest_single_path')
 libcutest_double_path = get_option('libcutest_double_path')
+libhwloc_path = get_option('libhwloc_path')
 
 libmetis_version = get_option('libmetis_version')
 
+libhwloc_include = get_option('libhwloc_include')
 libcutest_single_modules = get_option('libcutest_single_modules')
 libcutest_double_modules = get_option('libcutest_double_modules')
 libhsl_modules = get_option('libhsl_modules')
@@ -127,7 +130,9 @@ libpastix = fc.find_library(libpastix_name, dirs : libpastix_path, required : fa
 libsmumps = fc.find_library('smumps', dirs : libmumps_path, required : false)
 libdmumps = fc.find_library('dmumps', dirs : libmumps_path, required : false)
 libampl = fc.find_library(libampl_name, dirs : libampl_path, required : false)
+libhwloc = fc.find_library(libhwloc_name, dirs : libhwloc_path, required : false)
 lm = cc.find_library('m', required : false)
+libmpi = dependency('mpi', language : 'fortran', required : false)
 
 # OpenMP
 if fc.get_id() == 'nvidia_hpc'
@@ -156,9 +161,6 @@ elif cxx.get_id() == 'intel-cl' or cxx.get_id() == 'intel-llvm-cl'
   add_global_arguments('/Qopenmp', language : 'cpp')
 endif
 
-libmpi = dependency('mpi', language : 'fortran', required : false)
-libhwloc = dependency('hwloc', required : false)
-
 libgalahad_single_deps = [libsmumps, libcutest_single]
 libgalahad_double_deps = [libdmumps, libcutest_double]
 libgalahad_deps = [libblas, liblapack, libmetis, libhsl,
@@ -211,7 +213,7 @@ galahad_python_tests = []
 # Folders that contain headers and Fortran modules
 libgalahad_include = [include_directories('include'),
                       include_directories('src/dum/include'),
-                      include_directories('src/ampl')] + libhsl_modules
+                      include_directories('src/ampl')] + libhsl_modules + libhwloc_include
 
 libgalahad_single_include = libgalahad_include + libcutest_single_modules
 libgalahad_double_include = libgalahad_include + libcutest_double_modules
@@ -223,7 +225,8 @@ else
 endif
 
 # HWLOC
-if libhwloc.found()
+has_hwloch = cc.has_header('hwloc.h', include_directories : libhwloc_include)
+if libhwloc.found() and has_hwloch
   add_global_arguments('-DSPRAL_HAVE_HWLOC', language : 'cpp')
 else
   add_global_arguments('-DSPRAL_NO_HWLOC', language : 'cpp')
diff --git a/meson_options.txt b/meson_options.txt
index 518455bd9b..e15c6435ad 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -93,6 +93,11 @@ option('libampl',
        value : 'ampl',
        description : 'AMPL library against which to link')
 
+option('libhwloc',
+       type : 'string',
+       value : 'hwloc',
+       description : 'HWLOC library against which to link')
+
 option('libblas_path',
        type : 'array',
        value : [],
@@ -153,6 +158,16 @@ option('libampl_path',
        value : [],
        description : 'Additional directories to search for the AMPL library library')
 
+option('libhwloc_path',
+       type : 'array',
+       value : [],
+       description : 'Additional directory to search for the HWLOC library')
+
+option('libhwloc_include',
+       type : 'array',
+       value : [],
+       description : 'Additional directories to search for the HWLOC header files')
+
 option('libhsl_modules',
        type : 'array',
        value : [],

From fafc7382276579f45c4200e6e84fdf83734a668f Mon Sep 17 00:00:00 2001
From: Alexis Montoison <35051714+amontoison@users.noreply.github.com>
Date: Fri, 26 Jan 2024 02:06:33 -0500
Subject: [PATCH 2/2] Update README.meson

---
 README.meson | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/README.meson b/README.meson
index b69d1b58c2..14e974cdf7 100644
--- a/README.meson
+++ b/README.meson
@@ -47,7 +47,7 @@ Currently supported options with their default value:
 * `-Dlibpastix_path=[]`: additional directories to search for the PASTIX library;
 * `-Dlibmumps_path=[]`: additional directories to search for the MUMPS libraries;
 * `-Dlibampl_path=[]`: additional directories to search for the AMPL library library;
-* `-Dlibhwloc_path=[]`: Additional directory to search for the HWLOC library;
+* `-Dlibhwloc_path=[]`: Additional directories to search for the HWLOC library;
 * `-Dlibhwloc_include=[]`: Additional directories to search for the HWLOC header files;
 * `-Dlibhsl_modules[]`: additional directories to search for the HSL modules;
 * `-Dlibmetis_version=5`: version of the METIS library;