[CMake] Compiling two versions of file/program

J Decker d3ck0r at gmail.com
Mon Jan 20 10:36:33 EST 2014


It's actually very simple.
Use target properties to set the flags you need (assuming that said
flag doesn't break other sources)

SET_PROPERTY(TARGET bag.video.puregl2 APPEND PROPERTY
COMPILE_DEFINITIONS
"RENDER_LIBRARY_SOURCE;_OPENGL_ENABLED;_OPENGL_DRIVER;MAKE_RCOORD_SINGLE"
)

You can also copy sources that are replicated into a directory in the
${CMAKE_BINARY_DIR}
There is a way to set flags on a single source file, but any time that
same source file name (with full path) is used, it gets those flags;
it's better to work with target flags.


You can just add_library() for each version in the same cmakelists

On Mon, Jan 20, 2014 at 7:20 AM, Rob McDonald <rob.a.mcdonald at gmail.com> wrote:
> 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
>
>
>
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake


More information about the CMake mailing list