[CMake] Compiling two versions of file/program

Rob McDonald rob.a.mcdonald at gmail.com
Mon Jan 20 10:20:41 EST 2014


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.

We also have an API/Library mode with no main(), but that can have graphics
or not.

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.

I think the workaround will be to have two CMakeLists.txt a level deeper
than the file with main().


\maindir
  CMakeLists.txt_1
  main.cpp
\maindir\graphics
  CMakeLists.txt_2
\maindir\headless
  CMakeLists.txt_3

Where...
CMakeLists.txt_1 is basically:
add_directory( graphics )
add_directory( headless )

And then _2 and _3 set the -DFOO at their level and include the source with
a ../main.cpp

Is there another/better way?

Rob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20140120/5a66a7fd/attachment.html>


More information about the CMake mailing list