I am trying to use CMake with the MSVC compiler/linker via a custom toolchain.
Everything works good until a project tries to specify custom link libraries, like this:
Microsoft (R) Incremental Linker Version 14.13.26132.0
Copyright (C) Microsoft Corporation. All rights reserved.
CMakeFiles/Simulator.dir/src/simulator.c.obj
LINK : fatal error LNK1181: cannot open input file 'Rpcrt4.obj'
What seems to be happening is the libraries at the end (Rpcrt4 & Ws2_32) have the extension stripped. This works okay with linkers that use LINK_LIBRARY_FLAG (e.g. gcc), but the Microsoft linker uses file extensions. Libraries that are coming from target_link_libraries(Simulator … come to the link line with .lib extension and work fine.
Seems like the problem is the library suffix variable is getting overwritten.
As shown in the dump below, the toolchain file is included (twice) when the project() command is executed, but the results are lost between the toolchain file and dump 2.
Should the toolchain be setting variables in the CACHE with FORCE?
The examples in cmake-toolchains show the toolchain setting values in regular variables, not the CACHE.
My whole toolchain (revised from what I posted before):
dump.cmake just prints out the watched vars
Update - It seems the overwrite of the setting is coming from setting CMAKE_SYSTEM_NAME to Generic. in other words, CMakeGenericSystem.cmake.
I was able to create my own MySystem.cmake file and load it with set(CMAKE_SYSTEM_NAME MySystem) from my toolchain file by setting CMAKE_MODULE_PATH.
That allowed me to change the suffixes and flags to whatever I want, but I was surprised that a “Generic” system wasn’t already an empty template where I could specify things from the toolchain.
This has left me a bit puzzled about which settings should be in a custom toolchain file and which should be in a custom system module, and whether there are any other modules that I need to customize to get a truly “Empty” default where my project files can specify all the build details and command lines.
Ideally, I’d like to keep CMake’s notion of relationships between source, objects, libraries, linkers, compilers, and archivers, while loading all the details and assumptions about command syntax, flags, options, and so forth from files CMakeLists and Module files in my project tree.
Is there a list somewhere that separates which build variables belong in which file (toolchain vs. system) and whether there are any other files I need to customize for a really “new” System?
As originally designed, toolchain files are meant to be specific to the host machine and set things like paths to compilers. All information that is common to the target platform should go a Platform/ module under CMAKE_MODULE_PATH.