我想用"cmake_minimum_required"工具为CMake定义最小版本.我已经看到一些项目设置了最低版本2.8,其他一些设置为3.0或3.2.我想了解您对该主题的意见和最佳实践.
在CMakeLists.txt脚本中,习惯上有一个:
cmake_minimum_required(VERSION x.y)
Run Code Online (Sandbox Code Playgroud)
为适当的xy版本号.但是 - 你怎么知道最低版本是什么?我不使用旧版本; 随着我的发行版更新,CMake也是如此,所以我甚至可能已经引入了需要更新版本的命令,而我只是不知道它.
理论上我可以要求我测试过这个版本CMakeLists.txt- 但它们很新(3.5.1,3.5.2),而且我不想限制我的代码用户.
CentOS6.9/cmake 3.6.1
在我的项目中,我正在尝试创建几个组件,而不是为它们构建运行时,开发和调试包,但是我无法为每个组件生成超过一个rpm.我创建了一个小项目来显示问题:
./include/Box.hpp
namespace room {
class Box {
public:
Box(int volume);
int get_volume() const;
private:
int m_volume;
};
}
Run Code Online (Sandbox Code Playgroud)
./source/Box.cpp
#include "Box.hpp"
namespace room {
Box::Box(int volume)
: m_volume(volume)
{
}
int Box::get_volume() const
{
return this->m_volume;
}
}
Run Code Online (Sandbox Code Playgroud)
./source/app.cpp
#include "Box.hpp"
int main() {
room::Box box(5);
return box.get_volume();
}
Run Code Online (Sandbox Code Playgroud)
./CMakeLists.txt
cmake_minimum_required(VERSION 3.6)
project (home)
set(CMAKE_INSTALL_PREFIX "/usr/local")
set(CMAKE_BUILD_TYPE "RelWithDebInfo")
include_directories("include")
file(GLOB SRC_FILES "source/*.cpp")
file(GLOB HDR_FILES "include/*.hpp")
add_executable(${PROJECT_NAME} ${SRC_FILES})
install(FILES ${HDR_FILES} DESTINATION "include" COMPONENT devel)
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION …Run Code Online (Sandbox Code Playgroud)