[CMake] Copy dlls to release and debug folder

Thomas Richard Thomas.Richard at imgtec.com
Thu Apr 18 06:51:01 EDT 2013


Hi Lloyd,

Personally I copy the DLLs to the VS folder (so that the program can be run from visual studio) using the following script.
It looks more complicated than it is.

A macro is available to several of my projects to select which Qt module they use and create a list of dlls to copy.
Then I simply choose where to copy the DLLs according to the generator.
I also add them to the list of files to install.
Finally the last line is to remove the command prompt opening.



MACRO(GetQtDLLs DEBUG_NAME RELEASE_NAME)

FOREACH(module QT3SUPPORT QTOPENGL QTASSISTANT QTDESIGNER QTMOTIF QTNSPLUGIN
               QAXSERVER QAXCONTAINER QTDECLARATIVE QTSCRIPT QTSVG QTUITOOLS QTHELP
               QTWEBKIT PHONON QTSCRIPTTOOLS QTMULTIMEDIA QTGUI QTTEST QTDBUS QTXML QTSQL
               QTXMLPATTERNS QTNETWORK QTCORE)

	if (QT_USE_${module} OR QT_USE_${module}_DEPENDS)

		string(REPLACE ".lib" ".dll" QT_${module}_DLL "${QT_${module}_LIBRARY_DEBUG}")
		set (${DEBUG_NAME} ${${DEBUG_NAME}} ${QT_${module}_DLL})
		
		string(REPLACE ".lib" ".dll" QT_${module}_DLL "${QT_${module}_LIBRARY_RELEASE}")
		set (${RELEASE_NAME} ${${RELEASE_NAME}} ${QT_${module}_DLL})
	
	endif()
  
ENDFOREACH(module)

ENDMACRO()

if (WIN32)
	GetQtDLLs(DEBUG_DLLS RELEASE_DLLS)
	
	if (${CMAKE_GENERATOR} MATCHES "Visual Studio 11")
		# visual studio 12 expects the DLLs in the executable folder.
		# but not the resources!
		# can be changed into the environment property of the project to include the project's directory
		set (DLL_TO_DBG ${CMAKE_CURRENT_BINARY_DIR}/Debug)
		set (DLL_TO_RELEASE ${CMAKE_CURRENT_BINARY_DIR}/Release)
	else()
		# for other version of visual studio the DLLs are expected into the project folder
		set (DLL_TO_DBG ${CMAKE_CURRENT_BINARY_DIR})
		set (DLL_TO_RELEASE ${CMAKE_CURRENT_BINARY_DIR})
	endif()
	
	foreach(dll ${DEBUG_DLLS})
		file(COPY ${dll} DESTINATION ${DLL_TO_DBG})
	endforeach()
	
	foreach(dll ${RELEASE_DLLS})
		file(COPY ${dll} DESTINATION ${DLL_TO_RELEASE})
	endforeach()
		
	install(FILES ${RELEASE_DLLS} DESTINATION ${INSTALL_FELIXPARAMGUI_PATH} CONFIGURATIONS Release)
		
	#
	# this is disabled for debug only (so signal/slots connect failures are seen)!
	#
	# this property is used to remove the prompt window when running the GUI from the explorer on WIN32
	# doesn't have effect on linux 
	#
	set_target_properties(FelixParamGui PROPERTIES WIN32_EXECUTABLE ${FELIXPARAMGUI_WIN32EXE})
endif()

From: cmake-bounces at cmake.org [mailto:cmake-bounces at cmake.org] On Behalf Of Lloyd
Sent: 18 April 2013 11:33
To: CMake ML
Subject: [CMake] Copy dlls to release and debug folder

Hi,

I was successful in creating and building a project using CMake on Windows (Visual Studio). After the build when I try to run the application it throws an error asking for the dlls of Qt (I know it is a common case in Windows, usually we do copy the dlls to debug/release folder where the exe resides). When I searched the mailing list, I have seen an advise to use "add_custom_command(TARGET ...)". Is this the right approach? Wont it be executed after each build, thus causing repeated dll copies? 

Can you please suggest me the right way?

Thanks,
  Lloyd



More information about the CMake mailing list