[CMake] Include directories for C compile command

Andrei Buzgan andrei.buzgan at gmail.com
Wed Aug 3 02:25:18 EDT 2011


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20110803/c65d031d/attachment.htm>


More information about the CMake mailing list