How to write Cmake find script for multi-platform library? - cmake

I have a third-party library that needs to be hooked up intpo cmake project. The library is built for a number of platforms, so in its folder, there are files:
libName_x86.lib
libName_x86.dll
libname_x64.lib
libName_x64.dll
libName_android.x86.a
libName_android.x86_64.a
libName_macosx.a
libName_mac.xcconfig
libName_mac.Debug.xcconfig
libName_mac.Release.xcconfig
and so on.
What would be the proper cmake way to determine name of the library in the find script?

Related

How to build libraries with different options for different CMake targets?

I have a CMake project which consist from a set libraries.
This libraries links with a several programs.
Is it possible to replace compile options, for libraries which build for specifical programs?
For example, when cmake builds library for program A it defines first includes directory, for another program it includes directory B?

How can I add external libraries to a cmake install?

My cmake project builds against external libraries, e.g. Boost. I would now like to advise cmake to generate "make install code" that causes all used external libraries to be added to the installation package.
My hope is that cmake can inspect the built shared objects and executables, e.g. using ldd, to find out which external libraries are required and add them without explicit naming of the individual libraries in the CMakeLists.txt.
Of course there is the other case in which the built code expicitly loads the external libaries (dlopen(), ...), e.g. as done by Intel IPP. In this case I would probably somehow need to explicitly name the libraries to install, e.g. using some variables set by the FindXXX cmake scripts.

CMake deploying required libraries

Is it possible to get CMake to gather up all the package libraries used during compilation, recursively grab their required libraries, and then put them all in a single directory?
As an example if my application requires gtk it would grab glib and its required libraries libiconv, gettext, and libffi.
You can use the GetPrerequesites CMake module.
See here for more information

Package vs Library

I've just started working with CMake and I noticed that they have both a find_package and a find_library. And this confuses me. Can somebody explain the difference between a package and a library in the world of programming? Or, in the world of CMake?
Appreciate it, guys!
Imagine you want to use zlib in your project, you need to find the header file zlib.h, and the library libz.so (on Linux). You can use the low-level cmake commands find_path and find_library to find them, or you can use find_package(ZLIB). The later command will try to find out all what is necessary to use zlib. It can be extra macro definitions, or dependencies.
Update, more detail about find_package: when the CMake command find_package(SomeThing) is called, as in the documentation, there are two possible modes that cmake can run:
the module mode (that searches for a file FindSomeThing.cmake)
or the config mode (that searches for a file named SomeThingConfig.cmake)
For ZLIB, there is a module named FindZLIB, shipped with CMake itself (on my Linux machine that is the file /usr/share/cmake/Modules/FindZLIB.cmake). That module is a CMake script that uses the CMake API to search for ZLIB files in default locations, or ask the user for the location if it cannot be found automatically.

C++ Windows Application to include all dlls into an executable file

IDE: VS2005
Say I am using Poco library and the executable needs below dlls. I have to put them in same directory where the executable is.
msjava.dll
msvcp80.dll
msvcr80.dll
PocoFoundation.dll
PocoNet.dll
Is there any way that can build a dll-free executable? Thanks.
They don't have to be in the same directory. They can be in another directory if your PATH variables includes the directory they are in.
It looks like the Poco libraries can be downloaded as source, so you should be able to build them as static libraries and make a stand alone executable.
Update
For the msvc DLL's, you can build against static libraries. Bring up the properties of your project, go to C/C++, Code Generation and modify "Runtime Library". Make sure to choose a library other then "Multi-threaded DLL" or "Multi-threaded Debug DLL." You will also want to make sure you do that for the Poco libraries as well.