如何使用CMake从一个主CMake项目构建多个平台而没有缓存问题 [英] How to use CMake to build multiple platforms from one master CMake project without cache problems

查看:56
本文介绍了如何使用CMake从一个主CMake项目构建多个平台而没有缓存问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个名为 A B 的项目,它们具有完整的CMakeLists.txt项目,并且每个项目都可以完全构建而没有错误.我想在CMake中定义一个 master 项目,该项目将同时构建 A B (最终可能还会生成一百种其他东西)./p>

我的顶级 CMakeLists.txt 项目看起来像

  add_subdirectory(A版)add_subdirectory(B build-B) 

CMake可以解析所有文件,并使make可以开始构建.

问题在于项目 A 适用于一种体系结构( x86_64 ),而 B 适用于另一种体系结构( k1om ),以及当CMake调用

之类的各种功能时

  find_package(增强功能....) 

它为第一个体系结构缓存库路径的结果,并将它们(错误地!)重用于所有后续体系结构.我们已经为 x86_64 k1om 编译了Boost.

是否有一种方法可以通过使两个项目之间的缓存完全无效来使CMake进行我想做的事情?这样的事情就可以了:

  add_subdirectory(A版)cmake_invalidate_cache_and_forget_everthing_that_just_happened()add_subdirectory(B build-B)cmake_invalidate_cache_and_forget_everthing_that_just_happened()... 

我完全知道,我可以制作一个可以执行此操作的shell脚本,并且可以在不同的输出目录中多次运行 cmake ,但是具有统一的入口"点真的很好对于所有用CMake编写的项目.

解决方案

我建议使用超级构建"设置,通过 ExternalProject_Add 而不是<代码>添加子目录.这样可以在子项目的构建之间实现非常清晰的分离.我认为您可能会尝试通过修改生成的CMakeCache.txt来与CMake战斗!

但是,我从未尝试过在子项目之间的体系结构有所不同的情况下实际进行此操作.因此,我所能做的就是建议您尝试一下-我认为它应该可以工作.

((本文可能会有所帮助).

I have two projects called A and B that have complete working CMakeLists.txt projects, and each project can be built completely without errors. I would like to have a master project defined in CMake that will build both A and B (and maybe a hundred other things eventually).

My top level CMakeLists.txt project looks like

add_subdirectory(A build-A)
add_subdirectory(B build-B)

and CMake can parse all the files and make can start building just fine.

The problem is that project A is for one architecture (x86_64) and B is for a different architecture (k1om) and when CMake invokes various features like

 find_package(Boost ....)

it caches the results of the library paths for the first architecture and reuses them (incorrectly!) for all subsequent architectures. We have Boost compiled for both x86_64 and k1om.

Is there a way to have CMake do what I want to do, by entirely invalidating the cache between the two projects? Something like this would be ok:

add_subdirectory(A build-A)
cmake_invalidate_cache_and_forget_everthing_that_just_happened()
add_subdirectory(B build-B)
cmake_invalidate_cache_and_forget_everthing_that_just_happened()
...

I am fully aware that I can just make a shell script that does this and just runs cmake multiple times in different output directories, but it would be really nice to have a uniform "entry" point for all projects written in CMake.

解决方案

I'd recommend using a "super-build" setup whereby each subproject is included via ExternalProject_Add rather than add_subdirectory. This gives very clean separation between the subprojects' builds. I think you'd be fighting CMake very hard by trying to tinker with the generated CMakeCache.txt!

However, I've never tried actually doing this where the architecture differs between subprojects. So all I can do is suggest you try it - I think it should work.

(This article may help).

这篇关于如何使用CMake从一个主CMake项目构建多个平台而没有缓存问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆