如何添加自定义生成类型cmake的? (针对MAKE)(How to add a custom

2019-06-26 05:25发布

我想添加自定义生成类型为我cmake的建立,在代码覆盖率针对性。

我发现它的FAQ条目: http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_specify_my_own_configurations_.28for_generators_that_allow_it.29_.3F

但是,我不能使它发挥作用。

这里是我的代码,使用cmake 2.8.5:

message("* Adding build types...")
if(CMAKE_CONFIGURATION_TYPES)
   list(APPEND CMAKE_CONFIGURATION_TYPES CodeCoverage)
   list(REMOVE_DUPLICATES CMAKE_CONFIGURATION_TYPES)
   set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING
       "Add the configurations that we need"
       FORCE)
   message("  Available build types are now : ${CMAKE_CONFIGURATION_TYPES}")
else()
   message("  XXX custom build types are not allowed...")
endif()

而我得到“XXX自定义生成类型不准......” ......

Answer 1:

发现了问题:有之间添加自定义构建和定制配置混乱:

  • 配置是对于像Visual Studio或XCode的特殊工具
  • 构建类型是一个更rawer功能

因此,添加自定义生成类型,就没有必要操纵CMAKE_CONFIGURATION_TYPES可变的。 只要设置相应的变量,并开始使用它, 解释说 :

SET(GCC_DEBUG_FLAGS "-g -Wall")

# Add new build types
message("* Adding build types...")
SET(CMAKE_CXX_FLAGS_COVERAGE
    "${GCC_DEBUG_FLAGS} -fprofile-arcs -ftest-coverage"
    CACHE STRING "Flags used by the C++ compiler during coverage builds."
    FORCE )
SET(CMAKE_C_FLAGS_COVERAGE
    "${GCC_DEBUG_FLAGS} -fprofile-arcs -ftest-coverage"
    CACHE STRING "Flags used by the C compiler during coverage builds."
    FORCE )
SET(CMAKE_EXE_LINKER_FLAGS_COVERAGE
    ""
    CACHE STRING "Flags used for linking binaries during coverage builds."
    FORCE )
SET(CMAKE_SHARED_LINKER_FLAGS_COVERAGE
    ""
    CACHE STRING "Flags used by the shared libraries linker during coverage builds."
    FORCE )
MARK_AS_ADVANCED(
    CMAKE_CXX_FLAGS_COVERAGE
    CMAKE_C_FLAGS_COVERAGE
    CMAKE_EXE_LINKER_FLAGS_COVERAGE
    CMAKE_SHARED_LINKER_FLAGS_COVERAGE )

我们可能还需要uDate公司的帮助字符串(沿设置默认生成类型的方式):

IF(NOT CMAKE_BUILD_TYPE)
   SET(CMAKE_BUILD_TYPE Debug
       CACHE STRING "Choose the type of build : None Debug Release RelWithDebInfo MinSizeRel Coverage."
       FORCE)
ENDIF(NOT CMAKE_BUILD_TYPE)
message("* Current build type is : ${CMAKE_BUILD_TYPE}")

警告有关试图继承另一个构建类型做这个默认选项的位:

SET(CMAKE_CXX_FLAGS_COVERAGE
    "${CMAKE_CXX_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage"
    CACHE STRING "Flags used by the C++ compiler during coverage builds."
    FORCE )

这是一个糟糕的主意,因为额外的选项保持每一个的配置再次来源(每次改变东西在里面)的时间被追加。



文章来源: How to add a custom build type to cmake ? (targeting make)
标签: cmake