Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7981247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:18:40+00:00 2026-06-04T10:18:40+00:00

The following is strange! macro(foo in1) message(FIRST ${in1}) message(OPtional1: ${ARGV1}) message(OPtional2: ${ARGV2}) if( NOT

  • 0

The following is strange!

macro(foo in1)
  message("FIRST" ${in1})
  message("OPtional1:" ${ARGV1})
  message("OPtional2:" ${ARGV2})
if( NOT ${ARGV1} AND ${ARGV2} )
   message("IF")  
else()
   message("ELSE")  
endif()
endmacro()

Running the following:

foo("gaga" false true)   

(SHOULD GIVE “IF”)
WORKS!

BUT

foo("gaga" false)   

(SHOULD GIVE “ELSE” because the second optional argument is FALSE!)

Results in error:

cmake:126 (if):
given arguments:  "NOT" "false" "AND"
Unknown arguments specified

Is this a bug??

The following works:

if( NOT "${ARGV1}" AND "${ARGV2}" )
   message("IF")  
else()
   message("ELSE")  
endif()

WHY???

THANKS For any help!

(With functions it works)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T10:18:41+00:00Added an answer on June 4, 2026 at 10:18 am

    In macros, ARGV1 etc. are not real CMake variables. Instead, ${ARGV1} is the string replacement from the macro call. That means that your call with only one argument expands to

    if( NOT false AND )
    

    which explains the error message. By enclosing the string expansions in quotes, you now have

    if( NOT "false" AND "")
    

    giving the IF command an empty string to evaluate. Other solutions: use the ${ARGC} string replacement to decide whether the argument is present before trying to expand ARGV2. Or, as you’ve mentioned, switch to a function instead of a macro. In a function, ARGV1 is an actual CMake variable, and you can write it more sensibly, even without the ${} expansion at all:

    function(foo in1)
      message("Optional1: " ${ARGV1})
      message("Optional2: " ${ARGV2})
    if( NOT ARGV1 AND ARGV2 )
       message("IF")  
    else()
       message("ELSE")  
    endif()
    endfunction()
    

    Reference:
    http://www.cmake.org/cmake/help/v2.8.8/cmake.html#command:macro

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The situation is the following: Macro Foo is defined in File foo.vss Macro Bar
the first strange thing about map in clojure is in following snippet: (apply map
I observe the following strange behaviour in Vim 7.3: When I'm below a fold,
Any ideas why does the entity framework in LINQ gives following strange error: Unable
The following line of code causes my program to break in a very strange
I created a new project with the following code segment: char* strange = (Strange??);
I have the following query, now the strange thing is if I run this
I'm getting a strange NullPointerException, evidently thrown by the following line of code: Iterator<Note>
I am having a strange problem which I don't understand. I have the following
In the following code, this line is a bit strange to me: var x=document.forms[myForm][fname].value;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.