Skip to content

Commit d50f117

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 51e1ab2 commit d50f117

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
@@ -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

+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
@@ -353,16 +354,8 @@ tree.
353354
\include examples/hwloc-hello.c
354355

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

367360
On a machine 2 processor packages -- each package of
368361
which has two processing cores -- the output from running \c
@@ -559,6 +552,75 @@ or GNU Autotools.
559552

560553

561554

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

564626
\section termsanddefs_objects Objects

0 commit comments

Comments
 (0)