[CMake] Can CMake intelligently support GCC "-include" directive

Richard Lang r_e_lang at hotmail.com
Mon Dec 14 23:03:17 EST 2015


Hi all,

Porting a collection of IAR Embedded Workbench projects to CMake/GCC.

The IAR projects make use of "preinclude headers" (header files that are
automatically included in every source file in the project without being
explicitly pulled in with a #include statement - not to be confused with
precompiled headers).  These map nicely to the GCC "-include <filename>"
directive and I can manually implement it in my CMakeList.txt file as
follows


    set(PREINCLUDE_FILE "${PROJ_BASE_DIR}/some-path/preinclude.h")

    ...

    if (PREINCLUDE_FILE)
        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -include ${PREINCLUDE_FILE}")
    endif()

and generate a makefile that builds OK.  However when I use CMake to
generate an Eclipse project there is no consideration given to the
preinclude header file(s).

In my case the preinclude contains several preprocessor definitions that
effectively drive the configuration of the rest of the system during
compilation - without them the Eclipse CDT Indexer does not get all the
definitions required to make sense of the codebase and requires additional
manual configuration before it will do anything useful.

Is there any way to automate this from the CMakeList.txt file?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20151215/78edafa4/attachment.html>


More information about the CMake mailing list