CMake小demo-01
# 设置CMake支持的版本cmake_minimum_required(VERSION 3.5)
# 设置变量
set(CXX_FLAG "-g -pthread -rdynamic -Wall -Werror -Wpointer-arith")
# 设置项目名称
project(project)
# 生成可执行文件
add_executable(project
hello.cpp
)
# 包含头文件
target_include_directories(project
PRIVATE
${PROJECT_SOURCE_DIR}/include)
# 如果是g++,添加额外的编译选项-std=c++17 -Wold-style-cast
if (CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "-std=c++17 -Wold-style-cast ${CXX_FLAG}")
endif (CMAKE_COMPILER_IS_GNUCXX)
# 添加编译选项
add_compile_options(project PRIVATE EX3)
#!/bin/bash
# Auto create the build folder and generate binary.
dir="build"
find . -name ${dir} | grep "build"
if [ $? -eq 0 ]; then
rm -rf ${dir}
fi
mkdir -p build && cd build && cmake .. && make VERBOSE=1
if [ $? -ne 0 ]; then
echo "error"
exit 1
fi
测试
链接: https://pan.baidu.com/s/15mCmZe3Uh2IEwTUdWe8bPw密码: aqp0
页:
[1]