{"id":1103,"date":"2022-08-30T15:12:26","date_gmt":"2022-08-30T15:12:26","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/cmake-argv-and-macro-bug-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:12:26","modified_gmt":"2022-08-30T15:12:26","slug":"cmake-argv-and-macro-bug-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/cmake-argv-and-macro-bug-collection-of-common-programming-errors\/","title":{"rendered":"Cmake ARGV and Macro BUG?-Collection of common programming errors"},"content":{"rendered":"<p>In macros, ARGV1 etc. are not real CMake variables. Instead, <code>${ARGV1}<\/code> is the string replacement from the macro call. That means that your call with only one argument expands to<\/p>\n<pre><code>if( NOT false AND )\n<\/code><\/pre>\n<p>which explains the error message. By enclosing the string expansions in quotes, you now have<\/p>\n<pre><code>if( NOT \"false\" AND \"\")\n<\/code><\/pre>\n<p>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&#8217;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:<\/p>\n<pre><code>function(foo in1)\n  message(\"Optional1: \" ${ARGV1})\n  message(\"Optional2: \" ${ARGV2})\nif( NOT ARGV1 AND ARGV2 )\n   message(\"IF\")  \nelse()\n   message(\"ELSE\")  \nendif()\nendfunction()\n<\/code><\/pre>\n<p>Reference: http:\/\/www.cmake.org\/cmake\/help\/v2.8.8\/cmake.html#command:macro<\/p>\n<p id=\"rop\"><small>Originally posted 2013-11-09 23:24:45. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>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 &#8220;false&#8221; AND &#8220;&#8221;) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1103","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1103","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1103"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1103\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}