TopoToolbox / libtopotoolbox

A C library for the analysis of digital elevation models.
https://topotoolbox.github.io/libtopotoolbox/
GNU General Public License v3.0
0 stars 3 forks source link

Add CMake package configuration #24

Closed wkearn closed 3 months ago

wkearn commented 3 months ago

This sets up a CMake Config package for libtopotoolbox that will allow it to be installed and more easily built by other CMake projects. The end goal is to use the libtopotoolbox CMake package with scikit-build-core to install things properly for pytopotoolbox.

CMakeLists.txt adds a target to install the topotoolbox library and header file in the appropriate lib/ and include/ directories, which are set by GNUInstallDirs. It sets include/topotoolbox.h to be a PUBLIC_HEADER, which allows it to be installed by the install command.

IMPORTANT: A static library is now built by default. The shared library can be built by passing the option -DBUILD_SHARED_LIBS=ON to cmake.

CMakeLists.txt also provides a package configuration that enables CMake's find_package to find the library. Something like find_package(TopoToolbox 3.0.0 REQUIRED) can add a library called topotoolbox to the environment of a CMake build if the CMAKE_PREFIX_PATH is set correctly.

cmake/TopoToolboxConfig.cmake.in is a template for a package configuration.

I have also added the TOPOTOOLBOX_STATICLIB flag to include/topotoolbox.h. This allows us to turn the __declspec definitions off for Windows when we build the static library. We set the flag automatically in src/CMakeLists.txt by checking the value of BUILD_SHARED_LIBS in src/CMakeLists.txt, which controls whether CMake builds a shared or a static library.