Files
leetcode/array/1binary search/35search-insert-position/c++/CMakeLists.txt
flowerstonezl e1006fa09c first init
2026-01-29 17:04:05 +08:00

49 lines
1.5 KiB
CMake
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 1. 指定CMake最低版本要求
cmake_minimum_required(VERSION 3.10)
# 2. 设置项目信息
project(
LeetCodeSolution # 项目名称(可根据题目修改)
VERSION 1.0.0 # 项目版本
DESCRIPTION "LeetCode Solution Template"
LANGUAGES CXX # 支持的语言
)
# 3. 设置C++标准和编译特性
set(CMAKE_CXX_STANDARD 17) # 使用C++17标准
set(CMAKE_CXX_STANDARD_REQUIRED ON) # 必须支持指定标准
set(CMAKE_CXX_EXTENSIONS OFF) # 禁用编译器特有扩展
# 4. 配置构建类型和编译选项
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug) # 默认构建类型为Debug便于调试
endif()
# 公共编译选项
add_compile_options(
"$<$<CONFIG:Release>:-O2>" # Release模式优化
"$<$<CONFIG:Debug>:-g>" # Debug模式包含调试信息
"$<$<CONFIG:Debug>:-O0>" # Debug模式不优化
)
# 平台特定选项
if(MSVC)
add_compile_options(/W3) # MSVC: 警告等级3刷题时不需要太严格
else()
add_compile_options(-Wall -Wextra) # GCC/Clang: 常用警告
endif()
# 5. 源文件收集
file(GLOB_RECURSE SOURCES "src/*.cpp") # 递归收集源文件
# 6. 创建可执行文件目标
add_executable(${PROJECT_NAME} ${SOURCES})
# 7. 自定义目标:运行程序
add_custom_target(run
COMMAND ${PROJECT_NAME}
DEPENDS ${PROJECT_NAME}
COMMENT "运行 ${PROJECT_NAME}..."
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)