|
28 | 28 | <li> Chapters
|
29 | 29 | <ul>
|
30 | 30 | <li> \ref installation
|
| 31 | + <li> \ref useapi |
31 | 32 | <li> \ref termsanddefs
|
32 | 33 | <li> \ref tools
|
33 | 34 | <li> \ref envvar
|
@@ -352,16 +353,8 @@ tree.
|
352 | 353 | \include examples/hwloc-hello.c
|
353 | 354 |
|
354 | 355 | 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. |
365 | 358 |
|
366 | 359 | On a machine 2 processor packages -- each package of
|
367 | 360 | which has two processing cores -- the output from running \c
|
@@ -558,6 +551,75 @@ or GNU Autotools.
|
558 | 551 |
|
559 | 552 |
|
560 | 553 |
|
| 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 | + |
561 | 623 | \page termsanddefs Terms and Definitions
|
562 | 624 |
|
563 | 625 | \section termsanddefs_objects Objects
|
|
0 commit comments