[CMake] newbie question about inline functions
Roy Zuo
roylzuo at gmail.com
Tue Sep 23 21:11:52 EDT 2008
Thanks a lot, and list(REMOVE_ITEM ...) works well for me.
Another stupid question, as I am really new to c++. There are some cpp
files containing only inline functions and some template class
functions. The could not be compiled correctly as well, but if I
exclude them from compilation, errors will come up in the linking
stage. How should I treat those files?
Roy
On Mon, Sep 22, 2008 at 06:00:52PM +0400, Timenkov Yuri 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
>
>
> _______________________________________________
> CMake mailing list
> CMake at cmake.org
> http://www.cmake.org/mailman/listinfo/cmake
More information about the CMake
mailing list