<div dir="ltr"><br><br><div class="gmail_quote">On Wed, Sep 24, 2008 at 5:11 AM, Roy Zuo <span dir="ltr"><<a href="mailto:roylzuo@gmail.com">roylzuo@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Thanks a lot, and list(REMOVE_ITEM ...) works well for me.<br>
<br>
Another stupid question, as I am really new to c++. There are some cpp<br>
files containing only inline functions and some template class<br>
functions. The could not be compiled correctly as well, but if I<br>
exclude them from compilation, errors will come up in the linking<br>
stage. How should I treat those files?</blockquote><div>You should include these files into .cpp sources where these inlines are used.<br>For example, I've used something like this:<br><br>file1.h:<br>template<typename T><br>
class C<br>{<br>public:<br>T myfunc();<br>};<br><br>file1_inl.h:<br>template<typename T><br>T C::myfunc()<br>{<br> // Implementation goes here.<br>}<br><br>file2.h<br>#include "file1.h"<br>// Use template class declared previously.<br>
typedef C<int> myC;<br><br>file2.cpp:<br>#include "file2.h"<br>#include "file1_inl.h"<br>// Here we can call myC::myfunc(), because its implementation is accessible from here.<br><br>I can be wrong, because I don't know how exactly you can define template classes and functions' implementations, but generally this should work.<br>
<br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
<font color="#888888"><br>
Roy<br>
</font><div><div></div><div class="Wj3C7c"><br>
On Mon, Sep 22, 2008 at 06:00:52PM +0400, Timenkov Yuri wrote:<br>
><br>
> Hello eveyone,<br>
><br>
> I am just new to cmake and have some trouble when compiling a big<br>
> project whose cpp source files are put deep inside subdirectories.<br>
><br>
> In my CMakeLists.txt, I use AUX_SOURCE_DIRECTORY(subdir VARX) and<br>
> SET(SRC ${VAR1} ${VAR2} ...) to put all the source files in a<br>
> variable, and then use ADD_EXECUTABLE(foo main.c ${SRC}) to make the<br>
> executable. However, there are some cpp files containing only inline<br>
> functions, and when complier tries to compile them into .o files, a<br>
> lot of errors are throw out. So my question is, how to exclude those<br>
> files from the compilation?<br>
><br>
> I know this question is naive because this is my first time working<br>
> with cmake as well as C++.<br>
><br>
> There are a lot of solutions. One (possible most correct) is to keep in cpp<br>
> files only code which should be compiled. Put other code to headers. For<br>
> example, we've used ".inl" or "-inl.h" files for template code which were<br>
> included only to .cpp files (keeping prototypes in separate header).<br>
><br>
> Next, you can try using list(remove_item) function as work-around for your<br>
> problem.<br>
> For example, you know exact list of your not-to-compile files:<br>
> set(MY_INLINE_FILES file1.cpp file2.cpp)<br>
> list(remove_item SRC ${MY_INLINE_FILES})<br>
><br>
> OR, It will be better to exclude such files from compilation, keeping them in<br>
> target's sources, so CMake will put them into corresponding VS project:<br>
> set_source_files_properties(${MY_INLINE_FILES} PROPERTIES HEADER_FILE_ONLY<br>
> TRUE)<br>
> So, generated build system will not try to compile these files. We used this<br>
> approach to include all sources into Studio projects (including linix-specific<br>
> ones).<br>
> Also, you can mark them:<br>
> source_group("Inline files" ${MY_INLINE_FILES})<br>
><br>
><br>
><br>
><br>
> Kind regards,<br>
><br>
> Roy<br>
> _______________________________________________<br>
> CMake mailing list<br>
> <a href="mailto:CMake@cmake.org">CMake@cmake.org</a><br>
> <a href="http://www.cmake.org/mailman/listinfo/cmake" target="_blank">http://www.cmake.org/mailman/listinfo/cmake</a><br>
><br>
><br>
<br>
> _______________________________________________<br>
> CMake mailing list<br>
> <a href="mailto:CMake@cmake.org">CMake@cmake.org</a><br>
> <a href="http://www.cmake.org/mailman/listinfo/cmake" target="_blank">http://www.cmake.org/mailman/listinfo/cmake</a><br>
_______________________________________________<br>
CMake mailing list<br>
<a href="mailto:CMake@cmake.org">CMake@cmake.org</a><br>
<a href="http://www.cmake.org/mailman/listinfo/cmake" target="_blank">http://www.cmake.org/mailman/listinfo/cmake</a><br>
</div></div></blockquote></div><br></div>