Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Link a compiled .res file with CMake

I'm trying to link a compiled .res file with cmake but I can't seem to find out much info on how to do it.

The closest I have got is

SET(RESOURCE_FILE resource.res)

file(GLOB src_files 
"src/*.h"
"src/*.cpp"
"${RESOURCE_FILE}"
)

add_executable(exename  ${src_files})

and then manually linking the .res file thru the IDE (i.e. in visual studio dropping the .res file in the Linker additional dependencies). This means I have to reset the additional dependency every time I change the cmake file. Surely there is a better way than this

Forgive my inexperience with cmake, any help would be appreciated.

like image 542
Biggy Smith Avatar asked Jul 22 '13 10:07

Biggy Smith


1 Answers

Default lib extension is a bit sticky one, but you can do as follows:

# ...
ADD_EXECUTABLE( FOO ${FOO_SRCS} )
TARGET_LINK_LIBRARIES( FOO ${FOO_LIBS} )
SET( FOO_LINKFLAGS ${CMAKE_CURRENT_SOURCE_DIR}/foo.res )
SET_TARGET_PROPERTIES( FOO PROPERTIES LINK_FLAGS ${FOO_LINKFLAGS} )

which would show up in MSVC as additional [linker] options (instead of dependencies). Hope that helps.

If there are other LINK_FLAGS defined, you may need to first store them in the FOO_LINKFLAGS and then append new ones.

like image 154
Vaaksiainen Avatar answered Oct 25 '22 10:10

Vaaksiainen