Hello,<br><br>I&#39;m trying to compile out-of-source an embedded C application using CMake and MinGW and to use specific compiler flags for some source files.<br>I tried the approach described in <a href="http://www.cmake.org/pipermail/cmake/2011-April/043703.html">http://www.cmake.org/pipermail/cmake/2011-April/043703.html</a> but it didn&#39;t work for me. I&#39;m describing below what i&#39;ve done, maybe someone highlights what i did wrong:<br>
<br>Project structure:<br><br>Top_Dir<br>|-- Build (from where I launch cmake)<br>|       |-- Output_Dir<br>|       |-- Toolchain.cmake<br>|       |-- build.bat<br>|-- Sources<br>        |-- Module1<br>        |         |-- module1.c<br>
        |         |-- module1.h<br>        |         |-- CMakeLists.txt [1]<br>        |-- Module2<br>        |         |-- module2.c<br>
        |         |-- module2.h<br>        |         |-- CMakeLists.txt [2]<br>        |-- Module3<br>        |         |-- module3.c<br>
        |         |-- module3.h<br>        |         |-- CMakeLists.txt [3]<br>
        |-- CMakeLists.txt [0]<br><br><b>build.bat</b><br>mkdir Output_Dir<br>cd Output_Dir<br>cmake ../../Sources -DCMAKE_TOOLCHAIN_FILE=../Toolchain.cmake -G&quot;MinGW Makefiles&quot;<br><br><b>CMakeLists.txt [0]</b><br>
cmake_minimum_required( VERSION 2.8 )<br><br>project( My_Project C ASM )<br><br>include_directories(<br>    Module1<br>    Module2<br>    Module3<br>)<br><br>add_subdirectory( Module1 )<br>add_subdirectory( Module2 )<br>add_subdirectory( Module3)<br>
<br>set( USER_C_COMPILER_FLAGS <br>    &quot;c_flag1&quot;<br>    &quot;c_flag2&quot;<br>    &quot;c_flag3&quot;<br>   )<br><br>foreach( flag ${USER_C_COMPILER_FLAGS} )<br>    set( USER_C_COMPILER_FLAGS_GENERAL &quot;${USER_C_COMPILER_FLAGS_GENERAL} ${flag}&quot; )<br>
endforeach( flag ${USER_C_COMPILER_FLAGS} )<br><br><i><b>set( CMAKE_C_FLAGS ${USER_C_COMPILER_FLAGS_GENERAL} )</b></i><br><br>add_definitions(<br>    -D DEF1<br>    -D DEF2<br>    -D DEF3<br>)<br><br>set( USER_LINKER_FLAGS<br>
     &quot;link_flag1&quot;<br>
    &quot;link_flag2&quot;<br>
    &quot;link_flag3&quot;<br>    )<br><br>set( USER_TMP_LINKER_FLAGS &quot;&quot; )<br><br>foreach( flag ${USER_LINKER_FLAGS} )<br>    set( USER_TMP_LINKER_FLAGS &quot;${USER_TMP_LINKER_FLAGS} ${flag}&quot; )<br>endforeach( flag ${USER_LINKER_FLAGS} )<br>
<br>set( CMAKE_EXE_LINKER_FLAGS ${USER_TMP_LINKER_FLAGS} )<br><br>set( PRJ_SOURCES <br>        Module1/module1.c<br>        Module2/module2.c<br>        Module3/module3.c<br>     )<br><br>add_executable( My_Exec ${PRJ_SOURCES} )<br>
<br>set( CMAKE_VERBOSE_MAKEFILE ON )<br><br>I tried to place in any of the leaf CMakeLists.txt files ([1][2][3]) statements like<br>set(USER_C_COMPILER_FLAGS_LOCAL &quot;c_loc_flag1 c_loc_flag2 c_loc_flag3&quot;) <br>set( CMAKE_C_FLAGS ${USER_C_COMPILER_FLAGS_LOCAL} )<br>
<br>and I expected to see different compiler flags for the sources in the respective directory, but instead ALL the sources were compiled with the flags defined in CMakeLists.txt[0] top level file.<br><br>What I did wrong? I clearly miss something in the inheritance mechanisms of CMake.<br>
<br>In Cmake Platform and Compiler folders i created the custom platform and compiler files with directives like:<br>set( CMAKE_C_LINK_EXECUTABLE <br>        &quot;${USER_CONFIG_LINKER} &lt;LINK_FLAGS&gt; &lt;OBJECTS&gt; -o &lt;TARGET&gt;&quot;<br>
        &quot;${USER_CONFIG_CONVERTER} &lt;TARGET&gt; -o &lt;TARGET&gt;&quot;<br>)<br><br>set( CMAKE_ASM_SOURCE_FILE_EXTENSIONS asm ASM )<br>set( CMAKE_ASM_OUTPUT_EXTENSION &quot;.obj&quot; )<br><br>set( CMAKE_ASM_COMPILE_OBJECT &quot;&lt;CMAKE_ASM_COMPILER&gt; &lt;FLAGS&gt; &lt;SOURCE&gt; -o &lt;OBJECT&gt;&quot; )<br>
<br>set( CMAKE_ASM_FLAGS_INIT &quot; a list of ASM flags &quot; )<br>to make the assembler work of ASM files and to use the custom linker and executable converter specific for the compiler kit I use.<br><br><br>Thanks,<br>
Andrei<br><br>