Skip to content

Commit cd3a1a7

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]>
1 parent c38aa5d commit cd3a1a7

File tree

2 files changed

+74
-18
lines changed

2 files changed

+74
-18
lines changed

README

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

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

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

doc/hwloc.doxy

+72-10
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<li> Chapters
2929
<ul>
3030
<li> \ref installation
31+
<li> \ref useapi
3132
<li> \ref termsanddefs
3233
<li> \ref tools
3334
<li> \ref envvar
@@ -352,16 +353,8 @@ tree.
352353
\include examples/hwloc-hello.c
353354

354355
hwloc provides a \c pkg-config executable to obtain relevant compiler
355-
and linker flags. For example, it can be used thusly to compile
356-
applications that utilize the hwloc library (assuming GNU Make):
357-
358-
\verbatim
359-
CFLAGS += $(shell pkg-config --cflags hwloc)
360-
LDLIBS += $(shell pkg-config --libs hwloc)
361-
362-
hwloc-hello: hwloc-hello.c
363-
$(CC) hwloc-hello.c $(CFLAGS) -o hwloc-hello $(LDLIBS)
364-
\endverbatim
356+
and linker flags. See \ref useapi for details on building program
357+
on top of hwloc's API using GNU Make or CMake.
365358

366359
On a machine 2 processor packages -- each package of
367360
which has two processing cores -- the output from running \c
@@ -558,6 +551,75 @@ or GNU Autotools.
558551

559552

560553

554+
\page useapi Compiling software on top of hwloc's C API
555+
556+
A program using the hwloc C API (for instance with <tt>hwloc-hello.c</tt>
557+
presented in \ref interface_example) may be built with standard
558+
development tools.
559+
<tt>pkg-config</tt> provides easy ways to retrieve the required compiler
560+
and linker flags as described below, but it is not mandatory.
561+
562+
563+
\section useapi_gnumake Compiling on top of hwloc's C API with GNU Make
564+
565+
Here's an example of Makefile for building <tt>hwloc-hello.c</tt>
566+
with GNU Make:
567+
568+
\verbatim
569+
CFLAGS += $(shell pkg-config --cflags hwloc)
570+
LDLIBS += $(shell pkg-config --libs hwloc)
571+
572+
hwloc-hello: hwloc-hello.c
573+
$(CC) hwloc-hello.c $(CFLAGS) -o hwloc-hello $(LDLIBS)
574+
\endverbatim
575+
576+
577+
\section useapi_cmake Compiling on top of hwloc's C API with CMake
578+
579+
Here's an example de <tt>CMakeLists.txt</tt> which shows variables
580+
obtained from <tt>pkg-config</tt> and how to use them:
581+
582+
\verbatim
583+
cmake_minimum_required(VERSION 3.5)
584+
project(TEST_HWLOC C)
585+
include(FindPkgConfig)
586+
if(PKG_CONFIG_EXECUTABLE)
587+
unset(HWLOC_FOUND CACHE)
588+
pkg_search_module(HWLOC hwloc)
589+
if(HWLOC_FOUND)
590+
message(STATUS "HWLOC_LIBRARIES=${HWLOC_LIBRARIES}")
591+
message(STATUS "HWLOC_LINK_LIBRARIES=${HWLOC_LINK_LIBRARIES}")
592+
message(STATUS "HWLOC_LIBRARY_DIRS=${HWLOC_LIBRARY_DIRS}")
593+
message(STATUS "HWLOC_LDFLAGS=${HWLOC_LDFLAGS}")
594+
message(STATUS "HWLOC_LDFLAGS_OTHERS=${HWLOC_LDFLAGS_OTHERS}")
595+
message(STATUS "HWLOC_INCLUDE_DIRS=${HWLOC_INCLUDE_DIRS}")
596+
message(STATUS "HWLOC_CFLAGS=${HWLOC_CFLAGS}")
597+
message(STATUS "HWLOC_CFLAGS_OTHER=${HWLOC_CFLAGS_OTHER}")
598+
else()
599+
message(FATAL_ERROR "HWLOC not found with pkg-config, add the path to hwloc.pc in PKG_CONFIG_PATH.")
600+
endif()
601+
else()
602+
message(FATAL_ERROR "PKG_CONFIG_EXECUTABLE: not found.")
603+
endif()
604+
605+
add_executable(hwloc-hello hwloc-hello.c)
606+
target_include_directories(hwloc-hello PRIVATE ${HWLOC_INCLUDE_DIRS})
607+
target_compile_options(hwloc-hello PRIVATE ${HWLOC_CFLAGS})
608+
target_link_libraries(hwloc-hello PRIVATE ${HWLOC_LINK_LIBRARIES})
609+
target_link_options(hwloc-hello PRIVATE ${HWLOC_LDFLAGS})
610+
\endverbatim
611+
612+
The project may be built with:
613+
\verbatim
614+
cmake -B build
615+
cmake --build build --verbose
616+
\endverbatim
617+
618+
The built binary is then available under <tt>build/hwloc-hello</tt>.
619+
620+
621+
622+
561623
\page termsanddefs Terms and Definitions
562624

563625
\section termsanddefs_objects Objects

0 commit comments

Comments
 (0)