VS generator add switch before /link switch

Hello,

The following mimic command to be run during the Link stage is generated by CMake with VS generator:

cl.exe /Fe"out.exe" main.obj /Zi /WX- /MDd /nologo /link /machine:x64 kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib

The arguments passed after the switch /link are expected to be passed to the linker.

Using target_link_options, the option will be added after the /link switch.

I would like to pass additional argument BEFORE the /link switch. Is there a way to do it in CMakeLists.txt?

Best Regards,
Amon

AFAIK, all arguments are passed to the linker. For instance, the linker needs /Fe"out.exe" to know the filename of the output, and main.obj to know what to include, and both these arguments are passed before /link.

If you want to change how main.cpp (or main.cc, or main.c) is compiled, then you should use target_compile_options.

I hope this helps.