From fdda5620389badee998fe1926ddd3b46f7a6bcd8 Mon Sep 17 00:00:00 2001 From: Guilhem Saurel Date: Tue, 28 May 2024 13:31:59 +0200 Subject: [PATCH 1/4] CMake: allow absolute install paths --- cmake/VISPGenerateConfig.cmake | 21 ++++++++----- cmake/VISPGenerateConfigScript.cmake | 45 +++++++++++++++++++++------- 2 files changed, 47 insertions(+), 19 deletions(-) diff --git a/cmake/VISPGenerateConfig.cmake b/cmake/VISPGenerateConfig.cmake index 01b548313f..340cff6308 100644 --- a/cmake/VISPGenerateConfig.cmake +++ b/cmake/VISPGenerateConfig.cmake @@ -41,14 +41,19 @@ # output: path_to_parent, the relative path to go from path_to_child to parent # example: if input =lib/x86_64-linux-gnu, then output=../.. macro(get_path_to_parent path_to_child path_to_parent) - set(${path_to_parent} "") - set(input_ "${path_to_child}") - while(input_) - if(input_) - set(${path_to_parent} "${${path_to_parent}}../") - endif() - get_filename_component(input_ "${input_}" PATH) - endwhile(input_) + if(IS_ABSOLUTE ${path_to_child}) + file(RELATIVE_PATH _path_to_parent "${path_to_child}" "${CMAKE_INSTALL_PREFIX}") + string(REGEX REPLACE "/$" "" ${path_to_parent} "${_path_to_parent}") + else() + set(${path_to_parent} "") + set(input_ "${path_to_child}") + while(input_) + if(input_) + set(${path_to_parent} "${${path_to_parent}}../") + endif() + get_filename_component(input_ "${input_}" PATH) + endwhile(input_) + endif() endmacro() # Here we determine the relative path from ./${VISP_LIB_INSTALL_PATH} to its parent folder diff --git a/cmake/VISPGenerateConfigScript.cmake b/cmake/VISPGenerateConfigScript.cmake index 17d4809160..04489e5dce 100644 --- a/cmake/VISPGenerateConfigScript.cmake +++ b/cmake/VISPGenerateConfigScript.cmake @@ -343,8 +343,16 @@ else() # DEFINED CMAKE_HELPER_SCRIPT # Updates VISP_SCRIPT_PC_LIBS (for visp.pc used by pkg-config) #---------------------------------------------------------------------- set(exec_prefix "\${prefix}") - set(includedir "\${prefix}/${VISP_INC_INSTALL_PATH}") - set(libdir "\${prefix}/${VISP_LIB_INSTALL_PATH}") + if(IS_ABSOLUTE ${VISP_INC_INSTALL_PATH}) + set(includedir "${VISP_INC_INSTALL_PATH}") + else() + set(includedir "\${prefix}/${VISP_INC_INSTALL_PATH}") + endif() + if(IS_ABSOLUTE ${VISP_LIB_INSTALL_PATH}) + set(libdir "${VISP_LIB_INSTALL_PATH}") + else() + set(libdir "\${prefix}/${VISP_LIB_INSTALL_PATH}") + endif() # prepend with ViSP own include dir set(VISP_SCRIPT_PC_CFLAGS @@ -356,18 +364,33 @@ else() # DEFINED CMAKE_HELPER_SCRIPT vp_list_remove_separator(VISP_SCRIPT_PC_CFLAGS) # prepend with ViSP own modules first - set(VISP_SCRIPT_PC_LIBS - "-L\${exec_prefix}/${VISP_LIB_INSTALL_PATH}" - "${_modules}" - ) + if(IS_ABSOLUTE ${VISP_LIB_INSTALL_PATH}) + set(VISP_SCRIPT_PC_LIBS + "-L${VISP_LIB_INSTALL_PATH}" + "${_modules}" + ) + else() + set(VISP_SCRIPT_PC_LIBS + "-L\${exec_prefix}/${VISP_LIB_INSTALL_PATH}" + "${_modules}" + ) + endif() if(BUILD_SHARED_LIBS) set(VISP_SCRIPT_PC_LIBS_PRIVATE "${_extra_opt}") else() - set(VISP_SCRIPT_PC_LIBS_PRIVATE - "-L\${exec_prefix}/${VISP_3P_LIB_INSTALL_PATH}" - "${_3rdparty}" - "${_extra_opt}" - ) + if(IS_ABSOLUTE ${VISP_3P_LIB_INSTALL_PATH}) + set(VISP_SCRIPT_PC_LIBS_PRIVATE + "-L${VISP_3P_LIB_INSTALL_PATH}" + "${_3rdparty}" + "${_extra_opt}" + ) + else() + set(VISP_SCRIPT_PC_LIBS_PRIVATE + "-L\${exec_prefix}/${VISP_3P_LIB_INSTALL_PATH}" + "${_3rdparty}" + "${_extra_opt}" + ) + endif() endif() vp_list_remove_separator(VISP_SCRIPT_PC_LIBS) From 6ec5ebc91f1a7ba49d2f12fbc321710afdc28ce5 Mon Sep 17 00:00:00 2001 From: Guilhem Saurel Date: Tue, 28 May 2024 13:30:51 +0200 Subject: [PATCH 2/4] add nix packaging --- .nixignore | 12 ++++++++ default.nix | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.lock | 61 +++++++++++++++++++++++++++++++++++++ flake.nix | 21 +++++++++++++ 4 files changed, 181 insertions(+) create mode 100644 .nixignore create mode 100644 default.nix create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.nixignore b/.nixignore new file mode 100644 index 0000000000..367fb8dafd --- /dev/null +++ b/.nixignore @@ -0,0 +1,12 @@ +*.nix +.clang-format +.git* +.nixignore +.vscode +appveyor.yml +ChangeLog.txt +ci +codecov.yml +CONTRIBUTING.md +INSTALL.txt +README.md diff --git a/default.nix b/default.nix new file mode 100644 index 0000000000..6d8feb17f3 --- /dev/null +++ b/default.nix @@ -0,0 +1,87 @@ +# TODO: +# visp> In file included from /nix/store/g6lpg2p890jn3hkv63jjkk2f7k66y6hk-ogre-14.2.5/include/OGRE/Ogre.h:52, +# visp> from /build/source/modules/ar/include/visp3/ar/vpAROgre.h:66: +# visp> /nix/store/g6lpg2p890jn3hkv63jjkk2f7k66y6hk-ogre-14.2.5/include/OGRE/OgreConfigFile.h:94:41: note: declared here +# visp> 94 | OGRE_DEPRECATED SectionIterator getSectionIterator(void); +# visp> | ^~~~~~~~~~~~~~~~~~ +# visp> /build/source/modules/ar/src/ogre-simulator/vpAROgre.cpp:315:33: error: no matching function for call to 'Ogre::Root::showConfigDialog()' +# visp> 315 | if (!mRoot->showConfigDialog()) { +# visp> | ~~~~~~~~~~~~~~~~~~~~~~~^~ +{ + cmake, + coin3d, + doxygen, + eigen, + #fetchFromGitHub, + lapack, + lib, + libdc1394, + libdmtx, + libglvnd, + libpng, + libxml2, + libX11, + nix-gitignore, + nlohmann_json, + #ogre, + openblas, + opencv, + python3, + stdenv, + texliveSmall, + v4l-utils, + xorg, + zbar, + zlib, +}: + +stdenv.mkDerivation (finalAttrs: { + pname = "visp"; + version = "3.6.0"; + + /* + src = fetchFromGitHub { + owner = "lagadic"; + repo = "visp"; + rev = "v${finalAttrs.version}"; + hash = "sha256-m5Tmr+cZab7eSjmbXb8HpJpFHb0UYFTyimY+CkfBIAo="; + }; + */ + src = nix-gitignore.gitignoreSource [ ./.nixignore ] ./.; + + nativeBuildInputs = [ + cmake + doxygen + texliveSmall + ]; + + doCheck = true; + + buildInputs = [ + coin3d + eigen + lapack + libdmtx + libxml2 + libdc1394 + libX11 + libglvnd + libpng + nlohmann_json + #ogre + openblas + opencv + (python3.withPackages (p: [ p.numpy ])) + v4l-utils + xorg.libpthreadstubs + zbar + zlib + ]; + + meta = { + description = "Open Source Visual Servoing Platform"; + homepage = "https://visp.inria.fr"; + license = lib.licenses.gpl2Plus; + maintainers = [ lib.maintainers.nim65s ]; + }; +}) diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000000..444ac0938c --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1716715802, + "narHash": "sha256-usk0vE7VlxPX8jOavrtpOqphdfqEQpf9lgedlY/r66c=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e2dd4e18cc1c7314e24154331bae07df76eb582f", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000000..c0b98db211 --- /dev/null +++ b/flake.nix @@ -0,0 +1,21 @@ +{ + description = "Open Source Visual Servoing Platform"; + + inputs = { + flake-utils.url = "github:numtide/flake-utils"; + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + }; + + outputs = + { flake-utils, nixpkgs, ... }: + flake-utils.lib.eachDefaultSystem ( + system: + let + pkgs = nixpkgs.legacyPackages.${system}; + visp = pkgs.callPackage ./default.nix { }; + in + { + packages.default = visp; + } + ); +} From f1bea94f18973640ab9213b92194b2a10be3c5e4 Mon Sep 17 00:00:00 2001 From: Guilhem Saurel Date: Tue, 28 May 2024 13:32:56 +0200 Subject: [PATCH 3/4] CI: setup nix --- .github/workflows/nix.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .github/workflows/nix.yml diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml new file mode 100644 index 0000000000..08dac2e379 --- /dev/null +++ b/.github/workflows/nix.yml @@ -0,0 +1,17 @@ +name: "Nix CI" + +on: [pull_request, push] + +jobs: + tests: + name: "Nix build on ${{ matrix.os }}" + runs-on: "${{ matrix.os }}-latest" + strategy: + matrix: + os: [ubuntu] # TODO: macos + steps: + - uses: actions/checkout@v4 + - uses: DeterminateSystems/nix-installer-action@main + - uses: DeterminateSystems/magic-nix-cache-action@main + - uses: DeterminateSystems/flake-checker-action@main + - run: nix build From 69c444a0e8d7459406e636f10e5a4fc7113af9fa Mon Sep 17 00:00:00 2001 From: Guilhem Saurel Date: Tue, 28 May 2024 15:55:04 +0200 Subject: [PATCH 4/4] nix: more dependencies --- default.nix | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/default.nix b/default.nix index 6d8feb17f3..63f52b4cff 100644 --- a/default.nix +++ b/default.nix @@ -18,7 +18,9 @@ libdc1394, libdmtx, libglvnd, + libjpeg, # this is libjpeg-turbo libpng, + librealsense, libxml2, libX11, nix-gitignore, @@ -26,6 +28,7 @@ #ogre, openblas, opencv, + pkg-config, python3, stdenv, texliveSmall, @@ -52,6 +55,7 @@ stdenv.mkDerivation (finalAttrs: { nativeBuildInputs = [ cmake doxygen + pkg-config texliveSmall ]; @@ -61,12 +65,14 @@ stdenv.mkDerivation (finalAttrs: { coin3d eigen lapack - libdmtx - libxml2 libdc1394 - libX11 + libdmtx libglvnd + libjpeg libpng + librealsense + libX11 + libxml2 nlohmann_json #ogre openblas