[vtkusers] Wrong CMake configuration for VTK+Qt-Projects in Visual Studio
John Drescher
drescherjm at gmail.com
Sun May 16 14:16:10 EDT 2010
On Sun, May 16, 2010 at 1:03 PM, Rocco Gasteiger
<post at rocco-gasteiger.de> wrote:
> Hello everybody,
>
>
>
> I use CMake to configure a VTK+Qt project in Visual Studio 9 on a Windows 7
> machine. According to information in this mailing list and other examples I
> create my own CMakeLists.txt file and it works…almost! I can build and link
> my project correctly against VTK but if I start my program within (or
> outside of) Visual Studio I get a error that some (I think all) VTK dlls are
> missing e.g. vtkCommon.dll. In my environment variables I already set a
> path (in the Path-variable or VTK_DIR) to the binary folder of the compiled
> VTK sources. Within this folder I have a debug and release folder.
>
>
>
> Currently, I can only resolve this behavior in one of two ways.
>
> 1. I set the path in my environment variables to the debug or release
> folder and can run the program in debug or release mode.
>
> 2. I set PATH=$(QTDIR)\bin;$(VTK_DIR)\$(OutDir) as entry in the
> debugging environment in the project properties (QTDIR was set in the
> environment variables too)
>
>
>
> But I think this manual effort is not necessary if I configure my
> CMakeLists.txt correctly. So I do something wrong and maybe somebody can
> help me.
>
> At the end of this mail you find the (shortened) content of my
> CMakeLists.txt file.
>
I use a build step to copy the Qt dlls to the build folder for Debug
and Release. I also build itk, and vtk statically. Eventually I could
build these as shared and update the build script below to copy those
dlls as well.
# Copy the needed Qt libraries into the Build directory. Also add installation
# and CPack code to support installer generation.
# this is a complete hack for Visual Studio to copy the Qt libraries.
if ( NOT Q_WS_MAC)
if (DEFINED QT_QMAKE_EXECUTABLE)
SET (QTLIBLIST QtCore QtGui)
IF (MSVC)
set(TYPE "d")
FOREACH(qtlib ${QTLIBLIST})
IF (WIN32)
GET_FILENAME_COMPONENT(QT_DLL_PATH_tmp
${QT_QMAKE_EXECUTABLE} PATH)
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/Debug)
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/Release)
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/MinSizeRel)
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/RelWithDebInfo)
INSTALL(FILES ${QT_DLL_PATH_tmp}/${qtlib}${type}d4.dll
DESTINATION ./
CONFIGURATIONS Debug
COMPONENT Applications)
INSTALL(FILES ${QT_DLL_PATH_tmp}/${qtlib}4.dll
DESTINATION ./
CONFIGURATIONS Release
COMPONENT Applications)
add_custom_target(ZZ_${qtlib}-Debug-Copy ALL
COMMAND ${CMAKE_COMMAND} -E
copy_if_different ${QT_DLL_PATH_tmp}/${qtlib}${TYPE}4.dll
${PROJECT_BINARY_DIR}/Debug/
COMMENT "Copying ${qtlib}${TYPE}4.dll to
${PROJECT_BINARY_DIR}/Debug/")
add_custom_target(ZZ_${qtlib}-Release-Copy ALL
COMMAND ${CMAKE_COMMAND} -E
copy_if_different ${QT_DLL_PATH_tmp}/${qtlib}4.dll
${PROJECT_BINARY_DIR}/Release/
COMMENT "Copying ${qtlib}4.dll to
${PROJECT_BINARY_DIR}/Release/")
ENDIF (WIN32)
ENDFOREACH(qtlib)
endif(MSVC)
endif(DEFINED QT_QMAKE_EXECUTABLE)
endif(NOT Q_WS_MAC)
John
More information about the vtkusers
mailing list