diff options
author | Kip Warner <kip@thevertigo.com> | 2021-07-13 00:38:00 +0300 |
---|---|---|
committer | Kip Warner <kip@thevertigo.com> | 2021-07-13 00:38:00 +0300 |
commit | c14bec00d22de3f1b71e6f65b019ebf24de660b5 (patch) | |
tree | c1c2803ee2154a3ac9c09d81131529967dced19d | |
parent | 44aca342025fabab351d942a5574959c6ce8d2d7 (diff) |
CMakeList.txt: Keep formatting consistent...
README.md: Improved pkg-config notes...
-rw-r--r-- | CMakeLists.txt | 46 | ||||
-rw-r--r-- | README.md | 26 |
2 files changed, 44 insertions, 28 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index a492b10..71b235b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -830,28 +830,28 @@ ENDIF() # ---[ pkg-config manifest. This is mostly from JsonCpp... if(CPUINFO_BUILD_PKG_CONFIG AND (CPUINFO_LIBRARY_TYPE STREQUAL "default" OR CPUINFO_LIBRARY_TYPE STREQUAL "shared")) - function(join_paths joined_path first_path_segment) - set(temp_path "${first_path_segment}") - foreach(current_segment IN LISTS ARGN) - if(NOT ("${current_segment}" STREQUAL "")) - if(IS_ABSOLUTE "${current_segment}") - set(temp_path "${current_segment}") - else() - set(temp_path "${temp_path}/${current_segment}") - endif() - endif() - endforeach() - set(${joined_path} "${temp_path}" PARENT_SCOPE) - endfunction() - - join_paths(libdir_for_pc_file "\${exec_prefix}" "${CMAKE_INSTALL_LIBDIR}") - join_paths(includedir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}") - - configure_file( - "libcpuinfo.pc.in" - "libcpuinfo.pc" - @ONLY) - install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libcpuinfo.pc" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") + function(join_paths joined_path first_path_segment) + set(temp_path "${first_path_segment}") + foreach(current_segment IN LISTS ARGN) + if(NOT ("${current_segment}" STREQUAL "")) + if(IS_ABSOLUTE "${current_segment}") + set(temp_path "${current_segment}") + else() + set(temp_path "${temp_path}/${current_segment}") + endif() + endif() + endforeach() + set(${joined_path} "${temp_path}" PARENT_SCOPE) + endfunction() + +join_paths(libdir_for_pc_file "\${exec_prefix}" "${CMAKE_INSTALL_LIBDIR}") +join_paths(includedir_for_pc_file "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}") + +configure_file( + "libcpuinfo.pc.in" + "libcpuinfo.pc" + @ONLY) +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libcpuinfo.pc" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") endif() @@ -102,11 +102,27 @@ pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpu_set); ## Use via pkg-config -If you would like to automatically have your project's build environment use the appropriate compiler and linker build flags, [pkg-config](https://www.freedesktop.org/wiki/Software/pkg-config/) can greatly simplify things. It is the portable international _de facto_ standard for determining build flags. Here is an example: +If you would like to provide your project's build environment with the necessary compiler and linker flags in a portable manner, the library by default when built enables `CPUINFO_BUILD_PKG_CONFIG` and will generate a [pkg-config](https://www.freedesktop.org/wiki/Software/pkg-config/) manifest (_libcpuinfo.pc_). Here are several examples of how to use it: + +### Command Line + +If you used your distro's package manager to install the library, you can verify that it is available to your build environment like so: + +```console +$ pkg-config --cflags --libs libcpuinfo +-I/usr/include/x86_64-linux-gnu/ -L/lib/x86_64-linux-gnu/ -lcpuinfo +``` + +If you have installed the library from source into a non-standard prefix, pkg-config may need help finding it: + +```console +$ PKG_CONFIG_PATH="/home/me/projects/cpuinfo/prefix/lib/pkgconfig/:$PKG_CONFIG_PATH" pkg-config --cflags --libs libcpuinfo +-I/home/me/projects/cpuinfo/prefix/include -L/home/me/projects/cpuinfo/prefix/lib -lcpuinfo +``` ### GNU Autotools -To [use](https://autotools.io/pkgconfig/pkg_check_modules.html) with the GNU Autotools, as an example, include the following snippet in your project's `configure.ac`: +To [use](https://autotools.io/pkgconfig/pkg_check_modules.html) with the GNU Autotools include the following snippet in your project's `configure.ac`: ```makefile # CPU INFOrmation library... @@ -119,7 +135,7 @@ YOURPROJECT_LIBS="$YOURPROJECT_LIBS $libcpuinfo_LIBS" ### Meson -To use with Meson, you just need to add `dependency('libcpuinfo')` as a dependency for your executable. +To use with Meson you just need to add `dependency('libcpuinfo')` as a dependency for your executable. ```meson project( @@ -137,7 +153,7 @@ executable( ### CMake -To use with a CMake build environment, use the [FindPkgConfig](https://cmake.org/cmake/help/latest/module/FindPkgConfig.html) module. Here is an example: +To use with CMake use the [FindPkgConfig](https://cmake.org/cmake/help/latest/module/FindPkgConfig.html) module. Here is an example: ```cmake cmake_minimum_required(VERSION 3.6) @@ -152,7 +168,7 @@ target_link_libraries(${PROJECT_NAME} PkgConfig::CpuInfo) ### Makefile -To use within a vanilla makefile, you can call `pkg-config` directly to supply compiler and linker flags using shell substitution. +To use within a vanilla makefile, you can call pkg-config directly to supply compiler and linker flags using shell substitution. ```makefile CFLAGS=-g3 -Wall -Wextra -Werror ... |