Hello,<br><br>I'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't work for me. I'm describing below what i'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"MinGW Makefiles"<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> "c_flag1"<br> "c_flag2"<br> "c_flag3"<br> )<br><br>foreach( flag ${USER_C_COMPILER_FLAGS} )<br> set( USER_C_COMPILER_FLAGS_GENERAL "${USER_C_COMPILER_FLAGS_GENERAL} ${flag}" )<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>
"link_flag1"<br>
"link_flag2"<br>
"link_flag3"<br> )<br><br>set( USER_TMP_LINKER_FLAGS "" )<br><br>foreach( flag ${USER_LINKER_FLAGS} )<br> set( USER_TMP_LINKER_FLAGS "${USER_TMP_LINKER_FLAGS} ${flag}" )<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 "c_loc_flag1 c_loc_flag2 c_loc_flag3") <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> "${USER_CONFIG_LINKER} <LINK_FLAGS> <OBJECTS> -o <TARGET>"<br>
"${USER_CONFIG_CONVERTER} <TARGET> -o <TARGET>"<br>)<br><br>set( CMAKE_ASM_SOURCE_FILE_EXTENSIONS asm ASM )<br>set( CMAKE_ASM_OUTPUT_EXTENSION ".obj" )<br><br>set( CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> <FLAGS> <SOURCE> -o <OBJECT>" )<br>
<br>set( CMAKE_ASM_FLAGS_INIT " a list of ASM flags " )<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>