@@ -582,33 +582,18 @@ Here's an example de <tt>CMakeLists.txt</tt> which shows variables
582
582
obtained from <tt>pkg-config</tt> and how to use them:
583
583
584
584
\verbatim
585
- cmake_minimum_required(VERSION 3.5 )
585
+ cmake_minimum_required(VERSION 3.6 )
586
586
project(TEST_HWLOC C)
587
+
587
588
include(FindPkgConfig)
588
- if(PKG_CONFIG_EXECUTABLE)
589
- unset(HWLOC_FOUND CACHE)
590
- pkg_search_module(HWLOC hwloc)
591
- if(HWLOC_FOUND)
592
- message(STATUS "HWLOC_LIBRARIES=${HWLOC_LIBRARIES}")
593
- message(STATUS "HWLOC_LINK_LIBRARIES=${HWLOC_LINK_LIBRARIES}")
594
- message(STATUS "HWLOC_LIBRARY_DIRS=${HWLOC_LIBRARY_DIRS}")
595
- message(STATUS "HWLOC_LDFLAGS=${HWLOC_LDFLAGS}")
596
- message(STATUS "HWLOC_LDFLAGS_OTHERS=${HWLOC_LDFLAGS_OTHERS}")
597
- message(STATUS "HWLOC_INCLUDE_DIRS=${HWLOC_INCLUDE_DIRS}")
598
- message(STATUS "HWLOC_CFLAGS=${HWLOC_CFLAGS}")
599
- message(STATUS "HWLOC_CFLAGS_OTHER=${HWLOC_CFLAGS_OTHER}")
600
- else()
601
- message(FATAL_ERROR "HWLOC not found with pkg-config, add the path to hwloc.pc in PKG_CONFIG_PATH.")
602
- endif()
603
- else()
604
- message(FATAL_ERROR "PKG_CONFIG_EXECUTABLE: not found.")
605
- endif()
589
+ if(PKG_CONFIG_FOUND)
590
+ pkg_search_module(HWLOC REQUIRED IMPORTED_TARGET hwloc)
591
+ else(PKG_CONFIG_FOUND)
592
+ message(FATAL_ERROR "FindHWLOC needs pkg-config program and PKG_CONFIG_PATH must contain the path to hwloc.pc file.")
593
+ endif(PKG_CONFIG_FOUND)
606
594
607
595
add_executable(hwloc-hello hwloc-hello.c)
608
- target_include_directories(hwloc-hello PRIVATE ${HWLOC_INCLUDE_DIRS})
609
- target_compile_options(hwloc-hello PRIVATE ${HWLOC_CFLAGS})
610
- target_link_libraries(hwloc-hello PRIVATE ${HWLOC_LINK_LIBRARIES})
611
- target_link_options(hwloc-hello PRIVATE ${HWLOC_LDFLAGS})
596
+ target_link_libraries(hwloc-hello PRIVATE PkgConfig::HWLOC)
612
597
\endverbatim
613
598
614
599
The project may be built with:
0 commit comments