[CMake] BundleUtilities

Michael Jackson mike.jackson at bluequartz.net
Wed Nov 17 12:43:32 EST 2010


On Nov 17, 2010, at 12:20 PM, Clinton Stimpson wrote:

> For Qt projects, a macro for creating a qt.conf file and a macro for  
> installing
> Qt plugins would be nice to have in FindQt4.cmake (anyone want to  
> take a stab
> at that?)


To say this needs cleaned up and refactored is an understatement but  
this is what I currently use to find the Qt Image Format plugins and  
make CMake variables for each of them.

#-------------------------------------------------------------------------------
# Finds plugins from the Qt installation. The pluginlist argument  
should be
# something like "qgif;qjpeg;qtiff"
#-------------------------------------------------------------------------------
macro (FindQt4Plugins pluginlist pluginfile libdirsearchfile plugintype)
   set (qt_plugin_list ${pluginlist})
   set (qt_plugin_types "Debug;Release")
   if (WIN32)
     set(qt_plugin_prefix "")
     set(qt_plugin_DEBUG_suffix "d4")
     set(qt_plugin_RELEASE_suffix "4")
   else ()
     set(qt_plugin_prefix "lib")
     set(qt_plugin_DEBUG_suffix "_debug")
     set(qt_plugin_RELEASE_suffix "")
   endif()

   #message(STATUS "qt_plugin_debug_suffix: ${qt_plugin_debug_suffix}")
   set (QTPLUGINS_RELEASE "")
   set (QTPLUGINS_DEBUG   "")
   set (QTPLUGINS "")

   # Loop through all the Build Types and all the plugins to find each  
one.
   foreach(build_type ${qt_plugin_types})
     string(TOUPPER ${build_type} BTYPE)
       foreach(plugin ${qt_plugin_list})
		STRING(TOUPPER ${plugin} PLUGIN)
		# message(STATUS "|-- Looking for ${plugin}${qt_plugin_$ 
{BTYPE}_suffix}")
         FIND_LIBRARY( QT_IMAGEFORMAT_PLUGIN_${PLUGIN}_${BTYPE}
                       NAMES ${plugin}${qt_plugin_${BTYPE}_suffix}
                       PATHS ${QT_PLUGINS_DIR}/${plugintype}
                       DOC "Library Path for ${plugin}"
                       NO_DEFAULT_PATH NO_CMAKE_PATH  
NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH)

         if (MSVC)
             #  message(STATUS "QT_PLUGINS_DIR: ${QT_PLUGINS_DIR}")
             #  message(STATUS " QT_IMAGEFORMAT_PLUGIN_${PLUGIN}_$ 
{BTYPE}: ${QT_IMAGEFORMAT_PLUGIN_${PLUGIN}_${BTYPE}}")
             get_filename_component(lib_path ${QT_IMAGEFORMAT_PLUGIN_$ 
{PLUGIN}_${BTYPE}} PATH)
             get_filename_component(lib_name ${QT_IMAGEFORMAT_PLUGIN_$ 
{PLUGIN}_${BTYPE}} NAME_WE)
             #  message(STATUS "lib_path: ${lib_path}")
             #  message(STATUS "lib_name: ${lib_name}")
             set (QT_IMAGEFORMAT_PLUGIN_${PLUGIN}_${BTYPE} ${lib_path}/ 
${lib_name}.dll CACHE PATH "" FORCE)
             if ( ${QT_IMAGEFORMAT_PLUGIN_${PLUGIN}_${BTYPE}}  
STREQUAL  "QT_IMAGEFORMAT_PLUGIN_${PLUGIN}_${BTYPE}-NOTFOUND")
               message(STATUS "A Companion DLL for ${upperlib}_LIBRARY_ 
${TYPE} was NOT found which usually means"
                                 " that the library was NOT built as a  
DLL. I looked in the "
                                 " following locations:  ${lib_path} 
\n  ${lib_path}/..\n  ${lib_path}/../bin")
             else()
				#  set(${upperlib}_LIBRARY_DLL_${TYPE}  ${${upperlib}_LIBRARY_DLL_$ 
{TYPE}}/${lib_name}.dll)
				#  message(STATUS "${upperlib}_LIBRARY_DLL_${TYPE}: ${$ 
{upperlib}_LIBRARY_DLL_${TYPE}}")
				#  message(STATUS "Generating Install Rule for DLL File for  
QT_IMAGEFORMAT_PLUGIN_${PLUGIN}_${BTYPE}\n  ${QT_IMAGEFORMAT_PLUGIN_$ 
{PLUGIN}_${BTYPE}}")
				INSTALL(FILES ${QT_IMAGEFORMAT_PLUGIN_${PLUGIN}_${BTYPE}}
					DESTINATION ./plugins/${plugintype}
					CONFIGURATIONS ${BTYPE}
					COMPONENT Runtime)
             endif()
		elseif (UNIX AND NOT APPLE)
			INSTALL(FILES ${QT_IMAGEFORMAT_PLUGIN_${PLUGIN}_${BTYPE}}
                 DESTINATION ./plugins/${plugintype}
                 CONFIGURATIONS ${BTYPE}
                 COMPONENT Runtime)

         endif()



         mark_as_advanced(QT_IMAGEFORMAT_PLUGIN_${PLUGIN}_${BTYPE})
		# message(STATUS "|--  QT_IMAGEFORMAT_PLUGIN_${PLUGIN}_${BTYPE}: $ 
{QT_IMAGEFORMAT_PLUGIN_${PLUGIN}_${BTYPE}}")
         LIST(APPEND QTPLUGINS_${BTYPE} ${QT_IMAGEFORMAT_PLUGIN_$ 
{PLUGIN}_${BTYPE}})
       endforeach()
	endforeach()

	# Assign either the debug or release plugin list to the QTPLUGINS  
variable on NON msvc platforms.
	if (NOT MSVC)
	  if ( NOT DEFINED CMAKE_BUILD_TYPE )
		if ( ${CMAKE_BUILD_TYPE} STREQUAL "Debug")
			set (QTPLUGINS ${QTPLUGINS_DEBUG})
		else()
			set (QTPLUGINS ${QTPLUGINS_RELEASE})
		endif()
	  else()
		set (QTPLUGINS ${QTPLUGINS_RELEASE})
	  endif()
	else()
		# Create the qt.conf file so that the image plugins will be loaded  
correctly
		FILE(WRITE ${PROJECT_BINARY_DIR}/qt.conf "[Paths]\nPlugins = plugins")
		INSTALL(FILES ${PROJECT_BINARY_DIR}/qt.conf
				DESTINATION .
				COMPONENT Runtime)
	endif()
	file(APPEND ${pluginfile} "${QTPLUGINS};")
	file(APPEND ${libdirsearchfile} "${QT_PLUGINS_DIR}/imageformats;")
	
endmacro(FindQt4Plugins pluginlist)


___________________________________________________________
Mike Jackson                      www.bluequartz.net
Principal Software Engineer       mike.jackson at bluequartz.net
BlueQuartz Software               Dayton, Ohio





More information about the CMake mailing list