cmake 处理与平台相关的源代码

alanwhy

关注

阅读 65

2023-01-13


​​代码在git​​

通过 cmake 宏定义来实现

#include <cstdlib>
#include <iostream>
#include <string>

std::string say_hello() {
#ifdef IS_WINDOWS
return std::string("Hello from Windows!");
#elif IS_LINUX
return std::string("Hello from Linux!");
#elif IS_MACOS
return std::string("Hello from macOS!");
#else
return std::string("Hello from an unknown system!");
#endif
}

int main() {
std::cout << say_hello() << std::endl;
return EXIT_SUCCESS;
}


精彩评论(0)

0 0 举报