Best practice for cmake package dependency - cmake

I have two separate git repositories that I am not sure how to best bring together using cmake. I would like a solution that is cross platform.
I have a C++ library project which produces a static library (and C++ headers). This project has its own cmake which will produce a static library. I haven't yet written an install step in the cmake.
I have a UI (Qt) project which visualizes the product of this library. This also is based on cmake and should be using the library; in fact, it does not make sense without the library.
What is the best practice for a situation such as this? I could imagine a few things:
The library is a git submodule of the UI project and the cmake of the UI uses add_subdirectory()
The UI build expects the user to have built and installed (to the system) the static library & headers
The UI build has a hard coded path (or ENV var) to the cmake of the library (or something like LibraryConfig.cmake, but I'm not familiar enough with this yet)
My end goal is that the user should be able to pull, build, and use the library in their own projects, but if in the future they feel necessary, they can grab the visualization tool additionally and use it with the library. Also, people who are not comfortable with using the library themselves might just want to clone the visualization tool repo and build & use it.

Related

Is CMake an equivalent of npm?

I am totally new to CMake and compiled languages for that matter. I have seen this question and answer. But I still don't fully understand what CMake is.
I am coming from a nodeJs/Javascipt environment, therefore if I could know a CMake equivalent in the nodeJs/Javascipt environment it would really help me understand what it is.So... Is CMake an equivalent of npm?
No, citing from Wikipedia:
CMake is a cross-platform free and open-source software tool for managing the build process of software using a compiler-independent method. It supports directory hierarchies and applications that depend on multiple libraries. It is used in conjunction with native build environments such as Make, Qt Creator, Ninja, Apple's Xcode, and Microsoft Visual Studio. It has minimal dependencies, requiring only a C++ compiler on its own build system.
JavaScript is an interpreted language, that means NodeJS/Browsers read and understand the code and execute it directly. For example C is built via a compiler (that reads and understands the code before execution) to Machine code (that does not need to be understand because it's the native language from your processor) and can be executed faster. CMake simplifies calling the Compiler, linking libraries (something like setting up require) and more for all files. Altough sometimes using babel, webpack and others via npm run is called 'building'.

CMake: how to properly distribuite CMake based libraries that will not be installed

It's said that library authors should ship their library with a config-file instead of a plain find-module.
Basically config-file are to be installed with the associated library on the system and can be used transparently by the user, whereas find-module is written by the user by his own when he finds out that the library hasn't any config-file.
But, what if I'm sure that my library will never be installed?
I'm doing embedded system development and it doesn't make much sense to install my static libraries on the system.
Different modules are organized as static libraries and handled by each project with git submodules.
Is there any way I can use config-files even in this scenario? Or, as library author, I should write a example of vanilla Find-module and say to client code "Take and copy this to your CMAKE_MODULE_PATH"?
Or maybe just tell the client code cmake to call add_subdirectory?

How to use cmake to compile autoconf project?

I'm using cmake to build my project, and I want it to integrate with a third party library called Project_A that using autoconf to generate make, how to write the CMakeLists.txt to build the Project_A and my project together?
Thanks!
I think using the ExternalProject module in CMake would be the best solution. See here for a good introduction to the api.
If you are wanting to do lexical code reuse (ie, copy-n-paste the code rather then relying on a dependency), then don't stop half way. By using the external code in this way, you are essentially claiming ownership of it for the purpose of your project, so there is no need to keep the autotool build. Just pull the code out and build it via cmake. Don't bother trying to create a hybrid build.

How to automate building of third party library using cmake

What I am looking for:
Download library
Extract It
Apply custom patch
Run configure
Run build command
What library I am trying to build are:
Openssl
Boost
Thrift
C-ares
Curl
Pcre
Nginx
ICU
JsonCPP
I think I can do these things using external module: http://cmake.org/cmake/help/v2.8.8/cmake.html#module:ExternalProject
But I have following question?
I have different type of build and with different directory. Is it
going to build all these library for every different target? If yes
it will be painful as all these library take one hour to build. Is
there a way I can control it and it only build it once. As library
remains same for all these targets.
On switching directory to different name. Cmake force everything to
be rebuild-ed. Will it be same for external library. If yes? How to
solve this problem. I don't want to rebuild the library if I am not
changing them and want to use them while switching to different
branches without building them.
Yes, you can use CMake's ExternalProject feature to accomplish what you want to do.
When using cross-compilation in combination with external projects, the source code will be built once for each toolchain. You could avoid rebuilds if you checked in the results of the build into a source-control system, and re-checked it out on each new person's machine, but I do not recommend this. Instead, have one of your "set up new computer" tasks actually be allowing the compilation to run overnight, which will also act as a test that the machine is actually usable. That set-up task can be launched by a system administrator prior to a new hire's arrival, or you can leave it to the new hire, as circumstances require.
I'm not completely certain what you are asking in your second question, but if the library is unchanged, CMake will detect that it is unchanged and not recompile it. Typically, the source code would be in a single directory tree: each compiled version would be built in a distinct location. Thus, developers can access any compiled version at any time just by switching directories. This is particularly helpful because it allows you to mount these directories over NFS to embedded hardware, et cetera.

Maemo / Symbian and external libraries

How can I know, whether an external library can be compiled to work on a different platform? the library for instance is tesseract-ocr
And if it possible, how do I do this?? (Basically I would like to create a Qt application that uses this library)
To find out, try building the library yourself. At the moment your question is quite broad. Post new questions when you have something more specific to ask.
If building the library fails, it is most probably due to some unsupported dependencies that you need to port first yourself.
Porting to Maemo is probably straightforward as it is a Debian-based environment and supports all the build tools such as autotools.
Symbian doesn't have autotools. Perhaps the fastest way to get started there is to first configure and build the library on e.g. cygwin and then generate the required bld.inf and .mmp files to build it on Symbian.
You can link your Qt application to regular C/C++ libraries. Just include the necessary header files in your code and link to the library using LIBS += -lfoo in your .pro file.