You are not logged in.

#1 2023-02-16 14:09:46

LukeLabrie
Member
Registered: 2022-02-19
Posts: 28

How to avoid cmake using ${pkgdir} directly?

I'm making two different packages: moab, and double-downdouble-down depends on moab. It also depends on embree, which is already available as a package on the AUR. They worked perfectly locally using

makepkg -si

so I updated the repos, and tested with

yay -S double-down-git

which throws the following error

fatal error: moab/Core.hpp: No such file or directory
    3 | #include "moab/Core.hpp"

Further up I see the following lines

-- MOAB_INCLUDE_DIRS is /home/myuser/.cache/yay/moab/pkg/moab/opt/MOAB/include/usr/include/eigen3
-- Found Embree 3.13.5 at 
-- EMBREE_LIBRARY is /usr/lib/libembree3.so.3.13.5
-- EMBREE_INCLUDE_DIRS is /usr/include

The issue is definitely that the MOAB_INCLUDE_DIRS filepath does not exist, so it can't find any of the header files. I dug into this a little, and it's because when I build moab, I use ${pkgdir} in the CMAKE_INSTALL_PREFIX flag, as follows:

build() {
	cd $srcdir
	mkdir build && cd build
	cmake ../$pkgname-$pkgver -DENABLE_HDF5=ON \
				  -DENABLE_NETCDF=ON \
				  -DENABLE_FORTRAN=OFF \
				  -DENABLE_BLASLAPACK=OFF \
				  -DENABLE_PYMOAB=ON \
				  -DBUILD_SHARED_LIBS=ON \
				  -DCMAKE_INSTALL_PREFIX=${pkgdir}/opt/MOAB
	make
}

The CMake configuration file, then uses CMAKE_INSTALL_PREFIX to set the MOAB_INCLUDE_DIRS variable, like so:

set(MOAB_LIBRARY_DIRS "@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@")

see here

So, what I think is happening, is when I use ${pkgdir} in the CMAKE flag, that path actually gets built into the package for use by its upstream dependencies. The reason I'm using ${pkgdir}, is that I have read that it is best practice per the guidelines, and I get permissions errors if I don't.

Two main questions:

1.) How is embree getting away with not using ${pkgdir}? See here. If I try the same with MOAB, I get a permissions error.

2.) Is there any way I can make this work without modifying MOAB Cmake config file?

Offline

#2 2023-02-16 14:28:05

Scimmia
Fellow
Registered: 2012-09-01
Posts: 12,051

Re: How to avoid cmake using ${pkgdir} directly?

The install prefix should not include $pkgdir, that comes later when you're actually installing in the package function.

Offline

#3 2023-02-16 14:45:25

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: How to avoid cmake using ${pkgdir} directly?

LukeLabrie wrote:

If I try the same with MOAB, I get a permissions error.

Then tell us about this error so it can be fixed.  If this is with the PKGBUILD that is currently in the AUR, the cmake PREFIX is correct, but you have not set the install DESTDIR to ${pkgdir}, rather you've tried setting it to ${pkgdir}/opt/MOAB which would not work.  PREFIX is appended to DESTDIR for an install, so you've doubled up /opt/MOAB.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#4 2023-02-16 15:26:36

LukeLabrie
Member
Registered: 2022-02-19
Posts: 28

Re: How to avoid cmake using ${pkgdir} directly?

So when I remove ${pkgdir}, like so:

build() {
	cd $srcdir
	mkdir build && cd build
	cmake ../$pkgname-$pkgver -DENABLE_HDF5=ON \
				  -DENABLE_NETCDF=ON \
				  -DENABLE_FORTRAN=OFF \
				  -DENABLE_BLASLAPACK=OFF \
				  -DENABLE_PYMOAB=ON \
				  -DBUILD_SHARED_LIBS=ON \
				  -DCMAKE_INSTALL_PREFIX=/opt
	make
}

package() {
        cd $srcdir/build
	make DESTDIR="${pkgdir}/" install
	cd pymoab 
	bash install.sh
	python setup.py install --user
}

The /opt folder is empty, and the make DESTDIR="$pkgdir/" install command fails with:

Install the project...
-- Install configuration: ""
-- Installing: /mnt/moab/pkg/moab/opt/lib/cmake/MOAB/MOABTargets.cmake
-- Installing: /mnt/moab/pkg/moab/opt/lib/cmake/MOAB/MOABTargets-noconfig.cmake
-- Installing: /mnt/moab/pkg/moab/opt/lib/iMesh-Defs.inc
-- Installing: /mnt/moab/pkg/moab/opt/lib/moab.make
CMake Error at cmake_install.cmake:77 (file):
  file failed to open for writing (No such file or directory):

    /opt/lib/moab.make


make: *** [Makefile:110: install] Error 1

where ${pkgdir} is /mnt/moab/pkg/moab.

You can see that  /opt/lib/moab.make exists actually at /mnt/moab/pkg/moab/opt/lib/moab.make, so I'm not sure why it's not looking there...

Last edited by LukeLabrie (2023-02-16 15:47:52)

Offline

#5 2023-02-16 17:04:47

LukeLabrie
Member
Registered: 2022-02-19
Posts: 28

Re: How to avoid cmake using ${pkgdir} directly?

Why wouldn't it be using ${pkgdir} in the cmake_install.cmake file?

Offline

#6 2023-02-16 17:10:47

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: How to avoid cmake using ${pkgdir} directly?

EDIT: I thought I had it working, but it did error out with the same message as yours at the very last steps.  I'm no good at troubleshooting cmake.  The error references a file name, but not a full path, and there are nearly a dozen files with that same name in the source tree ... so I'm not sure which one to look at.  But this looks to me like an error in some flavor of install-hook script that is run after all the other content is installed properly to DESTDIR - some upstream makefile or similar file is not properly using DESTDIR, but is ignoring it and trying to act directly on the root filesystem.

EDIT 2: the file in question is the toplevel in the build directory, and line 77 as well as line 81 include clear errors.

Last edited by Trilby (2023-02-16 17:22:16)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#7 2023-02-16 17:21:02

LukeLabrie
Member
Registered: 2022-02-19
Posts: 28

Re: How to avoid cmake using ${pkgdir} directly?

What/where is the install-hook script you're referring to? I thought this was all under the make install command...


EDIT:

I see, I can try making an issue on the moab repo I suppose

Last edited by LukeLabrie (2023-02-16 17:22:06)

Offline

#8 2023-02-16 17:24:19

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: How to avoid cmake using ${pkgdir} directly?

See my edit, the file src/build/cmake_install.cmake has errors on (at least) lines 77 and 81 where INSTALL DESTINATION and ${CMAKE_INSTALL_PREFIX} are completely ignored and instead a specific path is hardcoded.  However, this file itself is generated from other upstream supplied cmake input files, and I don't know enough about cmake to know which one is relevant.

Other notes on the PKGBUILD: be sure to add cmake to the makedepends, and while not really a problem there is no reason for a PKGBUILD to be executable.

Note that someone versed in using cmake could likely spot the source of this issue quickly and perhaps have an easy patch to allow this to build/install properly.  But sending this patch upstream would still be worthwhile, so certainly open the issue there.

Last edited by Trilby (2023-02-16 17:28:53)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#9 2023-02-17 12:03:07

LukeLabrie
Member
Registered: 2022-02-19
Posts: 28

Re: How to avoid cmake using ${pkgdir} directly?

Ok, thanks.

Have I made it executable?

Offline

#10 2023-02-19 17:37:50

loqs
Member
Registered: 2014-03-06
Posts: 18,006

Re: How to avoid cmake using ${pkgdir} directly?

Lines 643 and 647 of the top CMakeLists.txt are the ones not using DESTDIR.  Beyond my cmake knowledge as to why.

	bash install.sh
	python setup.py install --user

Where install.sh contains

cd /build/moab/src/build/pymoab

PYMOAB_INSTALL_PREFIX=/opt/MOAB/lib/python3.10/site-packages

export PYTHONPATH="$PYMOAB_INSTALL_PREFIX:$PYTHONPATH"

if [[ ! -d $PYMOAB_INSTALL_PREFIX ]]; then
  mkdir -p /opt/MOAB/lib/python3.10/site-packages
fi


/usr/bin/python setup.py install --prefix=/opt/MOAB --record /opt/MOAB/lib/python3.10/site-packages/install_files.txt

The script looks as though it will install files directly to /opt/MOAB
Why install the python module with --user?

Offline

#11 2023-02-21 09:43:55

LukeLabrie
Member
Registered: 2022-02-19
Posts: 28

Re: How to avoid cmake using ${pkgdir} directly?

Thanks for the extra digging @loqs.

Looks like lines 643 and 647 uses the `CMAKE_INSTALL_FULL_LIBDIR` variable, which I'm guessing is based on `CMAKE_INSTALL_PREFIX`. Do you know where the `CMAKE_INSTALL_FULL_LIBDIR` variable comes from? Because I don't see it defined in CMakeLists.txt.

Offline

#12 2023-02-21 13:10:37

Lone_Wolf
Administrator
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 12,893

Re: How to avoid cmake using ${pkgdir} directly?

It appears to be  a standard GNU dir although I don't remember seeing it used before,  https://cmake.org/cmake/help/latest/mod … lDirs.html

CMAKE_INSTALL_FULL_<dir>

    The absolute path generated from the corresponding CMAKE_INSTALL_<dir> value. If the value is not already an absolute path, an absolute path is constructed typically by prepending the value of the CMAKE_INSTALL_PREFIX variable. However, there are some special cases as documented below.

Those 2 lines are the only ones that use CMAKE_INSTALL_FULL and I think the first occurence on both lines is wrong.

Try applying this diff as a patch (see https://wiki.archlinux.org/title/Patching_packages if you're unfamiliar with patching)

diff --unified --recursive --text --color moab-5.3.1/CMakeLists.txt moab-5.3.1-new/CMakeLists.txt
--- moab-5.3.1/CMakeLists.txt   2021-11-12 07:17:17.000000000 +0100
+++ moab-5.3.1-new/CMakeLists.txt       2023-02-21 14:02:31.267636548 +0100
@@ -640,11 +640,11 @@
   )
 INSTALL(
   CODE
-  "file(APPEND  ${CMAKE_INSTALL_FULL_LIBDIR}/moab.make MOAB_LIBDIR=${CMAKE_INSTALL_FULL_LIBDIR}\\n )"
+  "file(APPEND  ${CMAKE_INSTALL_LIBDIR}/moab.make MOAB_LIBDIR=${CMAKE_INSTALL_FULL_LIBDIR}\\n )"
   )
 INSTALL(
   CODE
-  "file(APPEND  ${CMAKE_INSTALL_FULL_LIBDIR}/moab.make MOAB_INCLUDES=-I${CMAKE_INSTALL_FULL_INCLUDEDIR}\\n )"
+  "file(APPEND  ${CMAKE_INSTALL_LIBDIR}/moab.make MOAB_INCLUDES=-I${CMAKE_INSTALL_FULL_INCLUDEDIR}\\n )"
   )
 INSTALL(
   FILES "${PROJECT_BINARY_DIR}/MOABConfig.cmake"

NOTES
-  I have not tested this ! assuming it builds now , verify if desired functionality works.
-  I know this can be done with sed, but I expect upstream will prefer a diff over a sed command in a bugreport .


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.

clean chroot building not flexible enough ?
Try clean chroot manager by graysky

Offline

#13 2023-02-24 13:17:27

LukeLabrie
Member
Registered: 2022-02-19
Posts: 28

Re: How to avoid cmake using ${pkgdir} directly?

@Lone_Wolf, that patch worked. I've added it to the PKGBUILD. Thanks very much.

Offline

#14 2023-02-24 13:41:10

loqs
Member
Registered: 2014-03-06
Posts: 18,006

Re: How to avoid cmake using ${pkgdir} directly?

==> Starting prepare()...
patch: **** Can't open patch file ../../moab-5.4.0-p.1.patch : No such file or directory

Please add the patch to the source array and change ../../ to ../ as you can not assume anything about what is in the parent of $srcdir.

Offline

Board footer

Powered by FluxBB