简体   繁体   English

如何让我的项目易于设置?

[英]How to make my project easy to set up?

For now, the repository of my application contains the Visual Studio 11 project files, my source and header files, library headers and their compiled *.lib files and some assets. 目前,我的应用程序的存储库包含Visual Studio 11项目文件,源文件和头文件,库头文件及其编译的* .lib文件和一些资源。

But it is a big effort to set up the project on every new platform to test compatibility or continue development. 但是,在每个新平台上设置项目以测试兼容性或继续开发是一项巨大的工作。 Each time I have to create a new project for the current IDE, and more important, download all the used third party libraries and compile the *.lib files for the current compiler. 每次我必须为当前IDE创建一个新项目,更重要的是,下载所有使用过的第三方库并编译当前编译器的* .lib文件。

Is there a way to automatedly fetch required libraries and compile them to *.lib files on all platforms? 有没有办法自动获取所需的库并将它们编译为所有平台上的* .lib文件? Moreover, it would be pleasant to cover project settings so that it is easier to set up projects for new compilers or IDEs. 此外,覆盖项目设置会很愉快,因此更容易为新的编译器或IDE设置项目。

I believe, CMake ( http://www.cmake.org/ ) is the best C++ has now. 我相信,CMake( http://www.cmake.org/ )是目前最好的C ++。 Like C++ itself, CMake is neither pretty nor simple to use, but, again, like C++, it's very powerful and versatile. 就像C ++本身一样,CMake既不漂亮又不易使用,但同样,就像C ++一样,它非常强大且功能多样。

It's currently used by a great number of projects, which need custom and/or complex configuration and building. 它目前被大量项目使用,需要定制和/或复杂的配置和构建。

Here's some of it's features, you may find useful: 以下是它的一些功能,您可能会觉得有用:

  1. It's not a build tool. 它不是构建工具。 It generates the files which will be used by the native build tools - Visual Studio solution files, GNU make files and what not. 它生成将由本机构建工具使用的文件 - Visual Studio解决方案文件,GNU make文件以及不存在的文件。 It supports a lot of compilers out-of-the box - namely, cl, gcc, clang. 它支持很多开箱即用的编译器 - 即cl,gcc,clang。 So, this addresses the 'IDE' part of your question. 因此,这解决了问题的“IDE”部分。
  2. It has a useful find_package macro that helps finding installed libraries to make use of it in the project. 它有一个有用的find_package宏,可帮助查找已安装的库以在项目中使用它。 Eg if you have the boost libraries installed, you can use something like the following code, which I believe is rather self-descriptive 例如,如果你安装了boost库,你可以使用类似下面的代码,我相信这是相当自我描述的
     find_package( Boost COMPONENTS thread system) if(Boost_FOUND) include_directories(${Boost_INCLUDE_DIRS}) link_directories(${Boost_LIBRARY_DIRS}) endif(Boost_FOUND) 
  3. It has an ExternalProject extension, which can help automate downloading, building and installing libraries. 它有一个ExternalProject扩展,可以帮助自动下载,构建和安装库。 Eg for zlib, add the following to your CMakeLists.txt: 例如,对于zlib,将以下内容添加到CMakeLists.txt:
     include(ExternalProject) ExternalProject_Add( ZLIB URL http://zlib.net/zlib-1.2.8.tar.gz ) 
    It will fetch the tarball from the given url, build zlib, and install it. 它将从给定的URL获取tarball,构建zlib并安装它。 After that you can use find_package again. 之后,您可以再次使用find_package。
  4. In the end of the day, CMake is highly customizable. 在一天结束时,CMake是高度可定制的。 You can customize the ExternalProject_Add function to change downloading, building and installing rules. 您可以自定义ExternalProject_Add函数以更改下载,构建和安装规则。 If it doesn't help either, you can always fallback to calling curl or git clone to fetch the sources, and call building and installing commands manually. 如果它也没有帮助,您可以始终回退到调用curlgit clone来获取源,并手动调用构建和安装命令。

Once again, it's not an out-of-the-box or just-works solution, but it gets the job done, which is acknowledged by a quite large user base. 再一次,它不是一个开箱即用或只是工作的解决方案,但它完成了工作,这得到了相当大的用户群的认可。 To paraphrase the known quote, 'CMake is the worst build tool, but others are even worse' 用已知的引用来解释,'CMake是最糟糕的构建工具,但其他工具更糟糕'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM