CMake, Qt 4.2.1 and application icons
I've just started using CMake to build Qt 4 applications on Windows. The problem is that I cannot get the application icon into place. I've used the RC_FILE variable for this in QMake. Does anyone know how to do it with CMake?
4 Comments:
Are you building with mingw? CMakeurrently not generates needed actions in Makefile to compile and link resource file
Here is what we do in sim-im(http://sim-im.org) to deal with this:
if(MINGW)
# resource compilation for mingw
ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/sim_rc.o
COMMAND windres.exe -I${CMAKE_CURRENT_SOURCE_DIR}
-i${CMAKE_CURRENT_SOURCE_DIR}/sim.rc
-o ${CMAKE_CURRENT_BINARY_DIR}/sim_rc.o)
SET(sim_EXE_SRCS ${sim_EXE_SRCS} ${CMAKE_CURRENT_BINARY_DIR}/sim_rc.o)
else(MINGW)
SET(sim_EXE_SRCS ${sim_EXE_SRCS} sim.rc)
endif(MINGW)
Thanks for the tip - I'll try it right away!
Nice features!
I have made a macro to ease the integration of *.ico in the application.
####################################################################
# Macro To Generate RC file for application Icon
# ------------------------------------------------------------------
# - 18/12/2009: Compil RC file under MinGW work.
#
# ------------------------------------------------------------------
MACRO(MAKE_WINDOWS_PATH pathname)
# An extra \\ escape is necessary to get a \ through CMake's processing.
STRING(REPLACE "/" "\\\\" ${pathname} "${${pathname}}")
# Enclose with UNESCAPED quotes. This means we need to escape our
# quotes once here, i.e. with \"
SET(${pathname} \"${${pathname}}\")
ENDMACRO(MAKE_WINDOWS_PATH)
MACRO(GENERATE_RCICONFILE ICON_SRCS ICON_FILE)
GET_FILENAME_COMPONENT(ICON_FPATH ${CMAKE_CURRENT_SOURCE_DIR}/${ICON_FILE} ABSOLUTE)
if(EXISTS ${ICON_FPATH})
## Only work under windows platform.
if(NOT UNIX)
SET(ICON_RC_FILE "${CMAKE_CURRENT_BINARY_DIR}/appicon.rc")
#CONFIGURE_FILE(${ICON_FPATH} ${CMAKE_CURRENT_BINARY_DIR}/app.ico COPYONLY)
#FILE(WRITE ${ICON_RC_FILE} "IDI_ICON1 ICON DISCARDABLE \"app.ico\"")
SET(ICON_WINFPATH ${ICON_FPATH})
MAKE_WINDOWS_PATH(ICON_WINFPATH)
FILE(WRITE ${ICON_RC_FILE} "IDI_ICON1 ICON DISCARDABLE ${ICON_WINFPATH}")
## Check that we are using MINGW
if(MINGW)
GET_FILENAME_COMPONENT(MINGW_DIR ${CMAKE_C_COMPILER} PATH)
SET(MINGW_WINDRES ${MINGW_DIR}/windres.exe)
# resource compilation for mingw
ADD_CUSTOM_COMMAND(OUTPUT ${ICON_RC_FILE}.o
COMMAND ${MINGW_WINDRES}
ARGS -I${CMAKE_CURRENT_BINARY_DIR} -i ${ICON_RC_FILE} -o ${ICON_RC_FILE}.o
DEPENDS ${ICON_FPATH}
)
SET(ICON_SRCS ${ICON_RC_FILE}.o)
else(MINGW)
SET(ICON_SRCS ${ICON_RC_FILE})
endif(MINGW)
MESSAGE(STATUS "(${ICON_RC_FILE} ${ICON_FILE})")
endif(NOT UNIX)
else(EXISTS ${ICON_FPATH})
MESSAGE(STATUS "Icon file ${ICON_FPATH} not found!")
endif(EXISTS ${ICON_FPATH})
ENDMACRO(GENERATE_RCICONFILE)
Thanks!
Post a Comment
<< Home