Link a compiled .res file with CMake

北城以北 提交于 2020-01-03 11:27:30

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/17784995/link-a-compiled-res-file-with-cmake

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!