I'm looking into switching my C++ building workflow from use of VisualStudio sln/vcxproj files and Makefiles to using CMake. Compilation is fine, but I'm running into issues when trying to link .res files for our Windows dialogs.
Our project is structured as you would expect a VS project to be structured: it has a solution with a core project, and it relies symbols from other projects. One of the 'libraries' I need for building on Windows is our base dialog .res file, which has been pre-compiled and is available in a directory, but when I try to link that file I get an error stating that it can't link "BaseResource.res.lib".
So of course I've done some Googling on this, and have spent more than a few hours looking for something. The closest I've found is this StackOverflow question on the subject, and I've tried its suggestion which apparently worked for the original ask-er, but it doesn't seem to be working on my end. Currently within my CMakeLists I have:
project(my_project CXX)
...
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
ENABLE_LANGUAGE(RC)
file(TO_CMAKE_PATH "${RES_SOURCE_ROOT}/Source/Resources/Dialogs/Resource.rc"
BASE_RESOURCE_RC)
add_executable( BaseResource ${BASE_RESOURCE_RC})
target_link_libraries(BaseResource "BaseResource.res")
set(BASE_RESOURCE_LINK_FLAGS
"${RES_SOURCE_ROOT}/Lib/${PLATFORM_DIR}/BaseResource.res")
set_target_properties(BaseResource PROPERTIES LINK_FLAGS
${BASE_RESOURCE_LINK_FLAGS})
...
else()
# Do *Nix things.
endif()
Where BaseResource is the previously-undeclared project which is different from this one, and PLATFORM_DIR is the platform-based directory where we keep our binaries, e.g. "windows/v140/32bit". However, when I attempt this, loading the project tells me:
Cannot find source file:
D:/Path/To/Resource/Root/Source/Resources/Dialogs/Resource.rc
Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
.hpp .hxx .in .txx
No SOURCES given to target: BaseResource
To be clear, this project should not care about the sources of other projects - it is specifically meant to compile just this project and to use the libraries from other projects to do so. The use of the above workaround was solely in the hope that it might allow me to use the resource.
I'm honestly at a loss; it's using the MSVC compiler so there really should be no issues in doing this linking, which goes off without a hitch using the VisualStudio solution. Any help on this subject would be hugely appreciated.
Thanks, ~Jon
EDIT: To clarify further, the original error is when I attempt to use:
link_libraries("${RES_SOURCE_ROOT}/Lib/${PLATFORM_DIR}/BaseResource.res")
The original error I get is:
LINK : fatal error LNK1104: cannot open file 'BaseResource.res.lib'
The error with the .rc
file is coming from a workaround, in the event that it was the right direction but lacking some other things.