CMake deliberately works in a top-down manner for most things. So variable values and preprocessor definitions are inherited in subdirectories from the values they had in the parent. And any subsequent changes made to them in the subdirectory scope are not propogated up to the parent. This is a good thing in my opinion because it allows you to isolate components from one another.
If you try to work against this you will find it difficult as CMake doesn't work that way. On 4 August 2011 06:15, Andrei Buzgan <andrei.buz...@gmail.com> wrote: > Hello Glenn and thanks, > > I found out yesterday the method you describe works. I was trying to use > include_directories() before, but unfortunately the statement was after any > add_directory() statement and it was a matter of scope (what other > variable/property updates add_directory() does?). > It works now, but still I'm wondering if there is a method of doing the > same thing at module level (leaf CMakeLists.txt files) and propagate the > updates upwards in directory hierarchy. > > Thanks again, > > Andrei > > > > > On Wed, Aug 3, 2011 at 8:10 PM, Glenn Coombs <glenn.coo...@gmail.com>wrote: > >> Have you tried using the include_directories() command ? In your top >> level CMakeLists.txt add a line like this: >> >> include_directories(SWC1 SWC2 SWC3 Common) >> >> before you do any add_subdirectory() commands. >> >> Does that not add the appropriate -Ixxx flags to the compile command ? It >> does for me but I'm using Visual Studio and gcc rather than an embedded >> compiler. >> >> On 3 August 2011 07:25, Andrei Buzgan <andrei.buz...@gmail.com> wrote: >> >>> Hello everyone, >>> >>> I'm trying to set up an environment for building a pre-existing medium >>> sized embedded software project, by using CMake 2.8 and MinGW. The compiler >>> kit is specific for the target microcontroller and contains C compiler, >>> assembler, linker, all different executables. >>> >>> I do have some restrictions: >>> The project structure looks like this: >>> Sources >>> |-- SWC1 >>> | |-- swc1.c >>> | |-- swc1.h >>> | |--CMakeLists.txt >>> |-- SWC2 >>> | |-- swc2_a.c >>> | |-- swc2_b.c >>> | |-- swc2.h >>> | |--CMakeLists.txt >>> |-- COMMON >>> | |-- config1.h >>> | |-- config2.h >>> | |--CMakeLists.txt >>> |-- UNUSED_DIR >>> |-- SWC3 >>> | |-- swc3.obj >>> | |-- swc3.h >>> >>> >>> - I cannot change the directory structure of the project (i can add but i >>> must not move files around) >>> >>> - each SW module (component) has it own files including interface headers >>> in it's own directory >>> (SW component SWC1 resides in folder SWC1 and contains a source file and >>> a header file) >>> >>> - SW modules may be interfaced with any other module >>> (swc1.c may include swc2.h...) >>> >>> - There are common header files with project scope definitions and >>> configurations which reside in their own directory too >>> (both swc1.c and swc2.c may include headers config1.h and config2.h) >>> >>> - The SW has more variants, some variants use different C source files >>> for a specific SW component but the sources reside in the same directory and >>> interface headers are common for all variants. >>> (For SW variant A the SW component SWC2 uses swc2_a.c source file, for SW >>> variant B it uses swc2_b.c file) >>> >>> - Some SW components are precompiled and provided as object files >>> together with the interface header (SWC3) >>> >>> *These being the conditions, i couldn't manage to gather the relevant >>> folders in order to correctly create the build object command *where >>> "flags" like -I<dir_pah1> -I<dir_path2> ... are expected in order to look >>> for included headers. Due to mixed source-precompiled objects I chose to >>> define each component as a static library (add_library(...)) in each >>> CMakeLists.txt file and list there the used source files, being able to use >>> conditions for SW variants and basically add different library definitions >>> for each variant. I intend to add the pre-compiled sources as IMPORTED >>> libraries and in the end just link the "libraries" with the specific linker >>> command for linking any object files (but i didn't get there yet!) >>> >>> I'm currently use the default CMAKE_C_COMPILE_OBJECT command >>> <CMAKE_C_COMPILER> <DEFINES> <FLAGS> -o <OBJECT> -c <SOURCE>, the compiler >>> ignoring the unknown flags ("-c" in this case). *Without any explicit >>> configuration from my part, it looks like <FLAGS> variable contains also a >>> -I<path> directive for the current compiled source file* (<path> is the >>> same directory where the source files about to be compiled resides). >>> >>> I tried to use "set( CMAKE_INCLUDE_CURRENT_DIR ON )" in each >>> CMakeLists.txt file but <FLAGS> variable seems not to be updated this way. >>> >>> I'd like to know if there is an efficient method to build an include >>> directory list in order to pass it to compile flags. It would be very useful >>> to make this in CMakeLists.txt file or link it somehow to add_directory(dir) >>> and use an internal CMake mechanism trying to avoid creating this part of >>> the compiler flags manually in order to be easily maintained in the future. >>> >>> Thanks, >>> Andrei >>> >>> >>> >>> >>> _______________________________________________ >>> Powered by www.kitware.com >>> >>> Visit other Kitware open-source projects at >>> http://www.kitware.com/opensource/opensource.html >>> >>> Please keep messages on-topic and check the CMake FAQ at: >>> http://www.cmake.org/Wiki/CMake_FAQ >>> >>> Follow this link to subscribe/unsubscribe: >>> http://www.cmake.org/mailman/listinfo/cmake >>> >> >> >
_______________________________________________ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake