CMakeLists.txt的模板
cmake_minimum_required(VERSION xxx) # minimum version required
project(xxx) # project name
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release) # {Debug, Release, RelWithDebInfo, MinSizeRel}
endif()
if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
# Debug 配置
elseif (${CMAKE_BUILD_TYPE} STREQUAL "Release")
# Release 配置
else ()
# 其他配置
endif ()
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
message(STATUS "C flags, Debug configuration: ${CMAKE_C_FLAGS_DEBUG}")
message(STATUS "C flags, Release configuration: ${CMAKE_C_FLAGS_RELEASE}")
message(STATUS "C flags, Release configuration with Debug info: ${CMAKE_C_FLAGS_RELWITHDEBINFO}")
message(STATUS "C flags, minimal Release configuration: ${CMAKE_C_FLAGS_MINSIZEREL}")
message(STATUS "C++ flags, Debug configuration: ${CMAKE_CXX_FLAGS_DEBUG}")
message(STATUS "C++ flags, Release configuration: ${CMAKE_CXX_FLAGS_RELEASE}")
message(STATUS "C++ flags, Release configuration with Debug info: ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
message(STATUS "C++ flags, minimal Release configuration: ${CMAKE_CXX_FLAGS_MINSIZEREL}")
add_executable(xxx yyy.cpp) # -o xxx yyy.cpp
include_directories(xxx) # -I xxx
link_directories(xxx) # -L xxx
target_link_libraries(xxx yyy) # -l yyy