Hi, <br><br>Instead of using the following structure:<br>&lt;PROJECT_ROOT&gt;<br>   |---- FeatureViewer<br>   |---- TestDriver<br><br>You should use the following one:<br>&lt;PROJECT_ROOT&gt;<br>
   |---- FeatureViewer<br>
             |---- TestDriver<br><br>The naming convention we use in our different porject is the following:<br>&lt;PROJECT_ROOT&gt;<br>

   |---- FeatureViewer<br>

             |---- Testing<br>

                       |---- Cpp<br>
<br>Often we also add the extra subdirectory named &quot;Cpp&quot;, doing so allows the project to scale nicely in case the project deals with other language like Python. In that case, we will add a subdirectory named &quot;Python&quot;.<br>

<br>What motivates the change of the structure ? <br><br>Within the directory FeatureViewer, VTK is found and the following command is executed: <span style="font-family: &quot;Courier New&quot;;">INCLUDE(${VTK_USE_FILE})<br>

<br></span>The variable VTK_USE_FILE points to a file named UseVTK.cmake that will be included. De facto all CMake command listed in that file will be executed. Among them, let&#39;s note the use of this one:<br>   INCLUDE_DIRECTORIES(${VTK_INCLUDE_DIRS})<br>

<br>After being executed, this later one will allow you to include VTK header files from files associated with FeatureViewer target and targets located in subdirectories. For example tests.<br><br>Moreover, in your example, it seems the command &quot;LINK_DIRECTORIES&quot; is missing. Indeed, you should add the following command before calling <span style="font-family: &quot;Courier New&quot;;">ADD_LIBRARY(FeatureViewer ...)</span>:<br>

<br>LINK_DIRECTORIES(${VTK_LIBRARY_DIRS})<br><br><br>To summarize:<br><br> Changing the layout associated with the use of LINK_DIRECTORIES will:<br><br>   - allow unit test to include featureViewer headers that internally include VTK headers. <br>
<br>  - allow the linking of the test with FeatureViewer to work properly since the corresponding target will be defined in the current scope.<br> <br>HTH<br>Jc<br><br><div class="gmail_quote">
On Tue, Mar 22, 2011 at 6:33 PM, Chris Volpe ARA/SED <span dir="ltr">&lt;<a href="mailto:cvolpe@ara.com" target="_blank">cvolpe@ara.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

<div link="blue" vlink="purple" lang="EN-US"><div><p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">Jc-</span></p><p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">I already tried that, which is why I ended up with the ordering I did. Originally, with FeatureViewer first, I figured CMake would “know about” the dependent VTK libraries by the time it got to TestDriver, thereby enabling the undesired behavior. I then put TestDriver first, hoping that it would generate a project file to build against FeatureViewer without having gone into the subdirectory to find out about FeatureViewer’s VTK dependencies. But, alas, clearly it must descend into FeatureViewer anyway before actually generating the project file for TestDriver in order for it to know where to find the FeatureViewer library. So, clearly, it must go through a “gather all information” pass before it embarks on the “generate all project files” pass. </span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p><p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">So, my options at this point appear to be:</span></p><p>

<span style="font-size: 11pt; color: rgb(31, 73, 125);"><span>1.<span style="font: 7pt &quot;Times New Roman&quot;;">       </span></span></span><span style="font-size: 11pt; color: rgb(31, 73, 125);">Generate the project files, remove the VTK lib dependencies from TestDriver, and divorce myself from CMake at this point, doing all further project modifications (e.g. new classes/sources) directly within Visual Studio, or…</span></p>

<p><span style="font-size: 11pt; color: rgb(31, 73, 125);"><span>2.<span style="font: 7pt &quot;Times New Roman&quot;;">       </span></span></span><span style="font-size: 11pt; color: rgb(31, 73, 125);">Continue working within CMake, and continually remove the VTK lib dependencies each time I re-run CMake (a pain).</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p><p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">I’m amazed that nobody has ever experienced this problem before. It seems like a very natural thing to want to do.</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p><p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">Thanks for the quick response.</span></p><p class="MsoNormal">

<span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p><p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">-Chris</span></p><p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p>

<div style="border-width: medium medium medium 1.5pt; border-style: none none none solid; border-color: -moz-use-text-color -moz-use-text-color -moz-use-text-color blue; padding: 0in 0in 0in 4pt;"><div><div style="border-width: 1pt medium medium; border-style: solid none none; border-color: rgb(181, 196, 223) -moz-use-text-color -moz-use-text-color; padding: 3pt 0in 0in;">

<p class="MsoNormal"><b><span style="font-size: 10pt;">From:</span></b><span style="font-size: 10pt;"> Jean-Christophe Fillion-Robin [mailto:<a href="mailto:jchris.fillionr@kitware.com" target="_blank">jchris.fillionr@kitware.com</a>] <br>

<b>Sent:</b> Tuesday, March 22, 2011 2:41 PM<br><b>To:</b> Chris Volpe ARA/SED<br><b>Cc:</b> <a href="mailto:cmake@cmake.org" target="_blank">cmake@cmake.org</a><br><b>Subject:</b> Re: [CMake] Building a DLL and test driver EXE using CMake -- error by design?</span></p>

</div></div><div><div></div><div><p class="MsoNormal"> </p><p class="MsoNormal" style="margin-bottom: 12pt;">Hi Chris, <br><br>Try to change the order of the ADD_DUBDIRECTORY.</p><p class="MsoNormal" style="margin-left: 0.5in;">

<span style="font-family: &quot;Courier New&quot;;">add_subdirectory(FeatureViewer)</span></p><p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: &quot;Courier New&quot;;">add_subdirectory(TestDriver)</span></p>

<p class="MsoNormal" style="margin-left: 0.5in;"> </p><div><p class="MsoNormal" style="margin-bottom: 12pt;">instead of </p><p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: &quot;Courier New&quot;;">add_subdirectory(TestDriver)</span></p>

<p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: &quot;Courier New&quot;;">add_subdirectory(FeatureViewer)</span></p><p class="MsoNormal"><br>As mentioned in the <a href="http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:add_subdirectory" target="_blank">doc</a>: &quot;<i>The CMakeLists.txt file in the specified source directory will be processed immediately by CMake before processing in the current input file continues beyond this command.</i>&quot;<br>

<br>Changing the order of subdirectory will ensure that FeatureViewer dll is built before TestDriver ...<br><br>Jc<br><br>On Tue, Mar 22, 2011 at 10:16 AM, Chris Volpe ARA/SED &lt;<a href="mailto:cvolpe@ara.com" target="_blank">cvolpe@ara.com</a>&gt; wrote:</p>

<div><div><p class="MsoNormal">I posted this question in the VTK Users mailing list originally, but have since determined that it is more of a CMake issue than a VTK issue, and the involvement of VTK is only tangential. </p>

<p class="MsoNormal"> </p><p class="MsoNormal">I am trying to set up a source tree which will allow CMake to create a MSVC++ .sln file that contains the following two projects:</p><p>1.<span style="font-size: 7pt;">       </span>A DLL (called “FeatureViewer”) containing a vanilla C++ class that links against several VTK kits (Graphics, Rendering, and Hybrid).</p>

<p>2.<span style="font-size: 7pt;">       </span>An EXE (called “TestDriver”) that links against the aforementioned library containing the vanilla C++ class.</p><p class="MsoNormal"> </p><p class="MsoNormal">I want to deliver the DLL, LIB, and class header file from (1) above (as well as the dependent VTK DLLs) to a co-worker who has his own application and wants to use the functionality I’m encapsulating, but he doesn’t want to “vtk-ify” his build process. The EXE in (2) above is simply my test driver for (1).</p>

<p class="MsoNormal"> </p><p class="MsoNormal">My problem is that the EXE won’t build because the generated project is spuriously looking for vtk libraries (e.g. vtkGraphics.lib et. al.) at link time that it doesn’t directly reference, and it doesn’t know where to find them. The EXE shouldn’t need to know about them because their use is strictly within the FeatureViewer library. If I go into the EXE project properties and manually delete the references to vtkGraphics.lib et. al. from the linker-&gt;input-&gt;additional-dependencies list, it works. </p>

<p class="MsoNormal"> </p><p class="MsoNormal">At first, I thought I was just doing something wrong in my CMakeLists.txt files, but page 25 of the CMake User’s Guide suggests that this behavior is by design. </p><p class="MsoNormal">

The example given is:</p><p class="MsoNormal"> </p><p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: &quot;Lucida Console&quot;;">add_library(foo foo.cxx)</span></p><p class="MsoNormal" style="margin-left: 0.5in;">

<span style="font-family: &quot;Lucida Console&quot;;">target_link_libraries(foo bar)</span></p><p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: &quot;Lucida Console&quot;;"> </span></p><p class="MsoNormal" style="margin-left: 0.5in;">

<span style="font-family: &quot;Lucida Console&quot;;">add_executable(foobar foobar.cxx)</span></p><p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: &quot;Lucida Console&quot;;">target_link_libraries(foobar foo)</span></p>

<p class="MsoNormal"> </p><p class="MsoNormal">The text below the example states, <b>“This will link the libraries foo and bar into the executable foobar even [sic], although only foo was explicitly linked into foobar. With shared or DLL builds this linking is not always needed, but the extra linkage is harmless.”</b></p>

<p class="MsoNormal"> </p><p class="MsoNormal">It seems to me that this extra linkage is not harmless: I don’t want clients of FeatureViewer to have to know about vtkGraphics.lib et. al., but CMake is creating a spurious reference.</p>

<p class="MsoNormal"> </p><p class="MsoNormal">Can someone provide a work-around?</p><p class="MsoNormal"><span style="color: rgb(31, 73, 125);"> </span></p><p class="MsoNormal">My CMakeLists.txt files look like this:</p>

<p class="MsoNormal"> </p><p class="MsoNormal">Top Level:</p><p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: &quot;Courier New&quot;;">CMAKE_MINIMUM_REQUIRED(VERSION 2.4)</span></p><p class="MsoNormal" style="margin-left: 0.5in;">

<span style="font-family: &quot;Courier New&quot;;">IF(COMMAND CMAKE_POLICY)</span></p><p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: &quot;Courier New&quot;;">  CMAKE_POLICY(SET CMP0003 NEW)</span></p>

<p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: &quot;Courier New&quot;;">ENDIF(COMMAND CMAKE_POLICY)</span></p><p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: &quot;Courier New&quot;;"> </span></p>

<p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: &quot;Courier New&quot;;">PROJECT(FeatureViewer)</span></p><p class="MsoNormal"><span style="font-family: &quot;Courier New&quot;;"> </span></p><p class="MsoNormal" style="margin-left: 0.5in;">

<span style="font-family: &quot;Courier New&quot;;">add_subdirectory(TestDriver)</span></p><p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: &quot;Courier New&quot;;">add_subdirectory(FeatureViewer)</span></p>

<p class="MsoNormal"> </p><p class="MsoNormal">FeatureViewer:</p><p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: &quot;Courier New&quot;;">SET (FeatureViewer_SRCS</span></p><p class="MsoNormal" style="margin-left: 0.5in;">

<span style="font-family: &quot;Courier New&quot;;">  FeatureViewer.cxx</span></p><p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: &quot;Courier New&quot;;">)</span></p><p class="MsoNormal" style="margin-left: 0.5in;">

<span style="font-family: &quot;Courier New&quot;;"> </span></p><p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: &quot;Courier New&quot;;">IF(NOT VTK_BINARY_DIR)</span></p><p class="MsoNormal" style="margin-left: 0.5in;">

<span style="font-family: &quot;Courier New&quot;;">FIND_PACKAGE(VTK REQUIRED)</span></p><p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: &quot;Courier New&quot;;">IF(NOT VTK_USE_RENDERING)</span></p>

<p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: &quot;Courier New&quot;;">  MESSAGE(FATAL_ERROR &quot;Example ${PROJECT_NAME} requires VTK_USE_RENDERING.&quot;)</span></p><p class="MsoNormal" style="margin-left: 0.5in;">

<span style="font-family: &quot;Courier New&quot;;">ENDIF(NOT VTK_USE_RENDERING)</span></p><p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: &quot;Courier New&quot;;">INCLUDE(${VTK_USE_FILE})</span></p>

<p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: &quot;Courier New&quot;;">ENDIF(NOT VTK_BINARY_DIR)</span></p><p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: &quot;Courier New&quot;;"> </span></p>

<p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: &quot;Courier New&quot;;">ADD_LIBRARY(FeatureViewer SHARED ${FeatureViewer_SRCS})</span></p><p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: &quot;Courier New&quot;;">TARGET_LINK_LIBRARIES(FeatureViewer vtkGraphics vtkRendering vtkHybrid)</span></p>

<p class="MsoNormal"> </p><p class="MsoNormal">TestDriver:</p><p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: &quot;Courier New&quot;;">ADD_EXECUTABLE(TestDriver TestDriver.cxx)</span></p><p class="MsoNormal" style="margin-left: 0.5in;">

<span style="font-family: &quot;Courier New&quot;;"> </span></p><p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: &quot;Courier New&quot;;">TARGET_LINK_LIBRARIES(TestDriver FeatureViewer)</span></p>

<p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: &quot;Courier New&quot;;"> </span></p><p class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: &quot;Courier New&quot;;">INCLUDE_DIRECTORIES(${FeatureViewer_SOURCE_DIR}/FeatureViewer)</span></p>

<p class="MsoNormal"> </p><p class="MsoNormal">Thanks in advance!!</p><p class="MsoNormal"><span style="font-size: 24pt; font-family: &quot;Monotype Corsiva&quot;;">Chris</span></p><p class="MsoNormal"><span style="font-size: 10pt;">--<br>

Christopher R. Volpe, Ph.D.                                                           </span><span style="font-size: 10pt;" lang="FR">Email: <a href="mailto:cvolpe@ara.com" target="_blank">cvolpe@ara.com</a> </span></p><p class="MsoNormal">

<span style="font-size: 10pt;" lang="FR">Senior Scientist, Information Exploitation Systems             Main Desk: 919-582-3300</span></p><p class="MsoNormal"><span style="font-size: 10pt;"><a href="http://www.ara.com/" target="_blank">Applied Research Associates, Inc</a>                                                     Direct: 919-582-3380</span></p>

<p class="MsoNormal"><span style="font-size: 10pt;" lang="FR">8537 Six Forks Rd., Suite 6000                                                            Fax : 919-582-3301</span></p><p class="MsoNormal"><span style="font-size: 10pt;" lang="FR">Raleigh, NC 27615                                         Web: </span><span style="font-size: 10pt;"><a href="http://www.ara.com/offices/NC.htm" title="http://www.ara.com/offices/NC.htm" target="_blank">http://www.ara.com/offices/NC.htm</a></span></p>

<p class="MsoNormal"> </p><p class="MsoNormal"> </p></div></div><p class="MsoNormal"><br>_______________________________________________<br>Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>

<br>Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br><br>Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>

<br>Follow this link to subscribe/unsubscribe:<br><a href="http://www.cmake.org/mailman/listinfo/cmake" target="_blank">http://www.cmake.org/mailman/listinfo/cmake</a></p></div><p class="MsoNormal" style="margin-bottom: 12pt;">

<br><br clear="all"><br>-- <br>+1 919 869 8849</p></div></div></div></div></div></blockquote></div><br><br clear="all"><br>-- <br>+1 919 869 8849<br><br>