Hello everyone,<br><br>Thanks for your answers.<br><br>I managed to obtain what I want using Michael&#39;s proposal to set up each module with different compiler flags as a static library.<br>Here&#39;s what I did, maybe someone else needs this information:<br>
<br>Using set_source_files_properties() in the top level CMakeLists.txt with no static libraries correctly appends compiler flags and definitions to the existing ones. This was not good for my situation since duplicating some flags and definitions will not give the expected result: e.g. top level -U &lt;define&gt; will override the effect of a -D &lt;define&gt; in the leaf CMakeLists.txt file and for some compiler flags I had no option to disable them if they were already set, but this is just a drawback of the compiler kit I&#39;m using.<br>
<br><b>Working solution:</b><br><u>Top level CMakeLists.txt contains:</u><br><br><i>add_executable( ${USER_SUBPROJECT_NAME} ${USER_SOURCES} )</i><br>where USER_SOURCES is the list of source files with global compiler flags and definitions.<br>
<br><i>target_link_libraries( ${USER_SUBPROJECT_NAME}<br>        lib1<br>        lib2<br>        lib3<br>    )</i><br>where lib1 lib2 lib3 will be defined in leaf CMakeLists.txt files.<br><br><u>In leaf CMakeLists.txt files:</u><br>
<i>add_library( lib STATIC source.c )</i><br><i>set( USER_LOCAL_DEFINES<br>        &quot;DEF1&quot;<br>        &quot;DEF2&quot;<br>        &quot;DEF3&quot;<br>    )</i><br># without -D prefix.<br><i>set_source_files_properties( source.c PROPERTIES COMPILE_FLAGS &quot;-flag1 -flag2 -flag3&quot; )<br>
set_source_files_properties( source.c PROPERTIES COMPILE_DEFINITIONS &quot;${USER_LOCAL_DEFINES}&quot; )</i><br><br>the last line combined with set of USER_LOCAL_DEFINES will give the correct format since property COMPILE_DEFINITIONS expects a list separated by semicolons and automatically add -D prefix to each element.<br>
<br>Also, COMPILE_DEFINITIONS, as it&#39;s working now, does not permit to add undefines so probably I&#39;ll give up to this format and use only COMPILE_FLAGS property with explicit -D and -U prefixed macros as regular compiler flags.<br>
<br>Because of the non-standard compiler kit a static library does not need processing by ar.exe and ranlib.exe found and configured by CMake automatically out of MinGW. So I had to override some CMake configuration in the manually created Platform-Compiler-Lang.cmake file I&#39;m using:<br>
<br><u>In Platform-Compiler-Lang.cmake:</u><br><br>#Linking command<br><i>set( CMAKE_C_LINK_EXECUTABLE <br>        &quot;${USER_CONFIG_LINKER} &lt;LINK_FLAGS&gt; &lt;OBJECTS&gt; <b>&lt;LINK_LIBRARIES&gt;</b> -o &lt;TARGET&gt;&quot;<br>
        &quot;${USER_CONFIG_CONVERTER} &lt;TARGET&gt; -o &lt;TARGET&gt;&quot;<br>    )</i><br><br>&lt;LINK_LIBRARIES&gt; will contain all the libraries declared in leaf CMakeLists.txt files. &lt;OBJECTS&gt; will contain all the regular compiled sources declared in set_executable() statement.<br>
${USER_CONFIG_LINKER} is a custom variable used to call the linker executable and override the ld.exe found by CMake. It is initialize in Toolchain.cmake file like:<br><br><i>find_program( USER_CONFIG_LINKER linker )</i><br>
<br>The second and last command in CMAKE_C_LINK_EXECUTABLE is the converter invocation, which specifically for this compiler kit converts the .abs linked file (which contains also debug info) to plain hex executable ready to be burned in flash - also a feature specific to my compiler kit.<br>
<br><u>Second, also in  Platform-Compiler-Lang.cmake file I added the following lines:</u><br><br><i>set( CMAKE_C_ARCHIVE_CREATE &quot;${CMAKE_COMMAND} -E copy &lt;OBJECTS&gt; &lt;TARGET&gt;&quot; )</i><br><br>in order to create the library target by simply copy the object file in the &quot;archive library&quot; step. Basically what I&#39;m using are custom compiled object files and not &quot;real&quot; libraries.<br>
<br>The second line is:<br><br><i>set( CMAKE_C_ARCHIVE_FINISH &quot;&quot; )</i><br><br>used to disable ranlib.exe usage in the second step of library creation.<br><br>That&#39;s it. Maybe not the most elegant solution for embedded cross-compiling with custom flags for each source file but it seems to work well.<br>
<br>Andrei<br><br><br><br><div class="gmail_quote">On Tue, Aug 9, 2011 at 6:28 PM, Michael Hertling <span dir="ltr">&lt;<a href="mailto:mhertling@online.de">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 class="im">On 08/09/2011 04:43 PM, Michael Wild wrote:<br>
&gt; Well, directory properties are used by _targets_ defined in that<br>
&gt; directory. It doesn&#39;t matter where the sources are located.<br>
&gt;<br>
&gt; Michael<br>
<br>
</div>Additionally, setting a source property in the leaf CMakeLists.txt<br>
files as it has been suggested in this thread earlier wouldn&#39;t work<br>
also since such properties apply to source files for targets defined<br>
in the same CMakeLists.txt only. As the target is defined in the top-<br>
level CMakeLists.txt, any source property set in a subdirectory&#39;s<br>
CMakeLists.txt won&#39;t take effect.<br>
<br>
To revisit Andrei&#39;s concern: As your target is defined in the top-level<br>
CMakeLists.txt, only settings which are valid in this file apply to the<br>
My_Exec target, i.e. they must be defined in this CMakeLists.txt since<br>
there&#39;s no superior one to inherit from. Thus, you should imply source<br>
file properties, e.g. COMPILE_FLAGS, on the source files from within<br>
the top-level CMakeLists.txt. As an alternative, in each of your sub-<br>
directories, you might define a static library target built from the<br>
respective source files and link your top-level target against these<br>
libraries, provided your toolchain supports it. In this manner, you<br>
can define fine-grained target/directory-specific compilation flags,<br>
and linking against a static library is usually quite the same as<br>
incorporating the library&#39;s object files immediately.<br>
<br>
&#39;hope that helps.<br>
<br>
Regards,<br>
<div><div></div><div class="h5"><br>
Michael<br>
<br>
&gt; On 08/09/2011 04:36 PM, Tim Gallagher wrote:<br>
&gt;&gt; Interesting -- I guess this is sort of off topic from the original post, but that brings up a question:<br>
&gt;&gt;<br>
&gt;&gt; How does setting the COMPILE_DEFINITIONS on the directory work then? I was under the impression (not having tried it) that those definitions would only be added when compiling files contained in the directory. I assumed COMPILE_FLAGS could, if it existed, operate the same way.<br>

&gt;&gt;<br>
&gt;&gt; Tim<br>
&gt;&gt;<br>
&gt;&gt; ----- Original Message -----<br>
&gt;&gt; From: &quot;Michael Wild&quot; &lt;<a href="mailto:themiwi@gmail.com">themiwi@gmail.com</a>&gt;<br>
&gt;&gt; To: <a href="mailto:cmake@cmake.org">cmake@cmake.org</a><br>
&gt;&gt; Sent: Tuesday, August 9, 2011 10:32:58 AM<br>
&gt;&gt; Subject: Re: [CMake] Overriding C compiler flags in CMakeLists files<br>
&gt;&gt;<br>
&gt;&gt; On Tue 09 Aug 2011 04:28:51 PM CEST, Tim Gallagher wrote:<br>
&gt;&gt;&gt; In your leaf CMakeLists.txt, try doing:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; set_source_files_properties(${SOURCE_FILES} PROPERTIES COMPILE_FLAGS<br>
&gt;&gt;&gt; ${LOCAL_COMPILE_FLAGS})<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; where ${SOURCE_FILES} is a list of the files in the directory and<br>
&gt;&gt;&gt; ${LOCAL_COMPILE_FLAGS} is the list of flags for those files.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Ideally you would want to set this for the entire directory, but<br>
&gt;&gt;&gt; according to the documentation, the COMPILE_FLAGS property doesn&#39;t exist<br>
&gt;&gt;&gt; for directories.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Tim<br>
&gt;&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; Setting a directory property wouldn&#39;t help, since the directory<br>
&gt;&gt; property is inherited by the target, not the source files. And since<br>
&gt;&gt; the target lives in the top-level CMakeLists.txt file, the directory<br>
&gt;&gt; properties wouldn&#39;t come into play at all.<br>
&gt;&gt;<br>
&gt;&gt; Michael<br>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.cmake.org/mailman/listinfo/cmake" target="_blank">http://www.cmake.org/mailman/listinfo/cmake</a><br>
</div></div></blockquote></div><br>