CentOS 系统下编译安装最新版本cmake
1. 安装依赖
$ sudo yum install openssl-devel
2. 编译安装
$ wget https://github.com/Kitware/CMake/releases/download/v3.20.0/cmake-3.20.0.tar.gz
$ tar -xvf cmake-3.20.0.tar.gz
$ cd cmake-3.20.0
$ ./bootstrap --prefix=/usr/local/cmake3-20
$ gmake
$ sudo gmake install
$ sudo yum remove cmake
$ cmake --version
cmake version 3.20.0
CMake suite maintained and supported by Kitware (kitware.com/cmake).
3. 常用语法
3.1 源文件路径
# aux_source_directory(< dir > < variable >)
aux_source_directory(. DIR_SRCS)
FILE (GLOB ALL_SOURCES "*.cpp" "*.c" "./AFolder/*.cpp" )
FILE (GLOB ALL_INCLUDES "*.hpp" "*.h" "./AFolder/*.hpp" "./AFolder/*.h" )
SET (ALL_SRCS
${ALL_SOURCES}
${ALL_INCLUDES}
)
3.2 执行外部命令
execute_process(COMMAND sh ${PROJECT_SOURCE_DIR}/version.sh)
add_custom_target(CopyTask)
add_custom_command(TARGET CopyTask
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/config ${CMAKE_CURRENT_SOURCE_DIR}/etc
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/log.txt ${CMAKE_CURRENT_SOURCE_DIR}/etc
)
3.3 判断编译器类型
if (CMAKE_CXX_COMPILER MATCHES ".*clang")
set(CMAKE_COMPILER_IS_CLANGXX 1)
endif()