|
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
|
@@ -353,16 +354,8 @@ tree.
|
353 | 354 | \include examples/hwloc-hello.c
|
354 | 355 |
|
355 | 356 | 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. |
366 | 359 |
|
367 | 360 | On a machine 2 processor packages -- each package of
|
368 | 361 | which has two processing cores -- the output from running \c
|
@@ -559,6 +552,75 @@ or GNU Autotools.
|
559 | 552 |
|
560 | 553 |
|
561 | 554 |
|
| 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 | + |
562 | 624 | \page termsanddefs Terms and Definitions
|
563 | 625 |
|
564 | 626 | \section termsanddefs_objects Objects
|
|
0 commit comments