![]() The CMakeLists.txt comes in at a 16 lines of code which is pretty short for automatically downloading the project dependencies and making them available to the rest of the CMake project. In this example I choose to download Catch2 unit testing framework and the JSON for Modern C++ framework in a minimal example. Once this is done then the target_link_libraries can be used to “link” the header only library to whatever CMake targets that are available. The target_include_directories() command is used to specify the include path for the library that has just been downloaded. The interface part is required because the library is a header only library and does not contain any source files. The tutorial was pretty clear on how to make this happen and have CMake files created via install that another Cmake project could import via findpackage(). A interface library can be added which allows the library to be recognized by CMake. Since abseil-cpp is a third-party dependency that builds with Cmake, I add it as a subdirectory in my top level CMakeLists.txt. I’ve chosen the $ since the header is a dependency and not actually considered part of the source of this project. The file(DOWNLOAD) CMake command can be used to download files from a URL to a directory. ![]() So basically we are going to use CMake to automatically download the single header file to satisfy the JSON for Modern C++ dependency instead of having to clone the entire repository. Our build server puts our builds in an opt folder, either /opt or c:/opt and I link thru various import and module or config normal methods. Fortunately JSON for C++ provides a link to the header only version of the library on their GitHub releases page.ĬMake has a feature to download files from the Internet as part of the generation process. I am trying to use the RUNTIMEDEPENDENCY system to install the shared libraries and dlls that have been linked to in my project. The newer version of CMake (3. JSON for Modern C++ is known to be a heavyweight for a JSON library, but it seemed like just too much for a library that hasto parse a little JSON. However, since CMake 3.x (released on 06.2014), it added new features that make CMake more powerful, clean, and elegant. In my case the JSON for Modern C++ was taking 8 seconds to clone and took up 439 MB of space on my hard drive. ![]() This has the disadvantage of having to clone the whole git repository which can take a long time and sometimes requires a large amount of disk space. This is a very convenient feature which allows your projects dependencies to be neatly downloaded without having to include the source in your project. CMake includes the FetchContent library call which allows a dependency to either be cloned from a git repository or tar.gz archive to be included into the project. Add the URL/tarball file to the top of 3rdparty/CMakeLists. CMake has eased this pain, but it is still often quite difficult to deal with with the numerous different types of build system. Adding a third-party dependency Add the version and SHA256 hash to Versions. Often times 3rd party dependencies can be the hardest part of setting up a C++ project. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |