From eda93acc49e03988f6517153360fbea4850a1cfa Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Date: Thu, 2 Nov 2023 18:21:26 +0100 Subject: [PATCH] Use pkg-config to find nOS-V --- CHANGELOG.md | 3 +++ cmake/FindNosv.cmake | 19 +++++++++++++++++++ flake.nix | 2 +- test/rt/nosv/CMakeLists.txt | 17 ++++++----------- 4 files changed, 29 insertions(+), 12 deletions(-) create mode 100644 cmake/FindNosv.cmake diff --git a/CHANGELOG.md b/CHANGELOG.md index 24cb615..0eaf53f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Don't modify nOS-V subsystem state on task pause. The "Task: Running" state is now renamed to "Task: In body" to reflect the change. +- Use pkg-config to locate the nOS-V library and get the version. Use + `PKG_CONFIG_LIBDIR=/path/to/nosv/install/lib/pkgconfig` to use a custom + installation path. ## [1.3.0] - 2023-09-07 diff --git a/cmake/FindNosv.cmake b/cmake/FindNosv.cmake new file mode 100644 index 0000000..327d82a --- /dev/null +++ b/cmake/FindNosv.cmake @@ -0,0 +1,19 @@ +# Copyright (c) 2023 Barcelona Supercomputing Center (BSC) +# SPDX-License-Identifier: GPL-3.0-or-later + +find_package(PkgConfig) + +if(NOT PKG_CONFIG_FOUND) + message(STATUS "pkg-config not found, required to locate nOSV-V") + return() +endif() + +# Use PKG_CONFIG_LIBDIR=/path/to/nosv/install/lib/pkgconfig to use a custom +# installation. +pkg_search_module(NOSV IMPORTED_TARGET nos-v) + +if(NOT NOSV_FOUND) + message(STATUS "nOS-V not found") +else() + message(STATUS "Found nOS-V ${NOSV_VERSION} at ${NOSV_LINK_LIBRARIES}") +endif() diff --git a/flake.nix b/flake.nix index 35ea90f..a22b337 100644 --- a/flake.nix +++ b/flake.nix @@ -67,7 +67,7 @@ # We need to be able to exit the chroot to run Nanos6 tests, as they # require access to /sys for hwloc __noChroot = true; - buildInputs = old.buildInputs ++ (with pkgs; [ nosv nanos6 nodes ]); + buildInputs = old.buildInputs ++ (with pkgs; [ pkg-config nosv nanos6 nodes ]); cmakeFlags = old.cmakeFlags ++ [ "-DENABLE_ALL_TESTS=ON" ]; preConfigure = old.preConfigure or "" + '' export NODES_HOME="${pkgs.nodes}" diff --git a/test/rt/nosv/CMakeLists.txt b/test/rt/nosv/CMakeLists.txt index 12fa551..524558b 100644 --- a/test/rt/nosv/CMakeLists.txt +++ b/test/rt/nosv/CMakeLists.txt @@ -1,16 +1,13 @@ -# Copyright (c) 2021-2022 Barcelona Supercomputing Center (BSC) +# Copyright (c) 2021-2023 Barcelona Supercomputing Center (BSC) # SPDX-License-Identifier: GPL-3.0-or-later -find_library(nosv libnosv) -find_path(NOSV_INCLUDE_DIR nosv.h) +find_package(Nosv) -check_library_exists(nosv nosv_init "nosv.h" HAVE_NOSV) - -if(NOT HAVE_NOSV) +if(NOT NOSV_FOUND) if(ENABLE_ALL_TESTS) - message(FATAL_ERROR "nOS-V library not found, cannot enable nOS-V RT tests") + message(FATAL_ERROR "nOS-V not found, cannot enable nOS-V RT tests") else() - message(STATUS "nOS-V library not found, disabling nOS-V RT tests") + message(STATUS "nOS-V not found, disabling nOS-V RT tests") endif() return() else() @@ -19,9 +16,7 @@ endif() function(nosv_test) ovni_test(${ARGN}) - target_link_libraries("${OVNI_TEST_NAME}" PRIVATE nosv) - target_include_directories("${OVNI_TEST_NAME}" - PUBLIC ${NOSV_INCLUDE_DIR}) + target_link_libraries("${OVNI_TEST_NAME}" PRIVATE PkgConfig::NOSV) set_property(TEST "${OVNI_TEST_NAME}" APPEND PROPERTY ENVIRONMENT "NOSV_CONFIG=${OVNI_TEST_SOURCE_DIR}/rt/nosv/nosv.toml")