Допустим есть такой CMakeLists.txt файл:
set(MYTARGET "target")
# we have some string var that we want to convert to correct define for pre-compiler
set(INTERFACES_VERSION_STR "-2016.10.23-" )
# remove all points (".")
string(REPLACE "." "" MY_INTERFACES_VER ${INTERFACES_VERSION_STR})
# remove all "-" symbols
string(REPLACE "-" "" MY_INTERFACES_VER ${MY_INTERFACES_VER})
# print them
message(STATUS "INTERFACES_VERSION_STR ${INTERFACES_VERSION_STR}")
message(STATUS "MY_INTERFACES_VER ${MY_INTERFACES_VER}")
add_library(${MYTARGET} my_source.cpp)
add_definitions(-DMY_INTERFACES_VER=${MY_INTERFACES_VER})
Тогда в исходном файле пишем:
//...
#if MY_INTERFACES_VER==20161023
#include "v20161023/include/interfaces.h"
#include "v20161023/include/interfaces.h"
std::cout << "---- MY_INTERFACES_VER==20161023 ---" << std::endl;
#else
#include "mainline/include/interfaces.h"
#include "mainline/include/interfaces.h"
std::cout << "do some by default " << std::endl;
#endif
Комментариев нет:
Отправить комментарий