-
Notifications
You must be signed in to change notification settings - Fork 64
Description
Hi Lex,
I have attached a patch which enables CMake support. I noticed that you started another project, but it might be useful to still support this one, at least until the other project reaches feature parity.
Maybe it could also prove useful as inspiration for that other project? :)
The patch adds modern CMake support, and is validated on both Linux and Windows. On Windows, it works with both mingw (gcc) and the Visual Studio compilers.
Features:
- ability to select whether to build the shared library and the static library (-DMODEST_BUILD_SHARED, and -DMODEST_BUILD_STATIC)
- ability to select the C standard used by the compiler, and to reject using a lower standard version if the requested one is not supported (default is C99)
- ability to add a suffix to debug binaries, by default "d";
- ability to select whether to install the header files or not
- ability to select whether to use the pthreads library or not; pthreads is linked only internally and not exposed to users of the modest library
- automatically retrieve library version from header files
- modern way of specifying target compiler definitions, options, include directories, with different settings for building the libraries and for installing the libraries
- define the targets in a namespace (modest::modest_shared, and modest::modest_static)
- install targets with proper creation of cmake config files at install location that allow using the libraries by simply specifying "find_package(modest)"
- ability to pack the libraries for distribution
- for the visual studio compiler, creation of exports for the shared library
- for the binaries built with the Visual Studio compiler, install also the pdb file (with the debug symbols)
- out-of-source builds
Notes:
- the installation will install a cmake folder inside the lib folder, with cmake configuration files: a modestConfig, a modestConfigVersion, as well as modest.cmake that defines the import targets needed by users of the modest libraries, and a modest-xxxx.cmake file for each build configuration (Debug, Release, etc) that lets a project that uses the modest libraries link to the debug binaries when it's built in debug mode, or to the release binaries when its built in release mode
- the debug suffix is useful for installing both the release and debug binaries at the same location; this allows a project that links the modest libraries to use either the debug or release binaries automatically, with no additional configuration; which are the binaries for debug or for release is specified in the installed cmake configuration files
A project that wants to use the installed libraries only has to add the modest libraries installation folder to its CMAKE_MODULE_PATH, and specify this in its CMakeLists.txt:
find_package(modest CONFIG REQUIRED)
...................................................................................
target_link_libraries(my_app
$<IF:$BOOL:${BUILD_SHARED_LIBS},modest::modest_shared,modest::modest_static>
)
The above will let the linking to the dynamic or the static library be controlled by the CMake global flag BUILD_SHARED_LIBS.
When "my_app" is built in Debug configuration, the modest Debug binaries will be linked in automatically. When "my_app" is built in Release configuration, the modest Release binaries will be linked in instead, etc.
As you can see, this is the modern Cmake way, with no need for include_directories and such.
To manually enforce the linking to the shared library, one would replace the above with:
target_link_libraries(my_app
modest::modest_shared
)
Or for enforcing the linking with the static library:
target_link_libraries(my_app
modest::modest_static
)
What this Cmake support patch does not do, is build the examples and the tests though.
cmake_support.zip