<div dir="ltr">My project can be compiled with support for graphics, or in a completely headless mode with no dependencies on any graphics libraries. By and large, this is accomplished with the same source code and a very few #define 's. <div>
<br></div><div>We also have an API/Library mode with no main(), but that can have graphics or not.</div><div><br></div><div>I'd like to use CMake to compile both versions of these in one go. However, I don't see any way to make a -DFOO for just a single file, or to compile two versions of a single object to then be used later.</div>
<div><br></div><div>I think the workaround will be to have two CMakeLists.txt a level deeper than the file with main().</div><div><br></div><div><br></div><div>\maindir</div><div> CMakeLists.txt_1</div><div> main.cpp</div>
<div>\maindir\graphics</div><div> CMakeLists.txt_2</div><div>\maindir\headless</div><div> CMakeLists.txt_3</div><div><br></div><div>Where...</div><div>CMakeLists.txt_1 is basically:</div><div>add_directory( graphics )</div>
<div>add_directory( headless )</div><div><br></div><div>And then _2 and _3 set the -DFOO at their level and include the source with a ../main.cpp</div><div><br></div><div>Is there another/better way?</div><div><br></div><div>
Rob</div><div><br></div><div> </div></div>