Link the compiled .res file to CMake

I am trying to link a compiled .res file to cmake, but I cannot find much information on how to do this.

The closest I got

SET(RESOURCE_FILE resource.res) file(GLOB src_files "src/*.h" "src/*.cpp" "${RESOURCE_FILE}" ) add_executable(exename ${src_files}) 

and then manually link the .res file through the IDE (i.e., in visual studio, delete the .res file in additional Linker dependencies). This means that I must reset to add an additional dependency every time I modify the cmake file. Of course there is a better way than this

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

+4
source share
1 answer

The default lib extension is a bit sticky, but you can do the following:

 # ... 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 will be displayed in MSVC as additional [linker] options (instead of dependencies). Hope this helps.

If other LINK_FLAGS , you may need to save them to FOO_LINKFLAGS first and then add new ones.

+3
source

Source: https://habr.com/ru/post/1492675/


All Articles