如何为 CLion 中的每个配置定义预处理器定义?

a72*_*969 2 c++ build-definition clion

我在CLion -> Settings -> Build, Execution, Deployment -> CMake. 无论我使用哪种编译器,如何为每个配置文件设置预处理器定义?

a72*_*969 7

  1. Settings -> Build, Execution, Deployment -> CMake
  2. 选择要为其设置预处理器定义的配置文件。
  3. 写入CMake options文本框:-DYOUR_DEFINE_VARIABLE=1
  4. 在您的 CMakeLists.txt 中写入以下内容:
if (YOUR_DEFINE_VARIABLE)
    add_definitions(-DYOUR_DEFINE_VARIABLE=1)
endif (YOUR_DEFINE_VARIABLE)
Run Code Online (Sandbox Code Playgroud)