
本文共 3676 字,大约阅读时间需要 12 分钟。
cmake3安装
echo '[group_kdesig-cmake3_EPEL]name=Copr repo for cmake3_EPEL owned by @kdesigbaseurl=https://copr-be.cloud.fedoraproject.org/results/@kdesig/cmake3_EPEL/epel-7-$basearch/type=rpm-mdskip_if_unavailable=Truegpgcheck=1gpgkey=https://copr-be.cloud.fedoraproject.org/results/@kdesig/cmake3_EPEL/pubkey.gpgrepo_gpgcheck=0enabled=1enabled_metadata=1' >> /etc/yum.repos.d/cmake3.repo yum install jsoncpp -yyum install -y cmake3 cmake3 -v
手动安装cmake-3.17.1-Linux-x86_64.tar.gz
解压到/usr/local/cmake-3.17.1-Linux-x86_64
ln -s /usr/local/cmake-3.17.1-Linux-x86_64/bin/cmake /usr/local/bin/cmake]# cmake --version
cmake version 3.17.1CMake suite maintained and supported by Kitware (kitware.com/cmake).
[root@localhost cmake-3.17.1-Linux-x86_64]#CMake学习(六) —— if 和 else
CentOS 7 源码安装 CMake 3.15.5 最新稳定版。解决
wget https://github.com/Kitware/CMake/releases/download/v3.15.5/cmake-3.15.5.tar.gztar -zxf cmake-3.15.5.tar.gzcd cmake-3.15.5./bootstrap --prefix=/usr --datadir=share/cmake --docdir=doc/cmake && makesudo make installcmake --version
现在使用cmake的项目越来越多,学习了解下。
其实,cmake和autotools正是makefile的上层工具,它们的目的正是为了产生可移植的makefile,并简化自己动手写makefile时的巨大工作量。
#CMAKE_SOURCE_DIR是cmake内置变量表示当前项目根目录
接着在同级目录下创建cmake文件 CMakeLists.txt
为了代码干净,同级目录下创建build目录,进入build目录,执行“cmake ./”命令来生成Makefile文件,接着执行命令make编译,最后build目录下生成二进制文件example_01, 执行程序可以输出打印信息。
mkdir buildcd buildcmake ../make-B build -B指定Build Tree路径,不存在则创建cmake . -Bbuild
vi ./CMakeFiles/viid_server.dir/build.make
找到
/opt/rh/devtoolset-7/root/usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -o CMakeFiles/viid_server.dir/mnt/hgfs/liantong/code/nvr-server/03-server/xxxxx/source/xxxxx.cpp.o -c /mnt/hgfs/liantong/code/nvr-server/03-server/xxxxx/source/xxxx.cpp
./CMakeFiles/viid_server.dir/flags.make:CXX_INCLUDES = -./CMakeFiles/viid_server.dir/DependInfo.cmake: "../../../../common_tool/plan/plan"
排错
CmakeLists编写
C++ 项目 使用 CMAKE 和 GOOGLE TEST(傻瓜式教程)
./CMakeFiles/xxxxx.dir/link.txt:目录里查找 使用到的lxxx库
vim ./CMakeFiles/xxxxx.dir/depend.make 查找依赖的头文件
t.dir/depend.make:CMakeFiles/secret.dir/mnt/hgfs/liantong/code/nvr-server/03-server/common_tool/secret/source/secret.cpp.o: ../../include/secret.h
./CMakeFiles/secret.dir/DependInfo.cmake:# The include file search paths: ./CMakeFiles/secret.dir/DependInfo.cmake: "../../include" ./CMakeFiles/secret.dir/DependInfo.cmake: "../../../../../01-common/include/system" ./CMakeFiles/secret.dir/DependInfo.cmake: "../../../../../01-common/include/cbb" ./CMakeFiles/secret.dir/DependInfo.cmake: "../../../base/include" ./CMakeFiles/secret.dir/flags.make:CXX_INCLUDES = -I/mnt/hgfs/liantong/code/nvr-server/03-server/common_tool/secret/prj_linux/../include -I/mnt/hgfs/liantong/code/nvr-server/03-server/common_tool/secret/prj_linux/../../../../01-common/include/system -I/mnt/hgfs/liantong/code/nvr-server/03-server/common_tool/secret/prj_linux/../../../../01-common/include/cbb -I/mnt/hgfs/liantong/code/nvr-server/03-server/common_tool/secret/prj_linux/../../base/include [root@localhost build]# vim ./CMakeFiles/secret.dir/build.make [root@localhost build]#
查找宏定义
g]# grep USE_CUT_FRAME ./ -rs
./CMakeCache.txt:USE_CUT_FRAME:UNINITIALIZED=true ./CMakeFiles/gbplat.dir/DependInfo.cmake: "USE_CUT_FRAME" ./CMakeFiles/gbplat.dir/flags.make:CXX_DEFINES = -DCROW_CHANGE -DUSE_CUT_FRAME -D_DEBUG -D_LINUX_ [root@localhost build-debug]#
指定输出路径
set(EXECUTABLE_OUTPUT_PATH ${CURDIR}) #set(EXECUTABLE_OUTPUT_PATH ${CURDIR}/../../) cmake添加相对路径 GET_FILENAME_COMPONENT(PARENT_DIR ${PROJECT_SOURCE_DIR} DIRECTORY)cmake之 ADD_LIBRARY()
SET(LIBHELLO_SRC hello.c)ADD_LIBRARY(hello SHARED ${LIBHELLO_SRC})ADD_LIBRARY(hello_static STATIC ${LIBHELLO_SRC})
多目录工程的CmakeLists.txt编写(自动添加多目录下的文件)
发表评论
最新留言
关于作者
