Build failure with '.tlh' files resulting from `#import` directive in parallel build
Using this cmake code:
cmake_minimum_required(VERSION 3.10)
project(cmaketest)
add_library(tlb
tlblib.cpp
otherfile1.cpp
)
with these source files:
// tlhlib.h
#import "mscorlib.tlb"
#import "System.Drawing.tlb"
#import "System.Windows.Forms.tlb"
// tlblib.cpp
#include "tlblib.h"
// otherfile1.cpp
#include "tlblib.h"
I get the following output from ninja:
C:\Users\Stephen\dev\src\playground\cmake\build>ninja -v
[1/3] C:\PROGRA~2\MICROS~3.0\VC\bin\amd64\cl.exe /nologo /TP /DWIN32 /D_WINDOWS /W3 /GR /EHsc /MDd /Zi /Ob0 /Od /RTC1 /showIncludes /FoCMakeFiles\tlb.dir\otherfile1.cpp.obj /FdCMakeFiles\tlb.dir\tlb.pdb /FS -c ..\otherfile1.cpp
FAILED: CMakeFiles/tlb.dir/otherfile1.cpp.obj
C:\PROGRA~2\MICROS~3.0\VC\bin\amd64\cl.exe /nologo /TP /DWIN32 /D_WINDOWS /W3 /GR /EHsc /MDd /Zi /Ob0 /Od /RTC1 /showIncludes /FoCMakeFiles\tlb.dir\otherfile1.cpp.obj /FdCMakeFiles\tlb.dir\tlb.pdb /FS -c ..\otherfile1.cpp
c:\users\stephen\dev\src\playground\cmake\tlblib.h(2): warning C4278: 'ReportEvent': identifier in type library 'mscorlib.tlb' is already a macro; use the 'rename' qualifier
c:\users\stephen\dev\src\playground\cmake\tlblib.h(3): fatal error C1083: Cannot open compiler generated file: 'c:\users\stephen\dev\src\playground\cmake\build\cmakefiles\tlb.dir\system.drawing.tlh': Permission denied
[2/3] C:\PROGRA~2\MICROS~3.0\VC\bin\amd64\cl.exe /nologo /TP /DWIN32 /D_WINDOWS /W3 /GR /EHsc /MDd /Zi /Ob0 /Od /RTC1 /showIncludes /FoCMakeFiles\tlb.dir\tlblib.cpp.obj /FdCMakeFiles\tlb.dir\tlb.pdb /FS -c ..\tlblib.cpp
c:\users\stephen\dev\src\playground\cmake\tlblib.h(4): warning C4192: automatically excluding 'IDataObject' while importing type library 'System.Windows.Forms.tlb'
ninja: build stopped: subcommand failed.
The problem seems to be that the compiler creates .tlh
files as a side-effect of preprocessing (without anything like lockfiles) and compiling in parallel causes multiple concurrent attempts to write the same tlh
file.
I'm not certain if CMake can do anything about this without pre-scanning all header files or adding some command user interface for users to specify the expected tlh files.