@@ -581,33 +581,18 @@ Here's an example de <tt>CMakeLists.txt</tt> which shows variables
581
581
obtained from <tt>pkg-config</tt> and how to use them:
582
582
583
583
\verbatim
584
- cmake_minimum_required(VERSION 3.5 )
584
+ cmake_minimum_required(VERSION 3.6 )
585
585
project(TEST_HWLOC C)
586
+
586
587
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()
588
+ if(PKG_CONFIG_FOUND)
589
+ pkg_search_module(HWLOC REQUIRED IMPORTED_TARGET hwloc)
590
+ else(PKG_CONFIG_FOUND)
591
+ message(FATAL_ERROR "FindHWLOC needs pkg-config program and PKG_CONFIG_PATH must contain the path to hwloc.pc file.")
592
+ endif(PKG_CONFIG_FOUND)
605
593
606
594
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})
595
+ target_link_libraries(hwloc-hello PRIVATE PkgConfig::HWLOC)
611
596
\endverbatim
612
597
613
598
The project may be built with:
0 commit comments