我正在评估使用 cmake 为嵌入式固件生成 makefile。 cmakelists.txt
将在团队中共享。
- 您能否确认 makefile 不能在不同计算机之间共享?
- 如果两台计算机上的项目路径相同,情况仍然如此吗?
- 使用 cmake makefile 生成和相同版本的编译器,生成的二进制文件在所有计算机上是否相同?
- 这与项目中共享的 makefile 的行为相同吗?
最佳答案
为什么你要共享生成的 makefile!?您通常会共享 cmake 文件。
- Can you confirm the makefile cannot be shared between different computers ?
您不应该共享makefile。它仅为您生成,包含本地信息以及 cmake(缓存)选项和状态。没有真正的理由这样做!
- Is this still true if project path is identical on both computers ?
是的,因为cmake维护着设置、选项等的缓存。因此,makefile 可能会根据路径、选项和状态而有所不同。您还必须保证任何依赖项的路径。
- Using cmake makefile generation and same version of compiler, will the generated binary be the same on all computers ?
如果环境(编译器、库等)和选项(构建类型、项目选项等)相同,Cmake 将可靠地生成完全相同的二进制文件系统。
- Is this the same behavior as a makefile shared in the project ?
不,CMake 更好:它是跨平台的。它不依赖于 make,您也可以使用任何其他系统(如 ninja 或 IDE 项目)——无需触及源代码或 cmake 代码。
CMake 的作用不仅仅是创建 makefile。您甚至可以使用多个不同的编译器/交叉编译器编译基于 CMake 的项目,而无需进行任何更改。
TL;DR
不要共享生成的 Makfile,而是共享 Cmake 源文件 - 这就是 CMake 的用途。
关于cmake 和 make 构建重现性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43109940/