<div dir="ltr">When returning values from a function, you have to use the PARENT_SCOPE argument of set():<br><br>
<div>function( test __ANDROID__ RETVAL )</div><span class="gmail-im"><div><br></div><div>  if( ${__ANDROID__} EQUAL 1 OR ${__ANDROID__} STREQUAL "ON")</div></span><div>

<div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">    set( ${RETVAL} ${${RETVAL}} qwer2 PASRENT_SCOPE)<br></div></div><span class="gmail-im"><div>    message( "Included..... " )</div><div>  endif( ${__ANDROID__} EQUAL 1 OR ${__ANDROID__} STREQUAL "ON")</div><div><br></div><div>  if( __ANDROID__ )</div></span><div>    set( ${RETVAL} ${${RETVAL}} asdf PARENT_SCOPE)</div><span class="gmail-im"><div>    message( "ALWAYS Included ${__ANDROID__}" )</div><div>  endif( __ANDROID__ )</div><div><br></div></span><div>endfunction( test )<br><br></div><div>Petr<br></div>

<br></div><div class="gmail_extra"><br><div class="gmail_quote">On 30 January 2018 at 17:07, J Decker <span dir="ltr"><<a href="mailto:d3ck0r@gmail.com" target="_blank">d3ck0r@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Okay... but then with function I can't set external variables; but if( __ANDROID__ ) works.<div><div><br></div><div>`result` never changes.</div><div><br></div><div>---------------------------</div><div><div><br></div><div>set( __ANDROID__ 1 )</div><div><br></div><div>function( test __ANDROID__ RETVAL )</div><span class=""><div><br></div><div>  if( ${__ANDROID__} EQUAL 1 OR ${__ANDROID__} STREQUAL "ON")</div></span><div>

<div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">    set( ${RETVAL} ${${RETVAL}} qwer2 )<br></div></div><span class=""><div>    message( "Included..... " )</div><div>  endif( ${__ANDROID__} EQUAL 1 OR ${__ANDROID__} STREQUAL "ON")</div><div><br></div><div>  if( __ANDROID__ )</div></span><div>    set( ${RETVAL} ${${RETVAL}} asdf )</div><span class=""><div>    message( "ALWAYS Included ${__ANDROID__}" )</div><div>  endif( __ANDROID__ )</div><div><br></div></span><div>endfunction( test ) </div><div><br></div><div><br></div><div>set( result "default" )</div><div><br></div><div>test( __ANDROID__ "result" )</div><div>message( "REsult:${result}" )</div><div><br></div><div>test( ${__ANDROID__} "result" )</div><div>message( "REsult:${result}" )</div><div><br></div><div>test( OFF  "result")</div><div>message( "REsult:${result}" )</div></div><div>

<div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial"><br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial">---------------------------</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial"><br class="m_6136231696068243700gmail-Apple-interchange-newline">

</div><br></div><div><br></div></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 30, 2018 at 12:35 AM, Petr Kmoch <span dir="ltr"><<a href="mailto:petr.kmoch@gmail.com" target="_blank">petr.kmoch@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Macros aren't functions, and macro parameters aren't CMake variables. Expanding a macro parameter is effectively *textual* substitution, whereas dereferencing a CMake variable is a semantic one.<br><br></div><div>In other words, inside your macro, the text __ANDROID__ (when not expanded) never refers to the macro parameter. Macro parameters "don't exist" outside of expansion context. The `if(__ANDROID__)` bit therefore always refers to the variable __ANDROID__, never to the macro parameter __ANDROID__.<br><br></div><div>You still don't have to spell out the conditional as explicitly as you're doing it now, but you have to expand the parameter:<br><br></div><div>macro(test __ANDROID__)<br></div><div>  if(${__ANDROID__})<br>    
message( "Included..... " )

<br></div><div>  endif()<br></div><div>endmacro()<br><br></div><div>This is what the evaluation will look like based on how you call it:<br><br></div><div>test(__ANDROID__)   -> if(__ANDROID__) -> refers to the variable<br></div><div>set(__ANDROID__ 1)<br></div><div>test(${__ANDROID__})   -> if(1)<br></div><div>set(__ANDROID__ 0)<br></div>
<div>test(${__ANDROID__})   -> if(0)<br></div><div></div>

<div>test(OFF)   -> if(OFF)<br><br></div><div>CMake macros have a lot of specific and potentially weird/counterintuitive behaviour. In general, you should always write your commands as functions and only resort to macros if you explicitly need their specific behaviour.<br><br></div><div>Petr<br></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="m_6136231696068243700h5">On 30 January 2018 at 09:11, J Decker <span dir="ltr"><<a href="mailto:d3ck0r@gmail.com" target="_blank">d3ck0r@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="m_6136231696068243700h5"><div dir="ltr">Why do I have to do <div><br></div><div><div>if( ${M__ANDROID__} EQUAL 1 OR ${M__ANDROID__} STREQUAL "ON")</div></div><div>

<div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration-style:initial;text-decoration-color:initial"><div>endif( ${M__ANDROID__} EQUAL 1 OR ${M__ANDROID__} STREQUAL "ON")</div></div><br class="m_6136231696068243700m_2849536489279512872m_-1826249616639550471gmail-Apple-interchange-newline">

in a macro like...</div><div>----------------------</div><div><br></div><div><div>set( __ANDROID__ 1 )</div><div><br></div><div>macro( test __ANDROID__ )</div><div><br></div><div>  if( ${__ANDROID__} EQUAL 1 OR ${__ANDROID__} STREQUAL "ON")</div><div>    message( "Included..... " )</div><div>  endif( ${__ANDROID__} EQUAL 1 OR ${__ANDROID__} STREQUAL "ON")</div><div><br></div><div>  if( __ANDROID__ )</div><div>    message( "ALWAYS Included ${__ANDROID__}" )</div><div>  endif( __ANDROID__ )</div><div><br></div><div>endmacro( test ) </div><div><br></div><div>

<div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial">test( __ANDROID__ )</div>

test( ${__ANDROID__} )</div><div>test( OFF )</div></div><div><br></div><div>----------</div><div>Output</div><div><br></div><div><div>Included.....</div><div>ALWAYS Included __ANDROID__</div><div>Included.....</div><div>ALWAYS Included 1</div><div>ALWAYS Included OFF</div></div></div>
<br></div></div>--<br>
<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" target="_blank">http://www.cmake.org/Wiki/CMak<wbr>e_FAQ</a><br>
<br>
Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
<br>
CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/su<wbr>pport.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/co<wbr>nsulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/tr<wbr>aining.html</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensou<wbr>rce/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="https://cmake.org/mailman/listinfo/cmake" rel="noreferrer" target="_blank">https://cmake.org/mailman/list<wbr>info/cmake</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>