gpt4 book ai didi

cmake - 如何将自定义构建类型添加到cmake? (定位品牌)

转载 作者:行者123 更新时间:2023-12-03 13:29:38 24 4
gpt4 key购买 nike

我正在尝试为我的cmake构建添加自定义构建类型,目标是代码覆盖率。

我已经找到有关它的FAQ条目:https://gitlab.kitware.com/cmake/community/wikis/FAQ#how-can-i-specify-my-own-configurations-for-generators-that-allow-it-

但是,我无法使其工作。

这是我的代码,使用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自定义构建类型...” ...

最佳答案

发现了问题:添加自定义构建和自定义配置之间存在混淆:

  • 配置用于特殊工具,例如Visual Studio或XCode
  • 构建类型是更加原始的功能

  • 因此,要添加自定义构建类型,根本不需要操纵CMAKE_CONFIGURATION_TYPES变量。只需设置相应的变量并开始使用它,就像 explained一样:
    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 )

    我们可能还想审核帮助字符串(顺便说一句,以及 setting the default build type):
    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 )

    这是 不好的想法,因为每次重新获得配置时(每次您对其进行更改时),都会继续附加附加选项。

    关于cmake - 如何将自定义构建类型添加到cmake? (定位品牌),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11437692/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com