[CMake] Defer compiler to different file in Visual Studio

Andreas Haferburg ahaferburg at scopis.com
Mon Mar 12 17:00:14 EDT 2012


On 12-Mar-12 9:36 PM, Bill Hoffman wrote:
> On 3/12/2012 3:28 PM, Andreas Haferburg wrote:
>> Hello,
>>
>> I'm currently evaluating Lazy C++ [1], which generates both header and
>> source files. I'm using add_custom_command() to invoke the generator on
>> *.lzz file, and for each .lzz file it generates one .hpp file and one
>> .cpp file. What I'm missing is the ability to compile the file I'm
>> currently editing from within Visual Studio.
>>
>> With .cpp files it's possible to compile just one file, e.g. by
>> right-clicking it in the Solution Explorer, then selecting "Compile". Or
>> even better, bind it to a hotkey.
>>
>> So what I'd like to do is for each lzz file, set the compile command to
>> compile the corresponding cpp file. I can't imagine it being that hard,
>> since one would merely have to change the file extension in the command
>> line from cpp to lzz. Any ideas?
>>
>> I'm not sure though, this might be more of a Visual Studio-specific
>> question than a CMake-specific one.
>
>
> Lzz is not a compiler, but rather a code generator. I would set things
> up so that you do something like this:
>
> create_lzz_source_list(MY_CPP_HH_SOURCES foo.lzz bar.lzz car.zzz)
> add_library(mylib ${MY_CPP_HH_SOURCES})
>
> # create_lzz_sources would be a function that creates a bunch of custom
> commands that run lzz on each lzz input file and create a .cpp and .hh
> file. So, there should be a custom command for each .cpp and .hh file.
> You should be able to click on one of those can select compile, and it
> will run that file.
>
> This is the exact type of thing that is done for the VTK code wrapper code.

Yea, that's pretty much what I've got so far. And yes, I realize that's 
the way it's *supposed* to be set up. ;) I've posted my CMakeLists.txt 
here if you want to have a look:
http://stackoverflow.com/a/9669388/872616

The only time I would really like to have anything to do with generated 
files is if something goes wrong with the generation, but not during 
normal development. I'd like to set up the tool chain such that I only 
have to touch the .lzz files, and the .hpp/.cpp would be completely 
hidden away in the build dir. Just as normally you wouldn't want to have 
anything to do with .obj files, you know?

Cheers
Andreas


More information about the CMake mailing list