MantisBT - CMake
View Issue Details
0008165CMakeCMakepublic2008-11-25 09:512012-03-16 13:07
Robert Lenhardt 
David Cole 
normalminoralways
closedfixed 
CMake-2-6 
CMake 2.8.4CMake 2.8.4 
0008165: vs2005 midl chokes on CMAKE_INTDIR
The midl compiler of Visual Studio 2005 chokes on the CMAKE_INTDIR define which is added by cmake. The problem is the escaped double quote in

/D "CMAKE_INTDIR=\"Debug\""

midl hands them over to the preprocessor as /D "CMAKE_INTDIR=\" and thinks Debug\"" is the input file:

BuildLog command line:

Creating temporary file "c:\foo\Debug\RSP00016D23004524.rsp" with contents
[
/D "CMAKE_INTDIR=\"Debug\"" /char signed /env win32 /Oicf /tlb "foo.tlb" /out "foo.dir\Debug" /h "foo.h" /iid "foo_i.c" /proxy "foo_p.c"

foo.idl
]
Creating command line "midl.exe @c:\foo\Debug\RSP00016D23004524.rsp /nologo"

BuildLog Output:

Creating Type Library...
midl : command line warning MIDL1009 : unknown argument ignored "foo.idl"
Processing Debug\""
Debug""
c1 : fatal error C1083: Cannot open source file: 'Debug""': Invalid argument
midl : command line error MIDL1003 : error returned by the C preprocessor (2)

I don't know if this behavior was fixed in recent versions. This is certainly a bug of midl, but i can not switch off the CMAKE_INTDIR define easily as it is hardcoded in the C++ sources. So right now i have to manually remove the double quotes after a cmake run. It would be nice to select the inclusion of this define maybe per target or per file.
No tags attached.
related to 0011311closed David Cole Visual Studio 2008 MIDL and cmake 2.8.2 
related to 0010687closed David Cole VC 2010 generator ignores .idl Files and doesn't produce .tlb file 
related to 0011461closed David Cole finish midl support for VS2010 Generator 
related to 0013043closed Kitware Robot IDL files do not supported if used NMake Makefiles generator 
patch cmLocalVisualStudio7Generator.cxx.patch (2,258) 2008-12-03 03:18
https://public.kitware.com/Bug/file/1887/cmLocalVisualStudio7Generator.cxx.patch
patch patch_cmake_midl_VS2005.patch (2,536) 2010-01-21 01:07
https://public.kitware.com/Bug/file/2789/patch_cmake_midl_VS2005.patch
patch cmLocalVisualStudio7Generator.cxx.2.8.0.patch (2,128) 2010-01-29 06:16
https://public.kitware.com/Bug/file/2822/cmLocalVisualStudio7Generator.cxx.2.8.0.patch
patch no_ppdefs_for_midl.patch (433) 2010-11-13 02:14
https://public.kitware.com/Bug/file/3492/no_ppdefs_for_midl.patch
zip VSMidl.zip (953) 2010-11-15 15:43
https://public.kitware.com/Bug/file/3500/VSMidl.zip
Issue History
2008-11-25 09:51Robert LenhardtNew Issue
2008-12-03 03:18Robert LenhardtFile Added: cmLocalVisualStudio7Generator.cxx.patch
2008-12-03 03:24Robert LenhardtNote Added: 0014273
2009-01-29 14:35Bill HoffmanStatusnew => assigned
2009-01-29 14:35Bill HoffmanAssigned To => David Cole
2009-06-08 05:57Lluís BatlleNote Added: 0016649
2009-11-03 12:01Jeroen DierckxNote Added: 0018331
2009-12-03 09:19qbprogerNote Added: 0018691
2010-01-21 01:07gfr10File Added: patch_cmake_midl_VS2005.patch
2010-01-21 01:07gfr10Note Added: 0019235
2010-01-29 06:16Robert LenhardtFile Added: cmLocalVisualStudio7Generator.cxx.2.8.0.patch
2010-01-29 06:17Robert LenhardtNote Added: 0019362
2010-11-12 06:28David ColeTarget Version => CMake 2.8.4
2010-11-12 07:16David ColeNote Added: 0023198
2010-11-12 13:23Robert LenhardtNote Added: 0023209
2010-11-12 17:05Robert LenhardtNote Added: 0023230
2010-11-12 17:15ScottNote Added: 0023231
2010-11-13 02:14Robert LenhardtFile Added: no_ppdefs_for_midl.patch
2010-11-13 02:27Robert LenhardtNote Added: 0023236
2010-11-15 07:56David ColeNote Added: 0023254
2010-11-15 08:09David ColeRelationship addedrelated to 0011311
2010-11-15 15:43Robert LenhardtFile Added: VSMidl.zip
2010-11-15 15:47Robert LenhardtNote Added: 0023268
2010-12-15 09:16David ColeRelationship addedrelated to 0010687
2010-12-15 12:13David ColeRelationship addedrelated to 0011461
2011-01-05 11:08David ColeNote Added: 0024421
2011-01-05 11:08David ColeStatusassigned => resolved
2011-01-05 11:08David ColeFixed in Version => CMake 2.8.4
2011-01-05 11:08David ColeResolutionopen => fixed
2011-05-02 14:45David ColeNote Added: 0026308
2011-05-02 14:45David ColeStatusresolved => closed
2012-03-16 13:07Brad KingRelationship addedrelated to 0013043

Notes
(0014273)
Robert Lenhardt   
2008-12-03 03:24   
I made a fix in cmLocalVisualStudio7Generator.cxx where the CMAKE_INTDIR define is passed to the midl compiler through AdditionalOptions and not with PreprocessorDefinitions. This way the define which already has quotes in it does not get double quoted as a whole by the IDE. This fixes the problem. Maybe all defines with double quotes should be passed this way -- in my project i do not have any of those.
(0016649)
Lluís Batlle   
2009-06-08 05:57   
I need to use the midl compiler in one of my projects, and I hit with this problem. Is there any chance to have that in a cmake release anytime soon?
Regards,
Lluís.
(0018331)
Jeroen Dierckx   
2009-11-03 12:01   
This still doesn't work correctly in Visual Studio 2008, with cmake 2.6-patch4.
(0018691)
qbproger   
2009-12-03 09:19   
Just ran into this with Visual Studio 2005, cmake 2.6-patch4. I was trying to convert from vcproj files to cmake. If you'd like me to test with cmake 2.8 I can.
(0019235)
gfr10   
2010-01-21 01:07   
Added patch for cmake-2.8.0.
(0019362)
Robert Lenhardt   
2010-01-29 06:17   
I added a patch with my not so intrusive fix for 2.8.0.
I can also confirm that this bug applies to VS2008.
So i ask you to put this little fix in the next CMake release.
It would make those locked up in COM very happy.
Thank you, keep up the good work!
(0023198)
David Cole   
2010-11-12 07:16   
I have been discouraged from simply applying the simple patch because:
- it only deals with the one CMAKE_INTDIR define, and it should apply to any define that is double-quoted
- it's not clear to me that we should be passing all the C++ defines as MIDL defines in the first place
- there is no test in the CMake test suite that will automatically verify this as fixed on the dashboard runs

If everybody listening in on this bug thinks the simple patch is sufficient, then I guess I should apply it -- after all, it's better than the way things are now, right?

Chime in, add a note, and let me know how many people are listening here, and if you all think the "cmLocalVisualStudio7Generator.cxx.2.8.0.patch" is sufficient.
(0023209)
Robert Lenhardt   
2010-11-12 13:23   
Hi everybody,

i can understand your points, but here are some points in favor of this patch:

- the CMAKE_INTDIR macro is special because it is inserted unconditionally -- you can work around in CMakeLists.txt if there is some misbehaving define in one of the COMPILE_DEFINITIONS variables
- witout it you can not include .idl files as cmake sources for VS2005/8

I had a look at the possibility to pass all preprocessor defintions as additional options, but it looks as if you need to change the Options class a lot to make it work, or capture the output of OutputPreprocessorDefinitions and do some dirty string replacement (the following does not work because the defines are missing the /D):

std::ostringsstream oss;
targetOptions.OutputPreprocessorDefinitions(oss, "\n\t\t\t\t", "");
std::string addOptions = oss.str();
std::string::size_type p = 0;
while (p=addOptions.find(p,"PreprocessorDefinitions") != std::string::npos) {
   addOptions.replace(p,"AdditionalOptions");
}

So i would opt for including the patch. Regarding your third point -- please point me to the code of some example test for cmake and i will happily provide you with a midl test. I would say the test should do a midl run on an empty .idl file to at least make sure that cmake can run midl out of the box.
(0023230)
Robert Lenhardt   
2010-11-12 17:05   
On second thought i favor the removal of preprocessor definitions for midl altogether. If you need defines passed to the idl file you can include a header.
If you add an idl file to an empty Visual Studio project, there are no default defines in the vcproj for midl. So there is no need to try to force passing definitions to the midl commandline in CMake. What do the idl experts monitoring this issue think?
(0023231)
Scott   
2010-11-12 17:15   
It would be nice to see a fix for this in the next release so the patch doesn't have to be applied each time a new one is downloaded.
(0023236)
Robert Lenhardt   
2010-11-13 02:27   
Just for the record there is now a patch with the removal of the preprocesor options for midl. I have tested it with my idl files and can can confirm it works.

Thank you David for bringing up that issue once again. Sometimes you need to think for two years to remove one line of code ;-)

Can you point me to an example of the cmake test suite, so i can create a simple midl test for the dashboard runs?
(0023254)
David Cole   
2010-11-15 07:56   
The CMake test suite is best approached through CMake/Tests/CMakeLists.txt. Many of the subdirectories of CMake/Tests are standalone projects that get built as part of running ctest on CMake itself.

A test for this is probably best wrapped in a block like this:
  IF(${CMAKE_TEST_GENERATOR} MATCHES "Visual Studio")

...similar to the VSExternalInclude test.
(0023268)
Robert Lenhardt   
2010-11-15 15:47   
I added a midl test run on a barebone idl file with small check if generated files are includeable in main. You can add the following to Tests/CmakeLists.txt right after the VSExternalInclude Test:

    ADD_TEST(VSMidl ${CMAKE_CTEST_COMMAND}
      --build-and-test
      "${CMake_SOURCE_DIR}/Tests/VSMidl"
      "${CMake_BINARY_DIR}/Tests/VSMidl"
      --build-two-config
      --build-generator ${CMAKE_TEST_GENERATOR}
      --build-project VSMidl
      --build-makeprogram ${CMAKE_TEST_MAKEPROGRAM}
      --test-command VSMidl)
    LIST(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/VSMidl")
(0024421)
David Cole   
2011-01-05 11:08   
Fixed by this commit, just pushed to CMake 'next':
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=13caaa3eb74a11dbf067409ea129321718d34dfe [^]

I expect this will make it into the upcoming CMake 2.8.4 release. I will update this and related issues with another note if that expectation turns out to be too optimistic... :-)
(0026308)
David Cole   
2011-05-02 14:45   
Closing resolved issues that have not been updated in more than 3 months.