Skip to content
Snippets Groups Projects

add_dune_test: Handle complex expressions in `CMAKE_GUARD`

Merged Ansgar Burchardt requested to merge bugfix/complex-CMAKE_GUARD-expressions into master

The check if(NOT ${condition}) does not behave as expected when condition is a complex string expression such as A OR B. It does however work when condition is a list.

Therefore convert condition to a list by calling separate_arguments.

Note that this change also adds missing parenthesis around condition which also results in wrong results for complex expressions.

Closes issue #39 (closed).

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • What's about more complex conditions like (HAVE_ALUGRID OR HAVE_UGGRID) AND (HAVE_SUPERLU OR HAVE_UMFPACK)? That's not a trick question, but a real problem. I know it does not work currently, but while we are trying to fix this code…

  • @gruenich They seem to work if you write "( A OR B ) AND ( C OR D )" with spaces around the parenthesis, see the example CMake script below (run with cmake -P ${foo}). I don't know enough about CMake to explain why it is so strange.

    foreach(A 0 1)
      foreach(B 0 1)
        foreach(C 0 1)
          foreach(D 0 1)
    
            #message("A=${A} B=${B} C=${C} D=${D}")
    
            if(NOT ((A OR B) AND (C OR D)))
              message(true)
            else()
              message(false)
            endif()
    
            set(X "( A OR B ) AND ( C OR D )")
            # No spaces leads to unhappiness:
            #set(X "(A OR B) AND (C OR D)")
            separate_arguments(X)
            #message("X=${X}")
            if(NOT (${X}))
              message(true)
            else()
              message(false)
            endif()
    
            message(======)
          endforeach()
        endforeach()
      endforeach()
    endforeach()
  • Added 1 commit:

    • 074f0993 - [cmake] Mention complex expression for CMAKE_GUARD in documentation
  • Christoph Grüninger Status changed to merged

    Status changed to merged

  • mentioned in commit 3d6dc19c

  • Might be a string vs. list issue. During processing the string might be converted to a list. "( A OR B ) AND ( C OR D )" becomes (;A;OR;B;);AND;(;C;OR;D;). Without spaces this conversion would not make sense because of "(A", etc. in there.

  • Sorry I did not reply to this, I was away for some days. Thanks @ansgar for fixing the mess I created there (although I will absolutely blame CMake's policy of handling lists...) The fix looks good, I did not know that separate_arguments existed.

  • Mentioned in commit 3d6dc19c

Please register or sign in to reply
Loading