I'm trying to create an Open Source C++ project. I want it to be as easy to build as possible, but at the same time cross platform. I don't need gui or heavy libraries like boost or Qt, so I've settled on using GitHub, CMake, and LibSourcey. My problem is, I can't find a way to make my project easy to build in windows, which is my development environment. How can I "make install" a library in Windows for use in my project? Do I even have to install it in windows? Is it possible to download, build, and link it automatically?
On windows, besides an installer, I also want to make a portable version, so don't want any hard coded library paths.
I assume, on some platforms, like Linux, libraries are built separably and packaged up by maintainers. So I shouldn't just bundle up my own copies.
So, my question is: How can I set up a project that is cross platform and easy to build, and what are the best practices?
To add a library in CMake, use the add_library() command and specify which source files should make up the library. Rather than placing all of the source files in one directory, we can organize our project with one or more subdirectories.
Make (or rather a Makefile) is a buildsystem - it drives the compiler and other build tools to build your code. CMake is a generator of buildsystems. It can produce Makefiles, it can produce Ninja build files, it can produce KDEvelop or Xcode projects, it can produce Visual Studio solutions.
CMake provides the install command to specify how a project is to be installed. This command is invoked by a project in the CMakeLists file and tells CMake how to generate installation scripts. The scripts are executed at install time to perform the actual installation of files.
You can create git submodule
in your git repo with path for example
contrib/LibSourcery
and url to github repo of LibSourcery
, because of LibSourcery
uses cmake
you just
need add such line into your CMakeLists.txt
: add_subdirectory(contrib/LibSourcery)
So person who want to use your code, just do git clone --recursive url
to get all of your code and dependencies, after that it run cmake -G
, to create project for IDE
of his choice (including MSVC++ of course),
open project in IDE
and press build button, that's all.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With