教程自动工具转换成的CMake [英] Tutorial for converting Autotools to CMake

查看:251
本文介绍了教程自动工具转换成的CMake的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,似乎有很多的自动工具与CMake的主题写的,但对我的生活我似乎无法找到如何将项目从自动工具转换为CMake的一个很好的教程。有谁知道一个?


解决方案

有没有自动化的工具,将任意构建系统转换自动工具CMake的。我已经手动转换一些中等大的项目。我想创建一个的CMakeLists.txt 文件每套 configure.ac 和/或 Makefile.am 文件,以缓解从自动工具C进行转换。

不幸的是,这种手工方法需要在开发两个系统的专业知识,其中没有一个人应该在任何无辜的,予以处罚。


  1. 捕捉什么自动工具构建实际做你的机器上的记录。这将帮助你确认你的CMake构建系统实际上编译每一个文件,使用相同的编译标志,并建立每个库和可执行文件,自动工具做的事情;至少你的机器上,你的选择。


      

    %的./configure [选项设置]> configure_autotools.log


      
      

    %彩妆> make_autotools.log


      
      

    %make install的> make_install_autotools.log



  2. 在包含 configure.ac Makefile.am 文件,包括项目的每个目录根目录下,新建一个空的CMakeLists.txt文件。添加cmake的 add_subdirectory (...)命令各非叶的CMakeLists.txt文件链接所有cmake的以树形结构文件一起。添加cmake的项目()和cmake_minimum_required()命令到您的顶层的CMakeLists.txt文件的顶部。


     项目(MyProject的)
    cmake_minimum_required(版本2.8)
    add_subdirectory(富)



  3. 您现在有一个一致的,但没用的CMake构建系统,什么也不做。暂时在更深的CMakeLists.txt文件添加几个消息(...)命令来验证一切都正确连接。请记住,消息()是你的朋友调试CMake的配置问题时。现在试图构建确保您cmake的基础设施工程。那什么事都建成或安装;但它是有价值此时行使cmake的基础设施。


      

    %的mkdir build_cmake


      
      

    %CD build_cmake


      
      

    %ccmake -i [项目根]


      
      

    [配置,配置,生成]


      
      

    %使VERBOSE = 1


      
      

    %make install的



  4. 这是最困难的部分。一个接一个,填充您的CMakeLists.txt文件。下面是一些准则:


    • 打开两个并排侧编辑器,一个具有的CMakeLists.txt文件,其他与相应的Makefile.am/configure.ac文件。


    • 让你的浏览器中打开到 cmake的命令文档


    • 而不是从最高层开始,通过建立一个小型的图书馆或可执行文件创建CMake的规则,如果你能找到一个在项目中(cmake的 add_library() add_executable())。使用这种方法,你可以建立在一个时间转换一块。


    • 请定期测试您的CMake构建系统为您添加的每个目标。


    • 我喜欢用cmake的文件(GLOB ...)命令来创建紧凑的源文件列表。请注意,这是一个有争议的观点。


    • 许多常见的自动工具节都有相应的 CMake的命令 。例如autoconf的<一个href=\"http://gnu.huihoo.org/autoconf-2.53/html_node/Examining-Syntax.html#Examining%20Syntax\">AC_TRY_COMPILE可以转换为cmake的 TRY_COMPILE 。但大多数情况下,我觉得我必须了解每一个小自动工具节做什么,并找出如何编写相应的cmake的。此外,还有一个一系列CMake的模块的这种帮助创建自动工具样的config.h文件。 Makefile.am文件往往更容易转换和翻译向CMake后其实可以变得更加紧凑。


    • 您比较构建的CMake结果在步骤1中拍摄的是编译标志相同的自动工具日志?都是一样的目标建?安装在同一个文件?


    • 不幸的是我还没有转换自动工具最近CMake的,所以我不写一个COM prehensive如果你看到在Makefile.am X,写的Y的CMakeLists.txt的位置。有人建议可以为公共维基哪里人谁正在积极从自动工具转换为cmake的可以积累COM prehensive设定的这些准则的好位置?我不知道这是否计算器的回答是这样的列表...

    • 最好的地方

  5. 有关额外的学分,一旦你拥有这一切的工作,调整你的cmake的规则,能够构建并运行从Windows的Visual Studio项目。尝试与自动工具!


So there seems to be a lot of writing on the subject of Autotools vs. CMake, but for the life of me I can't seem to find a good tutorial on how to convert a project from Autotools to CMake. Does anybody know of one?

解决方案

There is no automated tool that will convert an arbitrary build system from autotools to cmake. I have converted a few moderately large projects manually. I like to create one CMakeLists.txt file for each set of configure.ac and/or Makefile.am file, to ease the conversion from autotools to cmake.

Sadly, this manual approach requires developing an expertise in two systems, no one of which should be inflicted on any innocent.

  1. Capture a record of what autotools build actually does on your machine. This will help you verify that your CMake build system actually compiles every file, using the same compile flags, and creates every library and executable that autotools does; at least on your machine, with your options.

    % ./configure [configure options] > configure_autotools.log

    % make > make_autotools.log

    % make install > make_install_autotools.log

  2. In every directory that contains a configure.ac or Makefile.am file, including the project root directory, create a new empty CMakeLists.txt file. Add cmake add_subdirectory(...) commands to each non-leaf CMakeLists.txt file to link all the cmake files together in a tree structure. Add cmake project() and cmake_minimum_required() commands to the top of your top level CMakeLists.txt file.

    project(MyProject)
    cmake_minimum_required(VERSION 2.8)
    add_subdirectory(foo)
    

  3. You now have a consistent but useless cmake build system that does nothing. Temporarily add a few message(...) commands in the deeper CMakeLists.txt files to verify that everything is connected correctly. Remember that message() is your friend when debugging cmake configuration problems. Make sure your cmake infrastructure works by trying a build now. Nothing will get built or installed; but it is valuable to exercise the cmake infrastructure at this point.

    % mkdir build_cmake

    % cd build_cmake

    % ccmake -i [your project root]

    [configure, configure, generate]

    % make VERBOSE=1

    % make install

  4. This is the hard part. One by one, populate your CMakeLists.txt files. Here are some guidelines:

    • Open two side-by-side editors, one with the CMakeLists.txt file, the other with the corresponding Makefile.am/configure.ac file.

    • Have your browser open to the cmake commands documentation.

    • Rather than starting from the very top, start off by creating cmake rules for building a small library or executable, if you can find one in the project (cmake add_library() or add_executable()). Using this approach you can build up your conversion one piece at a time.

    • Keep periodically testing your cmake build system as you add each target.

    • I like to use the cmake file(GLOB ...) command to compactly create lists of source files. Be aware that this is a controversial opinion.

    • Many common autotools stanzas have corresponding CMake commands. For example autoconf AC_TRY_COMPILE can be converted to cmake TRY_COMPILE. But mostly I find I have to understand what every little autotools stanza does and figure out how to write the corresponding cmake. Also, there is a series of CMake modules that help create autotools-like config.h files. Makefile.am files are often easier to convert, and can actually become more compact after translation to cmake.

    • Compare your cmake build results to the autotools logs you captured in step 1. Are the compile flags the same? Are all of the same targets built? Are the same files installed?

    • Unfortunately I have not converted autotools to cmake recently, so I am not in a position to write a comprehensive "if you see x in Makefile.am, write y in CMakeLists.txt". Can someone suggest a good location for a public wiki where folks who are actively converting from autotools to cmake can accumulate a comprehensive set of such guidelines? I'm not sure if this stackoverflow answer is the best place for such a list...

  5. For extra credit, once you have it all working, tweak your cmake rules to be able to build and run your project from Windows Visual Studio. Try that with autotools!

这篇关于教程自动工具转换成的CMake的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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