I recently had to build a static library using CMake. In the current CMake version, apparently something has changed in the linker settings.
The build always ended with an error:
LINK : fatal error LNK1123: failure during conversion to COFF: file invalid
or corrupt [D:\0.GIT\libarchive-3.1.2\vc10.32\CMakeFiles\CMakeTmp\cmTC_bbd0c.vcxproj]
Looking at the linker settings, I found that CMake seems to enable incremental linking by default and this is the root cause for the trouble; at least with Visual Studio 2010
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\link.exe /ERRORREPORT:QUEUE
/NOLOGO kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib
/SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT
cmTC_bbd0c.dir\Debug\testCCompiler.obj /machine:X86 /debug
I searched the web for a solution, but could not find anything that really works. So here is what I did to fix the issue.
In in [CMakePrgmDir]\share\cmake-3.3\Modules\Platform\windows.cmake
modify the line 242 ( might be different in other versions )
# add /debug and /INCREMENTAL:YES to DEBUG and RELWITHDEBINFO also add pdbtype
# on versions that support it
set( MSVC_INCREMENTAL_YES_FLAG "")
if(NOT WINDOWS_PHONE AND NOT WINDOWS_STORE)
set( MSVC_INCREMENTAL_YES_FLAG "/INCREMENTAL:YES")
#set( MSVC_INCREMENTAL_YES_FLAG "/INCREMENTAL" ) ' comment out here
set( MSVC_INCREMENTAL_YES_FLAG "/INCREMENTAL:NO" )
With this modification in place, I was now able to let CMake create the project configuration files.