cmake_minimum_required(VERSION 3.9)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Try to enable interprocedual optimization
include(CheckIPOSupported)
check_ipo_supported(RESULT ipo_supported)
if(ipo_supported)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION True)
endif()
project(XXXPrj)
# Forbid in-source build
if(PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
message(FATAL_ERROR "In-source builds are not allowed")
endif()
add_executable(XXX main.cpp)
自用的CMakeList模板
该配置文件设置了CMake的最小版本为3.9,强制使用C++11标准,并禁用C++扩展。它检查并启用InterproceduralOptimization(IPO)如果支持,并定义了一个名为XXXPrj的项目。同时,禁止了源代码目录下的in-source构建。
摘要由CSDN通过智能技术生成