Makefile not recognizing DESTDIR variable

Issue #165 resolved
Luke Labrie-Cleary created an issue

I’m trying to install moab to a specific directory using make DESTDIR=/path/to/install/dir install, which is required when writing a PKGBUILD script in the Arch User Repository (AUR, see here). This works partially, and then fails when it looks for libraries just using the CMAKE_INSTALL_PREFIX and doesn’t check for the DESTDIR variable. See sample output below from my system (manjaro)

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

/opt/MOAB/lib/moab.make

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

So here, /opt/MOAB is the CMAKE_INSTALL_PREFIX, and DESTDIR is /mnt/moab/pkg/moab.On line 77 (and line 81) of `cmake_install.cmake`, which can be found in the build folder after cmakeis run, there is a hardcoded filepath, instead of the DESTDIRfilepath. See below

if(CMAKE_INSTALL_COMPONENT STREQUAL "Unspecified" OR NOT CMAKE_INSTALL_COMPONENT)
file(APPEND /home/luke/git/openmc_install_scripts/Arch/AUR/MOAB-PKGBUILD/pkg/moab/opt/MOAB/lib/moab.make MOAB_LIBDIR=/home/luke/git/openmc_install_scripts/Arch/AUR/MOAB-PKGBUILD/pkg/moab/opt/MOAB/lib\n )
endif()

if(CMAKE_INSTALL_COMPONENT STREQUAL "Unspecified" OR NOT CMAKE_INSTALL_COMPONENT)
file(APPEND /home/luke/git/openmc_install_scripts/Arch/AUR/MOAB-PKGBUILD/pkg/moab/opt/MOAB/lib/moab.make MOAB_INCLUDES=-I/home/luke/git/openmc_install_scripts/Arch/AUR/MOAB-PKGBUILD/pkg/moab/opt/MOAB/include\n )
endif()

Whereas the others all include the INSTALL DESTINATIONand CMAKE_INSTALL_PREFIXvariables, which results in proper behaviour. I think this is the root of the issue, but I’m not sure how to resolve it.

In the meantime, would there be a way around this issue just using cmake? Or will it require a fix?

Comments (3)

  1. Luke Labrie-Cleary reporter

    I was able to get around this issue with the following patch

    --- ./src/moab-5.3.1/CMakeLists.txt 2021-11-12 07:17:17.000000000 +0100
    +++ ./src/moab-5.3.1-new/CMakeLists.txt 2023-02-24 13:00:09.687251667 +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"
    

    Is there a reason to use CMAKE_INSTALL_FULL_LIBDIR instead of CMAKE_INSTALL_LIBDIR? Or could this be a quick PR?

  2. Vijay M

    Sorry, I missed this issue. If you want to submit a quick PR, please do. Else, I’ll try to apply this patch and run it through our CI before submitting a PR for it this weekend.

  3. Log in to comment