Skip to content

Commit 4f9fe46

Browse files
committed
doxy: add a section about building with GNU Make and CMake
The GNU Make stuff is moved from the API example, and CMake is added thanks to Florent Pruvost's example at https://gitlab.inria.fr/solverstack/distrib/-/tree/master/cmake/test/hwloc Refs #565 Signed-off-by: Brice Goglin <[email protected]> (cherry picked from commit cd3a1a7)
1 parent 30aa5e5 commit 4f9fe46

File tree

3 files changed

+78
-19
lines changed

3 files changed

+78
-19
lines changed

NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ Version 2.10.1
2323
* Add bandwidths between subdevices in the LevelZero XeLinkBandwidth
2424
matrix.
2525
* Fix CUDA/OpenCL test source path in Windows CMake.
26+
* Add section "Compiling software on top of hwloc's C API" in the
27+
documentation with examples for GNU Make and CMake,
28+
thanks to Florent Pruvost for the help.
2629

2730

2831
Version 2.10.0

README

+2-8
Original file line numberDiff line numberDiff line change
@@ -418,14 +418,8 @@ return 0;
418418
}
419419

420420
hwloc provides a pkg-config executable to obtain relevant compiler and linker
421-
flags. For example, it can be used thusly to compile applications that utilize
422-
the hwloc library (assuming GNU Make):
423-
424-
CFLAGS += $(shell pkg-config --cflags hwloc)
425-
LDLIBS += $(shell pkg-config --libs hwloc)
426-
427-
hwloc-hello: hwloc-hello.c
428-
$(CC) hwloc-hello.c $(CFLAGS) -o hwloc-hello $(LDLIBS)
421+
flags. See Compiling software on top of hwloc's C API for details on building
422+
program on top of hwloc's API using GNU Make or CMake.
429423

430424
On a machine 2 processor packages -- each package of which has two processing
431425
cores -- the output from running hwloc-hello could be something like the

doc/hwloc.doxy

+73-11
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<li> Chapters
3232
<ul>
3333
<li> \ref installation
34+
<li> \ref useapi
3435
<li> \ref termsanddefs
3536
<li> \ref tools
3637
<li> \ref envvar
@@ -365,16 +366,8 @@ tree.
365366
\include examples/hwloc-hello.c
366367

367368
hwloc provides a \c pkg-config executable to obtain relevant compiler
368-
and linker flags. For example, it can be used thusly to compile
369-
applications that utilize the hwloc library (assuming GNU Make):
370-
371-
\verbatim
372-
CFLAGS += $(shell pkg-config --cflags hwloc)
373-
LDLIBS += $(shell pkg-config --libs hwloc)
374-
375-
hwloc-hello: hwloc-hello.c
376-
$(CC) hwloc-hello.c $(CFLAGS) -o hwloc-hello $(LDLIBS)
377-
\endverbatim
369+
and linker flags. See \ref useapi for details on building program
370+
on top of hwloc's API using GNU Make or CMake.
378371

379372
On a machine 2 processor packages -- each package of
380373
which has two processing cores -- the output from running \c
@@ -590,9 +583,78 @@ or GNU Autotools.
590583

591584

592585

586+
587+
\page useapi Compiling software on top of hwloc's C API
588+
589+
A program using the hwloc C API (for instance with <tt>hwloc-hello.c</tt>
590+
presented in \ref interface_example) may be built with standard
591+
development tools.
592+
<tt>pkg-config</tt> provides easy ways to retrieve the required compiler
593+
and linker flags as described below, but it is not mandatory.
594+
595+
596+
\section useapi_gnumake Compiling on top of hwloc's C API with GNU Make
597+
598+
Here's an example of Makefile for building <tt>hwloc-hello.c</tt>
599+
with GNU Make:
600+
601+
\verbatim
602+
CFLAGS += $(shell pkg-config --cflags hwloc)
603+
LDLIBS += $(shell pkg-config --libs hwloc)
604+
605+
hwloc-hello: hwloc-hello.c
606+
$(CC) hwloc-hello.c $(CFLAGS) -o hwloc-hello $(LDLIBS)
607+
\endverbatim
608+
609+
610+
\section useapi_cmake Compiling on top of hwloc's C API with CMake
611+
612+
Here's an example de <tt>CMakeLists.txt</tt> which shows variables
613+
obtained from <tt>pkg-config</tt> and how to use them:
614+
615+
\verbatim
616+
cmake_minimum_required(VERSION 3.5)
617+
project(TEST_HWLOC C)
618+
include(FindPkgConfig)
619+
if(PKG_CONFIG_EXECUTABLE)
620+
unset(HWLOC_FOUND CACHE)
621+
pkg_search_module(HWLOC hwloc)
622+
if(HWLOC_FOUND)
623+
message(STATUS "HWLOC_LIBRARIES=${HWLOC_LIBRARIES}")
624+
message(STATUS "HWLOC_LINK_LIBRARIES=${HWLOC_LINK_LIBRARIES}")
625+
message(STATUS "HWLOC_LIBRARY_DIRS=${HWLOC_LIBRARY_DIRS}")
626+
message(STATUS "HWLOC_LDFLAGS=${HWLOC_LDFLAGS}")
627+
message(STATUS "HWLOC_LDFLAGS_OTHERS=${HWLOC_LDFLAGS_OTHERS}")
628+
message(STATUS "HWLOC_INCLUDE_DIRS=${HWLOC_INCLUDE_DIRS}")
629+
message(STATUS "HWLOC_CFLAGS=${HWLOC_CFLAGS}")
630+
message(STATUS "HWLOC_CFLAGS_OTHER=${HWLOC_CFLAGS_OTHER}")
631+
else()
632+
message(FATAL_ERROR "HWLOC not found with pkg-config, add the path to hwloc.pc in PKG_CONFIG_PATH.")
633+
endif()
634+
else()
635+
message(FATAL_ERROR "PKG_CONFIG_EXECUTABLE: not found.")
636+
endif()
637+
638+
add_executable(hwloc-hello hwloc-hello.c)
639+
target_include_directories(hwloc-hello PRIVATE ${HWLOC_INCLUDE_DIRS})
640+
target_compile_options(hwloc-hello PRIVATE ${HWLOC_CFLAGS})
641+
target_link_libraries(hwloc-hello PRIVATE ${HWLOC_LINK_LIBRARIES})
642+
target_link_options(hwloc-hello PRIVATE ${HWLOC_LDFLAGS})
643+
\endverbatim
644+
645+
The project may be built with:
646+
\verbatim
647+
cmake -B build
648+
cmake --build build --verbose
649+
\endverbatim
650+
651+
The built binary is then available under <tt>build/hwloc-hello</tt>.
652+
653+
654+
655+
593656
\page termsanddefs Terms and Definitions
594657

595-
596658
\htmlonly
597659
<div class="section" id="termsanddefs_objects">
598660
\endhtmlonly

0 commit comments

Comments
 (0)