[CMake] Building a DLL and test driver EXE using CMake -- error by design?

Jean-Christophe Fillion-Robin jchris.fillionr at kitware.com
Tue Mar 22 14:40:58 EDT 2011


Hi Chris,

Try to change the order of the ADD_DUBDIRECTORY.

add_subdirectory(FeatureViewer)

add_subdirectory(TestDriver)


instead of

add_subdirectory(TestDriver)

add_subdirectory(FeatureViewer)

As mentioned in the
doc<http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:add_subdirectory>:
"*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.*"

Changing the order of subdirectory will ensure that FeatureViewer dll is
built before TestDriver ...

Jc

On Tue, Mar 22, 2011 at 10:16 AM, Chris Volpe ARA/SED <cvolpe at ara.com>wrote:

> 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.
>
>
>
> 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:
>
> 1.       A DLL (called “FeatureViewer”) containing a vanilla C++ class
> that links against several VTK kits (Graphics, Rendering, and Hybrid).
>
> 2.       An EXE (called “TestDriver”) that links against the
> aforementioned library containing the vanilla C++ class.
>
>
>
> 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).
>
>
>
> 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->input->additional-dependencies list, it works.
>
>
>
> 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.
>
> The example given is:
>
>
>
> add_library(foo foo.cxx)
>
> target_link_libraries(foo bar)
>
>
>
> add_executable(foobar foobar.cxx)
>
> target_link_libraries(foobar foo)
>
>
>
> The text below the example states, *“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.”*
>
>
>
> 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.
>
>
>
> Can someone provide a work-around?
>
>
>
> My CMakeLists.txt files look like this:
>
>
>
> Top Level:
>
> CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
>
> IF(COMMAND CMAKE_POLICY)
>
>   CMAKE_POLICY(SET CMP0003 NEW)
>
> ENDIF(COMMAND CMAKE_POLICY)
>
>
>
> PROJECT(FeatureViewer)
>
>
>
> add_subdirectory(TestDriver)
>
> add_subdirectory(FeatureViewer)
>
>
>
> FeatureViewer:
>
> SET (FeatureViewer_SRCS
>
>   FeatureViewer.cxx
>
> )
>
>
>
> IF(NOT VTK_BINARY_DIR)
>
> FIND_PACKAGE(VTK REQUIRED)
>
> IF(NOT VTK_USE_RENDERING)
>
>   MESSAGE(FATAL_ERROR "Example ${PROJECT_NAME} requires
> VTK_USE_RENDERING.")
>
> ENDIF(NOT VTK_USE_RENDERING)
>
> INCLUDE(${VTK_USE_FILE})
>
> ENDIF(NOT VTK_BINARY_DIR)
>
>
>
> ADD_LIBRARY(FeatureViewer SHARED ${FeatureViewer_SRCS})
>
> TARGET_LINK_LIBRARIES(FeatureViewer vtkGraphics vtkRendering vtkHybrid)
>
>
>
> TestDriver:
>
> ADD_EXECUTABLE(TestDriver TestDriver.cxx)
>
>
>
> TARGET_LINK_LIBRARIES(TestDriver FeatureViewer)
>
>
>
> INCLUDE_DIRECTORIES(${FeatureViewer_SOURCE_DIR}/FeatureViewer)
>
>
>
> Thanks in advance!!
>
> Chris
>
> --
> Christopher R. Volpe,
> Ph.D.                                                           Email:
> cvolpe at ara.com
>
> Senior Scientist, Information Exploitation Systems             Main Desk:
> 919-582-3300
>
> Applied Research Associates, Inc <http://www.ara.com/>
> Direct: 919-582-3380
>
> 8537 Six Forks Rd., Suite
> 6000                                                            Fax :
> 919-582-3301
>
> Raleigh, NC 27615                                         Web:
> http://www.ara.com/offices/NC.htm
>
>
>
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>



-- 
+1 919 869 8849
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20110322/6fbf7e00/attachment.htm>


More information about the CMake mailing list