【发布时间】:2021-03-10 19:37:25
【问题描述】:
是否可以为调试和发布模式生成一个 makefile,使用 cMake 进行不同的配置? 例如不同的 CXX 选项或安装可执行文件的不同路径?
这是一个基本的 cMakeList.txt,它为发布和调试模式创建了一个 makefile。
cmake_minimum_required(VERSION 3.10)
# set the project name
project(Tutorial)
# add the executable
add_executable(Tutorial main.cpp)
set(CMAKE_CXX_STANDARD 17)
ADD_CUSTOM_TARGET(debug
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target all
COMMENT "Creating the executable in the debug mode.")
ADD_CUSTOM_TARGET(release
COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Release ${CMAKE_SOURCE_DIR}
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target all
COMMENT "Creating the executable in the release mode.")
如何扩展以支持不同的 Cxx 选项?
【问题讨论】:
-
一些生成器在单个构建目录中支持多个构建配置,但最后我检查了 makefile 不支持。您必须使用两个不同的构建目录并在配置时使用
CMAKE_BUILD_TYPE变量。
标签: cmake