The changes in this PR enable a user to install the library via cmake --install. Along with the header and the static library, it also installs CMake export files which allows users to use the library with CMake's find_package().
When configuring the project, you need to tell CMake where to find the exported CMake files by setting the CMAKE_PREFIX_PATH like so:
$ cd test-project
$ cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH=<path to installed minitrace>/share/minitrace
Background
I plan on also opening a PR at the vcpkg repo to update the minitrace port to the latest version. Currently, vcpkg uses an old version from 2019 and supplies its own CMakeLists.txt to build and install minitrace. However, they don't define MTR_ENABLED when building, resulting in a functionally useless binary. While I investigated that issue, I noticed that minitrace has since added its own CMakeLists.txt, so it seemed like a good idea to use that one and remove the custom one in vcpkg. However, vcpkg installs libraries with cmake --install, so without the changes in this PR, vcpkg would have to keep (and maintain) their own CMakeLists.txt.
Changes
The changes in this PR enable a user to install the library via
cmake --install
. Along with the header and the static library, it also installs CMake export files which allows users to use the library with CMake'sfind_package()
.The necessary CMake code is pretty much taken straight from the CMake guide at https://cmake.org/cmake/help/latest/guide/tutorial/Adding%20Export%20Configuration.html.
I chose the installation prefixes (mostly just the prefix for the CMake exports, which is
share/minitrace
) to conform to the layout that vcpkg uses.How to test
First, build and install minitrace into a directory of your choosing:
This will install minitrace to
<dir>
. Afterwards, you can test the exported CMake targets by creating a new CMake project which imports minitrace:When configuring the project, you need to tell CMake where to find the exported CMake files by setting the
CMAKE_PREFIX_PATH
like so:Background
I plan on also opening a PR at the vcpkg repo to update the minitrace port to the latest version. Currently, vcpkg uses an old version from 2019 and supplies its own
CMakeLists.txt
to build and install minitrace. However, they don't defineMTR_ENABLED
when building, resulting in a functionally useless binary. While I investigated that issue, I noticed that minitrace has since added its ownCMakeLists.txt
, so it seemed like a good idea to use that one and remove the custom one in vcpkg. However, vcpkg installs libraries withcmake --install
, so without the changes in this PR, vcpkg would have to keep (and maintain) their ownCMakeLists.txt
.