|
31 | 31 | <li> Chapters
|
32 | 32 | <ul>
|
33 | 33 | <li> \ref installation
|
| 34 | + <li> \ref useapi |
34 | 35 | <li> \ref termsanddefs
|
35 | 36 | <li> \ref tools
|
36 | 37 | <li> \ref envvar
|
@@ -365,16 +366,8 @@ tree.
|
365 | 366 | \include examples/hwloc-hello.c
|
366 | 367 |
|
367 | 368 | 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. |
378 | 371 |
|
379 | 372 | On a machine 2 processor packages -- each package of
|
380 | 373 | which has two processing cores -- the output from running \c
|
@@ -590,9 +583,78 @@ or GNU Autotools.
|
590 | 583 |
|
591 | 584 |
|
592 | 585 |
|
| 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 | + |
593 | 656 | \page termsanddefs Terms and Definitions
|
594 | 657 |
|
595 |
| - |
596 | 658 | \htmlonly
|
597 | 659 | <div class="section" id="termsanddefs_objects">
|
598 | 660 | \endhtmlonly
|
|
0 commit comments