CMake Eclipse构建配置 [英] CMake Eclipse Build Configurations

查看:374
本文介绍了CMake Eclipse构建配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用CMake生成一个Eclipse CDT项目,其中生成的Eclipse项目包含已定义的构建类型,这些构建类型是IDE中的可选构建配置。

I want to generate a Eclipse CDT project with CMake where the resulting Eclipse project contains the defined build types as selectable build configurations from within the IDE.

例如:

if(CMAKE_CONFIGURATION_TYPES)
   set(CMAKE_CONFIGURATION_TYPES PRODUCT_A PRODUCT_B)
   set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING
     "Reset the configurations to what we need"
     FORCE)
 endif()

SET(CMAKE_C_FLAGS_PRODUCT_A
    "-DF_ENABLE_FEATURE_A -DF_ENABLE_FEATURE_B
    )

SET(CMAKE_C_FLAGS_PRODUCT_B
    "-DF_ENABLE_FEATURE_A
    )

使用上述方法,Visual Studio项目生成器为我提供了构建配置,以选择product_A product_B并正确突出显示活动代码。

Using the above approach, a Visual Studio project generator gives me build configuriatons to select product_A product_B and highlights the active code correctly.

但是,如果我生成Eclipse项目,则构建配置不存在。

If however I generate a Eclipse project the build configuration isn't there.

如何获得此配置可以为Eclipse项目工作?

How do I get this to work for Eclipse projects?

推荐答案

简短的回答:不需要。

Eclipse CDT生成器围绕生成的Makefile创建包装器。基于Makefile的生成器不能设置为多配置。

The Eclipse CDT generator creates a wrapper around generated Makefiles. Makefile-based generators can't be made to be multi-configuration.

您必须使用单独的二进制树(请注意,两者都可以引用相同的源代码)树),并使用类似选项的选项来启用产品A和/或产品B:

You'll have to use separate binary trees (note that both can refer back to the same source tree), and use something like options to enable product A and/or product B:

OPTION(PRODUCT_A "Build product A." OFF)
OPTION(PRODUCT_B "Build product B." OFF)
IF(PRODUCT_A AND PRODUCT_B)
  MESSAGE(SEND_ERROR "Cannot build both product A and B at the same time.")
ENDIF()

IF(PRODUCT_A)
  SET(CMAKE_C_FLAGS
    "${CMAKE_C_FLAGS} -DF_ENABLE_FEATURE_A -DF_ENABLE_FEATURE_B"
  )
ENDIF()

IF(PRODUCT_B)
  SET(CMAKE_C_FLAGS
    "${CMAKE_C_FLAGS} -DF_ENABLE_FEATURE_A"
  )
ENDIF()

这篇关于CMake Eclipse构建配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆