<div dir="ltr"><br><br><div class="gmail_quote">On Wed, Sep 24, 2008 at 5:11 AM, Roy Zuo <span dir="ltr">&lt;<a href="mailto:roylzuo@gmail.com">roylzuo@gmail.com</a>&gt;</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&#39;ve used something like this:<br><br>file1.h:<br>template&lt;typename T&gt;<br>
class C<br>{<br>public:<br>T myfunc();<br>};<br><br>file1_inl.h:<br>template&lt;typename T&gt;<br>T C::myfunc()<br>{<br>&nbsp; // Implementation goes here.<br>}<br><br>file2.h<br>#include &quot;file1.h&quot;<br>// Use template class declared previously.<br>
typedef C&lt;int&gt; myC;<br><br>file2.cpp:<br>#include &quot;file2.h&quot;<br>#include &quot;file1_inl.h&quot;<br>// Here we can call myC::myfunc(), because its implementation is accessible from here.<br><br>I can be wrong, because I don&#39;t know how exactly you can define template classes and functions&#39; 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>
&gt;<br>
&gt; &nbsp; &nbsp; Hello eveyone,<br>
&gt;<br>
&gt; &nbsp; &nbsp; I am just new to cmake and have some trouble when compiling a big<br>
&gt; &nbsp; &nbsp; project whose cpp source files are put deep inside subdirectories.<br>
&gt;<br>
&gt; &nbsp; &nbsp; In my CMakeLists.txt, I use AUX_SOURCE_DIRECTORY(subdir VARX) and<br>
&gt; &nbsp; &nbsp; SET(SRC ${VAR1} ${VAR2} ...) to put all the source files in a<br>
&gt; &nbsp; &nbsp; variable, and then use ADD_EXECUTABLE(foo main.c ${SRC}) to make the<br>
&gt; &nbsp; &nbsp; executable. However, there are some cpp files containing only inline<br>
&gt; &nbsp; &nbsp; functions, and when complier tries to compile them into .o files, a<br>
&gt; &nbsp; &nbsp; lot of errors are throw out. So my question is, how to exclude those<br>
&gt; &nbsp; &nbsp; files from the compilation?<br>
&gt;<br>
&gt; &nbsp; &nbsp; I know this question is naive because this is my first time working<br>
&gt; &nbsp; &nbsp; with cmake as well as C++.<br>
&gt;<br>
&gt; There are a lot of solutions. One (possible most correct) is to keep in cpp<br>
&gt; files only code which should be compiled. Put other code to headers. For<br>
&gt; example, we&#39;ve used &quot;.inl&quot; or &quot;-inl.h&quot; files for template code which were<br>
&gt; included only to .cpp files (keeping prototypes in separate header).<br>
&gt;<br>
&gt; Next, you can try using list(remove_item) function as work-around for your<br>
&gt; problem.<br>
&gt; For example, you know exact list of your not-to-compile files:<br>
&gt; set(MY_INLINE_FILES file1.cpp file2.cpp)<br>
&gt; list(remove_item SRC ${MY_INLINE_FILES})<br>
&gt;<br>
&gt; OR, It will be better to exclude such files from compilation, keeping them in<br>
&gt; target&#39;s sources, so CMake will put them into corresponding VS project:<br>
&gt; set_source_files_properties(${MY_INLINE_FILES} PROPERTIES HEADER_FILE_ONLY<br>
&gt; TRUE)<br>
&gt; So, generated build system will not try to compile these files. We used this<br>
&gt; approach to include all sources into Studio projects (including linix-specific<br>
&gt; ones).<br>
&gt; Also, you can mark them:<br>
&gt; source_group(&quot;Inline files&quot; ${MY_INLINE_FILES})<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; &nbsp; &nbsp; Kind regards,<br>
&gt;<br>
&gt; &nbsp; &nbsp; Roy<br>
&gt; &nbsp; &nbsp; _______________________________________________<br>
&gt; &nbsp; &nbsp; CMake mailing list<br>
&gt; &nbsp; &nbsp; <a href="mailto:CMake@cmake.org">CMake@cmake.org</a><br>
&gt; &nbsp; &nbsp; <a href="http://www.cmake.org/mailman/listinfo/cmake" target="_blank">http://www.cmake.org/mailman/listinfo/cmake</a><br>
&gt;<br>
&gt;<br>
<br>
&gt; _______________________________________________<br>
&gt; CMake mailing list<br>
&gt; <a href="mailto:CMake@cmake.org">CMake@cmake.org</a><br>
&gt; <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>