【问题标题】:How to implement the Cmake -C option with the conan Cmake helper如何使用柯南 Cmake 助手实现 Cmake -C 选项
【发布时间】:2021-05-25 07:56:49
【问题描述】:

现在我像这样使用 cmake:

cmake .. -C pathToMyFile

我想使用柯南 Cmake 助手配置 cmake,以便在我的 conanfile.py 中拥有

cmake=CMake(self)
cmake.configure()

我怎样才能告诉 Cmake 预加载我的脚本来填充缓存。我试过了

cmake.configure(args="-C mypath")

但这没有用。谢谢!

【问题讨论】:

    标签: c++ cmake conan


    【解决方案1】:

    你为什么需要它? CMake 助手使用自己的缓存,你不需要额外配置任何东西。除此之外,您可以重复使用相同的 CMake 对象,以避免调用两次。

    正确的流程是:

    def _configure_cmake(self):
       if self._cmake:
           return self._cmake
       self._cmake = CMake(self)
       self._cmake.definitions["BUILD_TESTING"] = False
       self._cmake.configure() # it runs cmake <build_folder> -DBUILD_TESTING=False ...
       return self._cmake
    
    def build(self):
       cmake = self._configure_cmake()
       cmake.build() # it runs cmake --build .
    
    def package(self):
       cmake = self._configure_cmake()
       cmake.install()  # it runs cmake --build . --target install
     
    

    另外,CMake args 不是字符串,而是列表,很好documented,因此,你必须通过:

    cmake.configure(args=["-C", "mypath"])
    

    【讨论】:

      猜你喜欢
      • 2021-12-15
      • 2023-03-11
      • 1970-01-01
      • 1970-01-01
      • 2021-11-14
      • 1970-01-01
      • 1970-01-01
      • 2021-01-15
      • 1970-01-01
      相关资源
      最近更新 更多