[CMake] Link resource to dll or executable
Darko Miletic
darko at uvcms.com
Tue Nov 1 08:24:46 EST 2005
Hi,
I discovered that implementation of borland makefiel generator is
incomplete or incorrect.
In version 2.2.1 (beta) rc files are being ignored, that is no command
lines are being produced that generate res files.
Furthermore these files can not be added to the dll or executable using
current settings because bcc32 is not designed to handle res files when
passing them to linker.
The only way to link resource files to exe or dll is by using borland
linker ilink32.
This what I did in my script to resolve this issue:
PROJECT(Resourcetest)
SET (SRC dllmain.cpp )
SET ( RESOURCE_FILES_SRC test.rc )
SET ( RESOURCE_FILES test.res )
ADD_LIBRARY (test SHARED ${SRC})
ADD_CUSTOM_COMMAND ( TARGET test
PRE_LINK
COMMAND brcc32
ARGS -fo${RESOURCE_FILES} ${RESOURCE_FILES_SRC}
)
ADD_CUSTOM_COMMAND ( TARGET test
POST_BUILD
COMMAND del
ARGS "<TARGET>"
)
ADD_CUSTOM_COMMAND ( TARGET test
POST_BUILD
COMMAND del
ARGS "<TARGET_BASE>.lib"
)
ADD_CUSTOM_COMMAND ( TARGET test
POST_BUILD
COMMAND ilink32
ARGS ${CMAKE_START_TEMP_FILE}-Gn -Gi -Tpd -aa
c0d32.obj <OBJECTS>,<TARGET>,,<LINK_LIBRARIES>
cw32mti.lib,,${RESOURCE_FILES}${CMAKE_END_TEMP_FILE}
COMMENT "Real build of dll"
)
But the real solution for this would be to do following:
1. Add proper handling of rc files - which means to generate separate
target that will build res file.
2. Add placeholder <RESOURCE_FILES> that will contain generated res file
name(s).
3. Change CMAKE_CXX_CREATE_SHARED_LIBRARY,
CMAKE_C_CREATE_SHARED_LIBRARY, CMAKE_C_LINK_EXECUTABLE,
CMAKE_CXX_LINK_EXECUTABLE
to look like this:
CMAKE_CXX_CREATE_SHARED_LIBRARY/CMAKE_C_CREATE_SHARED_LIBRARY -
ilink32 ${CMAKE_START_TEMP_FILE}-Gn -Gi -Tpd -aa c0d32.obj
<OBJECTS>,<TARGET>,,<LINK_LIBRARIES>
cw32mti.lib,,<RESOURCE_FILES>${CMAKE_END_TEMP_FILE}
CMAKE_C_LINK_EXECUTABLE/CMAKE_CXX_LINK_EXECUTABLE
ilink32 ${CMAKE_START_TEMP_FILE}-Gn -Gi -Tpe -ap c0x32.obj
<OBJECTS>,<TARGET>,,<LINK_LIBRARIES>
cw32mt.lib,,<RESOURCE_FILES>${CMAKE_END_TEMP_FILE}
Of course this is just rough proposal. What needs to be taken into
acount is type of RTL we want and is it console or GUI app.
Darko
More information about the CMake
mailing list