Skip to content

Logic error in CMakeLists.txt when setting HAS_MMG and HAS_PARMMG #718

@mohrmarc

Description

@mohrmarc

Hi,

I detected an issue with the optional MMG dependency in the main CMakeList.txt file. This can lead to a broken elmerf90 script.
Running CMake with -DWITH_MMG=ON, but not having mmg or parmmg installed, does not set

  • HAS_MMG
  • HAS_PARMMG

Consequently text replacement of these in the elmerf90 template just inserts an empty string and we get lines like this:

if test  = "TRUE"; then
    MMGLIBDIR="-L"
    MMGINCLUDE="-IMMG_INCLUDE_DIR-NOTFOUND"
    printf "with MMG\n"
else
    MMGLIBDIR=""
    MMGINCLUDE=""
fi

if test  = "TRUE"; then
    PARMMGLIBDIR="-L"
    PARMMGINCLUDE="-I"
    printf "with ParMMG\n"

Now one might of course argue, that configuring with the option turned on is a bad idea, if the dependency is not installed. However, when no parallel version of mmg is installed, we still get a broken elmerf90 script, since HAS_PARMMG is not set to FALSE, when we run with

-DWITH_MMG:BOOL=TRUE   -DMMG_LIBRARY=<path-to-libmmg.so> -DMMG_INCLUDE_DIR=<path-to-include>

we still get a broken elmerf90

if test TRUE = "TRUE"; then
    MMGLIBDIR="-L/opt/software/elmerfem/2025-09-26_Installation/dependencies/local/lib"
    MMGINCLUDE="-I/opt/software/elmerfem/2025-09-26_Installation/dependencies/local/include"
    printf "with MMG\n"
else
    MMGLIBDIR=""
    MMGINCLUDE=""
fi

if test  = "TRUE"; then
    PARMMGLIBDIR="-L"
    PARMMGINCLUDE="-I"

IMHO this could be easily fixed by setting the two variables in the corresponding else branches of IF(MMG_FOUND) and IF(PARMMG_FOUND) to FALSE.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions