[CMake] Win DLL with rc-file...

Lars Pechan lars.pechan at parkerpechan.com
Mon Oct 25 22:26:20 EDT 2004


Hi Brad,
Sorry I should have pointed out that I have tried this as well. Here is 
my CMakeLists.txt (apologies for length):

#
# CMakeLists.txt
#
# CMake build file for X.
#

SET(CMDSDIR ${Y_SOURCE_DIR}/scripts)
SET(RCFILE ${CMAKE_CURRENT_BINARY_DIR}/XBtm.rc)
SET(SPLASH ${Y_SOURCE_DIR}/splash.gif)

# These are the files from the 'others' directory that we copy in here:
SET(otherFiles colourPic.bmp
                colourS.bmp)

# Copy files into build tree.
FOREACH(ofile ${otherFiles})
ADD_CUSTOM_COMMAND(
   OUTPUT ${ofile}
   COMMAND ${CMAKE_COMMAND}
   ARGS -E copy ${CMAKE_CURRENT_SOURCE_DIR}/others/${ofile} ${ofile}
)
ENDFOREACH(ofile)

# These are stubbs that we simply copy locally:
SET(stubbFiles genbmp.awk bmp.awk CMbmp.rc Cgenbmp.win)
FOREACH(stubb ${stubbFiles})
ADD_CUSTOM_COMMAND(
   OUTPUT ${stubb}
   COMMAND ${CMAKE_COMMAND}
   ARGS -E copy ${CMAKE_CURRENT_SOURCE_DIR}/${stubb} ${stubb}
   MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/${stubb}
)
ENDFOREACH(stubb)

#
ADD_CUSTOM_COMMAND(
   OUTPUT X.txt
   COMMAND ${CMAKE_COMMAND}
   ARGS -E copy ${CMDSDIR}/icons.txt X.txt
   DEPENDS ${CMDSDIR}/icons.txt
)

# This causes Unix2Dos to run on each make but Unix2Dos is
# idempotent so that's OK. (I.e. doing Unix2Dos on an already
# Unix2Dosed file does nothing).
IF (WIN32 AND UNIXSOURCE)
   ADD_CUSTOM_TARGET(convFile ${UNIX2DOS} X.txt DEPENDS X.txt)
ELSE (WIN32 AND UNIXSOURCE)
   ADD_CUSTOM_TARGET(convFile DEPENDS X.txt)
ENDIF (WIN32 AND UNIXSOURCE)

ADD_CUSTOM_COMMAND(
   OUTPUT ${RCFILE}
   COMMAND ${AWK}
   ARGS -f bmp.awk -v STUBB=CMbmp.rc -v SPLASH=X -v SPL=splash X.txt > 
${RCFILE}
   DEPENDS convFile bmp.awk CMbmp.rc XMake.win
)
#SET_SOURCE_FILES_PROPERTIES(${RCFILE} PROPERTIES GENERATED true)

# Convert gis to bmp
ADD_CUSTOM_COMMAND(
   OUTPUT convGifs
   COMMAND ${CMAKE_MAKE_PROGRAM}
   ARGS -f XMake.win
   MAIN_DEPENDENCY ${RCFILE}
   DEPENDS XMake.win ${Y_SOURCE_DIR}/bitmaps/color/some.gif
)

ADD_CUSTOM_COMMAND(
   OUTPUT some.gif
   COMMAND ${CMAKE_COMMAND}
   ARGS -E copy ${Y_SOURCE_DIR}/bitmaps/splash.gif some.gif
)

ADD_CUSTOM_COMMAND(
   OUTPUT XMake.win
   COMMAND ${AWK}
   ARGS -f genbmp.awk -v DEPEND=1 -v STUBB=Cgenbmp.win -v SPLASH=X X.txt 
 > XMake.win &&
   ${AWK} -f genbmp.awk -v DEPEND=0 -v SPLASH=X X.txt >> XMake.win
   DEPENDS X.txt genbmp.awk Cgenbmp.win
)

SET(cleanFiles $stubbFiles} ${otherFiles} ${RCFILE} X.txt)

SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_NMAKE_CLEAN_FILES 
"${cleanFiles}")

# Make a dll with the bitmaps:
ADD_LIBRARY(X1btm SHARED ${RCFILE} images.c)

######## End of file

I may have stuffed the file when obfuscating it. Basically all the 
steps do what they should except I can't get CMake to put in the 
reference to the rc-file on the link line.

Thanks for your help,

/Lars


On 26/10/2004, at 2:18 PM, Brad King wrote:

> Lars Pechan wrote:
>> Hello,
>> I'm trying to create a Win32 DLL that contains some resources.
>> I've read that you should be able to just add an rc-file to an exe or 
>> a lib/dll and CMake should figure out what to do.
>> In my CMakeLists.txt I have
>> SET(RCFILE XX.rc)
>> ADD_LIBRARY(libX SHARED XX.c ${RCFILE})
>> The rc-file is generated on the fly and lives in 
>> ${CMAKE_CURRENT_BINARY_DIR} whereas XX.c lives in 
>> ${CMAKE_CURRENT_SOURCE_DIR}. I have tested marking ${RCFILE} as 
>> GENERATED using SET_SOURCE_FILES_PROPERTIES(${RCFILE} PROPERTIES 
>> GENERATED true) but that makes no difference whatsoever.
>> The link line in the generated Makefile contains no trace of the 
>> res-file (assuming the generation is from .rc to .res for the 
>> linker).
>> However, if I manually add the (hand-generated) .res file to the 
>> linker line everything is fine.
>> Any ideas why this is not working?
>
> Sicne the .rc file is in the build tree, try specifying the full path:
>
> SET(RCFILE ${CMAKE_CURRENT_BINARY_DIR}/XX.rc)
>
> If the rc file is generated as the OUTPUTS of a custom command then 
> you do not need to mark it generated because the custom command will 
> automatically do so.  Just be sure to specify it as a full path 
> everywhere.
>
> -Brad



More information about the CMake mailing list