将已编译的.res文件与CMake链接 [英] Link a compiled .res file with CMake
问题描述
我正在尝试将已编译的.res文件与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.
我最近的是
SET(RESOURCE_FILE resource.res)
file(GLOB src_files
"src/*.h"
"src/*.cpp"
"${RESOURCE_FILE}"
)
add_executable(exename ${src_files})
,然后通过IDE手动链接.res文件(即,在Visual Studio中,将.res文件放入链接器的其他依赖项中).这意味着我每次更改cmake文件时都必须重置其他依赖项.当然有比这更好的方法了
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
原谅我对cmake的经验不足,将不胜感激.
Forgive my inexperience with cmake, any help would be appreciated.
推荐答案
默认的lib扩展名有点粘性,但是您可以执行以下操作:
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} )
,它将在MSVC中显示为其他[链接器]选项(而不是依赖项).希望能有所帮助.
which would show up in MSVC as additional [linker] options (instead of dependencies). Hope that helps.
如果定义了其他 LINK_FLAGS
,则可能需要先将它们存储在 FOO_LINKFLAGS
中,然后再添加新的.
If there are other LINK_FLAGS
defined, you may need to first store them in the FOO_LINKFLAGS
and then append new ones.
这篇关于将已编译的.res文件与CMake链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!