<div class="gmail_quote">On Tue, Mar 29, 2011 at 1:58 AM, Michael Hertling <span dir="ltr">&lt;<a href="mailto:mhertling@online.de" target="_blank">mhertling@online.de</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div><div></div><div>On 03/29/2011 07:47 AM, Michael Hertling wrote:<br>
&gt; On 03/28/2011 08:23 PM, David Doria wrote:<br>
&gt;&gt; I have setup a list of definitions:<br>
&gt;&gt;<br>
&gt;&gt; SET(MAIN_BUILD_DEFINITIONS &quot;${MAIN_BUILD_DEFINITIONS} UNIX;&quot;)<br>
&gt;&gt; SET(MAIN_BUILD_DEFINITIONS &quot;${MAIN_BUILD_DEFINITIONS} PIXEL_DIMENSION=3;&quot;)<br>
&gt;&gt;<br>
&gt;&gt; I display them and apply them to my executable as follows:<br>
&gt;&gt;<br>
&gt;&gt; add_executable(ImageCompleter ${MainSources})<br>
&gt;&gt; message(&quot;Main build definitions: &quot; ${MAIN_BUILD_DEFINITIONS})<br>
&gt;&gt; set_target_properties(ImageCompleter PROPERTIES COMPILE_DEFINITIONS<br>
&gt;&gt; &quot;${MAIN_BUILD_DEFINITIONS}&quot;)<br>
&gt;&gt;<br>
&gt;&gt; The output is:<br>
&gt;&gt; Main build definitions:  UNIX PIXEL_DIMENSION=3<br>
&gt;&gt;<br>
&gt;&gt; which looks correct (i.e. UNIX was defined)<br>
&gt;&gt;<br>
&gt;&gt; However, in my code there is:<br>
&gt;&gt;<br>
&gt;&gt; #if defined(UNIX)<br>
&gt;&gt;      ... some code...<br>
&gt;&gt; #else<br>
&gt;&gt; #error &quot;Not implemented for this platform!&quot;<br>
&gt;&gt; #endif<br>
&gt;&gt;<br>
&gt;&gt; When I build, the error is produced, indicating that UNIX was not defined.<br>
&gt;&gt;<br>
&gt;&gt; I created a small standalone example and it worked as expected... any<br>
&gt;&gt; suggestions of what else to check?<br>
&gt;&gt;<br>
&gt;&gt; Thanks,<br>
&gt;&gt;<br>
&gt;&gt; David<br>
&gt;<br>
&gt; AFAICS, you mess up the value of the MAIN_BUILD_DEFINITIONS<br>
&gt; list variable. Look at the following CMakeLists.txt file:<br>
&gt;<br>
&gt; CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)<br>
&gt; PROJECT(COMPDEFS C)<br>
&gt; FILE(WRITE ${CMAKE_BINARY_DIR}/main.c &quot;int main(void){return 0;}\n&quot;)<br>
&gt; ADD_EXECUTABLE(main main.c)<br>
&gt; SET(MAIN_BUILD_DEFINITIONS<br>
&gt;     &quot;${MAIN_BUILD_DEFINITIONS} UNIX;&quot;)<br>
&gt; LIST(LENGTH MAIN_BUILD_DEFINITIONS n)<br>
&gt; MESSAGE(&quot;MAIN_BUILD_DEFINITIONS: ${MAIN_BUILD_DEFINITIONS} -- n=${n}&quot;)<br>
&gt; SET(MAIN_BUILD_DEFINITIONS<br>
&gt;     &quot;${MAIN_BUILD_DEFINITIONS} PIXEL_DIMENSION=3;&quot;)<br>
&gt; LIST(LENGTH MAIN_BUILD_DEFINITIONS n)<br>
&gt; MESSAGE(&quot;MAIN_BUILD_DEFINITIONS: ${MAIN_BUILD_DEFINITIONS} -- n=${n}&quot;)<br>
&gt; SET_TARGET_PROPERTIES(main PROPERTIES<br>
&gt;     COMPILE_DEFINITIONS &quot;${MAIN_BUILD_DEFINITIONS}&quot;)<br>
&gt;<br>
&gt; CMake&#39;s output contains:<br>
&gt;<br>
&gt; MAIN_BUILD_DEFINITIONS:  UNIX; -- n=2<br>
&gt; MAIN_BUILD_DEFINITIONS:  UNIX; PIXEL_DIMENSION=3; -- n=3<br>
&gt;<br>
&gt; Provided that MAIN_BUILD_DEFINITIONS is initially empty, the command<br>
&gt; SET(MAIN_BUILD_DEFINITIONS &quot;${MAIN_BUILD_DEFINITIONS} UNIX;&quot;) makes<br>
&gt; MAIN_BUILD_DEFINITIONS a list of *two* elements: &quot; UNIX&quot; - note the<br>
&gt; leading blank - and the empty string &quot;&quot;, and the second SET() adds<br>
&gt; &quot;PIXEL_DIMENSION=3&quot;. Probably, this is not what you intended. ;)<br>
&gt;<br>
&gt; Instead, try<br>
&gt;<br>
&gt; LIST(APPEND MAIN_BUILD_DEFINITIONS &quot;UNIX&quot;)<br>
&gt; LIST(APPEND MAIN_BUILD_DEFINITIONS &quot;PIXEL_DIMENSION=3&quot;)<br>
&gt;<br>
&gt; and CMake&#39;s output changes to<br>
&gt;<br>
&gt; MAIN_BUILD_DEFINITIONS: UNIX -- n=1<br>
&gt; MAIN_BUILD_DEFINITIONS: UNIX;PIXEL_DIMENSION=3 -- n=2<br>
&gt;<br>
&gt; which should work when used as COMPILE_DEFINITIONS property.<br>
&gt;<br>
&gt; IMO, the rule of thumb is: Don&#39;t use semicolons explicitly in SET()<br>
&gt; commands to assign list variables, but let CMake do this by itself.<br>
&gt; Moreover, be particularly careful when SETting list values, e.g.<br>
&gt;<br>
&gt; SET(A1 &quot;a&quot;)<br>
&gt; SET(AB1 &quot;${A1} b&quot;)<br>
&gt; LIST(LENGTH AB1 n)<br>
&gt; MESSAGE(&quot;AB1: ${AB1} -- n=${n}&quot;)<br>
&gt; SET(A2 &quot;a&quot; &quot;a&quot;)<br>
&gt; SET(AB2 &quot;${A2} b&quot;)<br>
&gt; LIST(LENGTH AB2 n)<br>
&gt; MESSAGE(&quot;AB2: ${AB2} -- n=${n}&quot;)<br>
&gt;<br>
&gt; results in<br>
&gt;<br>
&gt; AB1: a b -- n=1<br>
&gt; AB2: a;a b -- n=2<br>
&gt;<br>
&gt; i.e. AB1 is a non-list value which might by unexpected, and AB2 remains<br>
&gt; a list with just two elements which might be unexpected, too. Here, the<br>
&gt; correct coding is SET(AB1 &quot;${A1}&quot; &quot;b&quot;) and SET(AB2 &quot;${A2}&quot; &quot;b&quot;) which<br>
&gt; could nevertheless lead to AB{1,2} being lists of length two with an<br>
&gt; empty first element if AB{1,2} have been empty before. When adding<br>
<br>
</div></div>Oops: &quot;... if A{1,2} have been empty before.&quot;, to be exact. 8-0<br>
<div><div></div><div><br>
&gt; elements to lists it&#39;s best to use the LIST(APPEND ...) command.<br>
&gt;<br>
&gt; BTW, I can see the abovementioned CMakeLists.txt work correctly with<br>
&gt; CMake 2.8.4, so what version of CMake do you use for your project?<br>
&gt;<br>
&gt; Regards,<br>
&gt;<br>
&gt; Michael<br>
</div></div><div><br></div></blockquote><div class="gmail_quote"><br></div>Hm, I see what you&#39;re saying regarding set() vs list(append), however I don&#39;t think that is the problem here. I tried this:</div><div class="gmail_quote">
<br></div><div class="gmail_quote"><div class="gmail_quote">list(APPEND my_definitions &quot;UNIX&quot;)</div><div class="gmail_quote">list(APPEND my_definitions &quot;USE_ITK&quot;)</div><div class="gmail_quote">list(APPEND my_definitions &quot;USE_FLOAT_PIXELS&quot;)</div>
<div class="gmail_quote">list(APPEND my_definitions &quot;PIXEL_DIMENSION=1&quot;)</div><div class="gmail_quote">message(&quot;my definitions: ${my_definitions}&quot;)</div><div class="gmail_quote">set_target_properties(ImageCompleter1f PROPERTIES COMPILE_DEFINITIONS &quot;${my_definitions}&quot;)</div>
<div class="gmail_quote"><br></div><div class="gmail_quote">(with and without quotes around ${my_definitions} in the set_target_properties line) </div><div class="gmail_quote"><br></div><div class="gmail_quote">The message command seems to be fine:</div>
<div class="gmail_quote"><div class="gmail_quote">my definitions: UNIX;USE_ITK;USE_FLOAT_PIXELS;PIXEL_DIMENSION=1</div><div class="gmail_quote"><br></div><div class="gmail_quote">but the #if defined(UNIX) still fails in the code!</div>
<div><br></div></div></div><div class="gmail_quote"><div>David </div></div>