Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake "make install" or including a library in windows

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?

like image 309
denisps Avatar asked May 11 '16 19:05

denisps


People also ask

How do I add a library to CMake project?

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.

What is difference between make and CMake?

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.

What does CMake install mean?

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.


1 Answers

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.

like image 164
fghj Avatar answered Oct 24 '22 09:10

fghj