开发者

cmake: Building multiple versions of a program

I would like to write a cma开发者_运维问答ke script that will compile the same source against multiple versions of header files. The aim is to be able to easily create shared libraries that are backwards compatible with earlier versions of an API.

I am looking for examples and pointers on the best way to do this.

I am new to both c++ and cmake so any help will be greatly appreciated.


This answer is a bit off the top of my head, so take it with a grain of salt.

In your source code do this:

#ifdef Version_1_0
#include "Header_1_0.h"
#endif

#ifdef Version_2_0
#include "Header_2_0.h"
#endif

In the CMakeLists.txt file do this:

add_library ( Foo_Version_1_0 SHARED Foo.cxx Header_1_0.h )
# When you compile Foo_Version_1_0, define "Version_1_0"
set_target_properties ( Foo_Version_1_0 PROPERTIES COMPILE_FLAGS -DVersion1_0 )

# Likewise for Version_2_0
...

When you are finished building, you should have two libraries called libFoo_Version_1_0.so and libFoo_Version_2_0.so.

Cheers,
-dan

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜