c++visual-studioautomationdependencies

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.

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.

Is there a way to automatedly fetch required libraries and compile them to *.lib files on all platforms? Moreover, it would be pleasant to cover project settings so that it is easier to set up projects for new compilers or IDEs.


Solution

  • I believe, CMake (http://www.cmake.org/) is the best C++ has now. Like C++ itself, CMake is neither pretty nor simple to use, but, again, like C++, it's very powerful and versatile.

    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. It supports a lot of compilers out-of-the box - namely, cl, gcc, clang. So, this addresses the 'IDE' part of your question.
    2. It has a useful find_package macro that helps finding installed libraries to make use of it in the project. E.g. if you have the boost libraries installed, you can use something like the following code, which I believe is rather self-descriptive
      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. E.g. for zlib, add the following to your 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. After that you can use find_package again.
    4. In the end of the day, CMake is highly customizable. You can customize the ExternalProject_Add function to change downloading, building and installing rules. 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.

    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'