[CMake] newbie question about inline functions

Timenkov Yuri ytimenkov at gmail.com
Mon Sep 22 10:00:52 EDT 2008


On Mon, Sep 22, 2008 at 10:00 AM, Roy Zuo <ROYLZUO at gmail.com> wrote:

> Hello eveyone,
>
> I am just new to cmake and have some trouble when compiling a big
> project whose cpp source files are put deep inside subdirectories.
>
> In my CMakeLists.txt, I use AUX_SOURCE_DIRECTORY(subdir VARX) and
> SET(SRC ${VAR1} ${VAR2} ...) to put all the source files in a
> variable, and then use ADD_EXECUTABLE(foo main.c ${SRC}) to make the
> executable. However, there are some cpp files containing only inline
> functions, and when complier tries to compile them into .o files, a
> lot of errors are throw out. So my question is, how to exclude those
> files from the compilation?
>
> I know this question is naive because this is my first time working
> with cmake as well as C++.

There are a lot of solutions. One (possible most correct) is to keep in cpp
files only code which should be compiled. Put other code to headers. For
example, we've used ".inl" or "-inl.h" files for template code which were
included only to .cpp files (keeping prototypes in separate header).

Next, you can try using list(remove_item) function as work-around for your
problem.
For example, you know exact list of your not-to-compile files:
set(MY_INLINE_FILES file1.cpp file2.cpp)
list(remove_item SRC ${MY_INLINE_FILES})

OR, It will be better to exclude such files from compilation, keeping them
in target's sources, so CMake will put them into corresponding VS project:
set_source_files_properties(${MY_INLINE_FILES} PROPERTIES HEADER_FILE_ONLY
TRUE)
So, generated build system will not try to compile these files. We used this
approach to include all sources into Studio projects (including
linix-specific ones).
Also, you can mark them:
source_group("Inline files" ${MY_INLINE_FILES})


>
> Kind regards,
>
> Roy
> _______________________________________________
> CMake mailing list
> CMake at cmake.org
> http://www.cmake.org/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20080922/4367fd41/attachment.htm>


More information about the CMake mailing list