首页 > 其他分享 >cmake CMAKE_BUILD_TYPE

cmake CMAKE_BUILD_TYPE

时间:2023-04-03 15:44:06浏览次数:38  
标签:cmake builds -- BUILD Debug CMAKE config build

https://stackoverflow.com/questions/24460486/cmake-build-type-is-not-being-used-in-cmakelists-txt

There are two types of generators: single-configurations and multi-configurations.

1. Single configurations

Make-like generators: Unix Makefiles, NMake Makefiles, MinGW Makefiles, ...

You set the configuration type in the generate step:

cmake -H. -B_builds/Debug -DCMAKE_BUILD_TYPE=Debug "-GUnix Makefiles"

In this case, the build step is always Debug:

> cmake --build _builds/Debug
/usr/bin/c++ -g ...
> cmake --build _builds/Debug --config Debug # `--config` ignored
/usr/bin/c++ -g ...
> cmake --build _builds/Debug --config Release # yep, ignored
/usr/bin/c++ -g ...

2. Multi-configuration

IDE generators: Visual Studio, Xcode

CMAKE_BUILD_TYPE on generate step is ignored,

CMake Warning:
  Manually-specified variables were not used by the project:

    CMAKE_BUILD_TYPE

both:

> cmake -H. -B_builds -DCMAKE_BUILD_TYPE=Debug "-GVisual Studio 12 2013 Win64"

and

> cmake -H. -B_builds -DCMAKE_BUILD_TYPE=Release "-GVisual Studio 12 2013 Win64"

will have the same effect:

This is because all the configurations is internal (i.e., _builds/msvc-opaque/Release and _builds/msvc-opaque/Debug or something, doesn't matter).

You can use --config options to switch:

> cmake --build _builds --config Release
cl /O2 ...
> cmake --build _builds --config Debug
cl /Od ...

3. Control

Yes, you can. Just define CMAKE_CONFIGURATION_TYPES:

# Somewhere in CMakeLists.txt
message("Generated with config types: ${CMAKE_CONFIGURATION_TYPES}")

Default output:

-- Detecting CXX compiler ABI info - done
Generated with config types: Debug;Release;MinSizeRel;RelWithDebInfo
-- Configuring done

Rewrite it:

> cmake -H. -B_builds -DCMAKE_CONFIGURATION_TYPES="Debug;Release" "-GVisual Studio 12 2013 Win64"
-- Detecting CXX compiler ABI info - done
Generated with config types: Debug;Release
-- Configuring done

You can even define your own configuration type:

> cmake -H. -B_builds -DCMAKE_CONFIGURATION_TYPES="Debug;MyRelease" -DCMAKE_CXX_FLAGS_MYRELEASE="/My-Rel-flag" -DCMAKE_EXE_LINKER_FLAGS_MYRELEASE="/My-Linker-flags" "-GVisual Studio 12 2013 Win64"

And build:

    cmake --build _builds --config MyRelease

4. Messy (?)

Not at all if you know the trick

标签:cmake,builds,--,BUILD,Debug,CMAKE,config,build
From: https://www.cnblogs.com/Searchor/p/17283249.html

相关文章

  • cmake xcode
    1.generateprojectcmake..-GXcodeerror:error:NoCMAKE_C_COMPILERcouldbefound.solu:IfyouhaveinstalledXcodeorCommandLineToolsforXcode,trythis:sudoxcode-select--reset......
  • Cmake
    1.GenerateaProjectBuildsystemcmake[<options>]<path-to-source>cmake[<options>]<path-to-existing-build>cmake[<options>]-S<path-to-source>-B<path-to-build>2.BuidaProjectcmake--build<dir&g......
  • 巧用rpmbuild的expand宏实现模板功能
    需求:构建生成的二进制包的个数不确定,由某些条件决定。比如,我们想为系统中的所有内核版本构建某个外来模块,如果系统中有2个内核版本,就生成两个2个二进制包,分别对应相应的版本,如果系统中有3个内核版本,就生成3个二进制包。我们的需求是实现动态个数的%package。很多人在讨论spec是......
  • 初见 cmake
    初见cmakecmake是自动生成构建系统的一个工具。cmake本身不是构建系统,它是一个生成构建系统的工具。或者说cmake不是一个构建工具,是一个能根据平台生成对应平台构建系统配置的构建工具。Cmake构建系统Unix平台的最常见的C/C++构建工具make,根据Makefile编译项目。而......
  • docker build 构建时 alpinelinux 镜像权限错误
    问题使用dockerbuild构建镜像时,发生一个错误:“ERROR:https://dl-cdn.alpinelinux.org/alpine/v3.15/main:Permissiondenied”。部分日志如下:[2023-03-3014:51:12]Step3/16:RUNapkupdate&&apkupgrade&&apkaddmusl-devmakegccpython3[2023-03-3014:51:12......
  • webpack基本使用(七)build命令打包
        运行npmrunbuild后出现了dist的目录 此目录里面存放的就是要发布的代码。我们把dist打包,发给运维就可以进行发布了。 ......
  • uni-app:button中添加图片/图标时与文字对齐(hbuilderx 3.7.3)
    一,js代码:1,html:<!--语音音阶动画end--><buttonclass="btn"@click="goRecord"><uni-icons:type="micType"size="30"></uni-icons>......
  • nginx配置vue打包npm build的静态页面
    nginx配置vue项目server{listen8081;server_name10.8.8.8;indexindex.html;root/home/www/crm/vue/dist;#SSL-STARTSSL相关配置,请勿删......
  • 理解String、StringBuilder和StringBuffer
    1.String、StringBuilder和StringBuffer异同相同点:底层都是通过char数组实现的不同点:String对象一旦创建,其值是不能修改的,如果要修改,会重新开辟内存空间来存储修改之......
  • PowerBuilder现代编程方法X01:PowerPlume的X模式
     临渊羡鱼,不如退而结网。 PB现代编程方法X01:PowerPlume的X模式 前言PowerPlume是PowerBuilder深度创新的扩展开发框架(免费商用)。它不是一个大而全的类库(取决于你......