c++ - 将 CMake 变量传递给 C++ 源代码

标签 c++ cmake

<分区>

首先,我已经阅读了How to read a CMake Variable in C++ source code ,我真的不知道它是否可以帮助我。

第二,我的问题。顶级 CMakeLists.txt 说 SET( MY_VAR/some/path ) 并且在顶级 source.cpp 中我需要以某种方式实现包含 /的 std::string some/path/to/files 自然使用 MY_VAR 值。

最佳答案

add_executable(myexe main.cpp)
if (MY_VAR)
    target_compile_definitions(myexe PRIVATE MY_VAR=${MY_VAR})
endif()

关于c++ - 将 CMake 变量传递给 C++ 源代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22259279/

相关文章:

c++ - 使用 phoenix 构造时调用析构函数

android - java.lang.UnsatisfiedLinkError : dlopen failed: library not found 错误

c++ - 当自定义库名称与系统库名称相同时,CMake出现循环依赖错误

c++ - 如何在动态库(/MD)项目中使用静态库(/MT)?

c++ - bool vector 的数学 ADD 运算

c++ - 获取 : error C2668: 'sqrt' : ambiguous call to overloaded function

C++ 指针取消引用乘法

c++ - 在 iOS 的 cocos2d-x v3 中使用自定义字体

c++ - CMake 构建后步骤 : copy multiple files dependent on visual studio configuration

c++ - 在 Windows 中配置 CMake 以从命令行使用 clang 以获得现代 OpenMP 支持