AaronRobinsonMSFT / DNMD

Reimplementation of ECMA-335 metadata APIs
MIT License
16 stars 3 forks source link

Update build infrastructure to install as a modern CMake package #26

Closed jkoritzinsky closed 1 year ago

jkoritzinsky commented 1 year ago

This PR updates the build of DNMD in a few ways:

jkoritzinsky commented 1 year ago

The main goal driving this PR was the following:

Enable a developer to walk up to a project do the following steps, and be able to use dnmd:

  1. Use a CMake-based package manager or set CMAKE_PREFIX_PATH to the artifacts directory of dnmd to declare a dependency on dnmd.
  2. Write the following CMake in their code:
find_package(dncp REQUIRED)
find_package(dnmd REQUIRED)
  1. Link their library against dnmd::dnmd
  2. Add #include <dnmd.h> to their code.

This way the user doesn't need to include any external headers, define any types, or muck with include paths before including dnmd.h. Everything is automatically hooked up through CMake.

Most of the complexity here is due to limiting the exposed dependency surface for consumers. For example, consumers of dnmd::interfaces don't need to reference dnmd::dnmd, but consumers of dnmd::interfaces_static do. Also, the test projects use the internal include paths, but we don't ship those, so some of the complexity is due to how I hooked that up. I can probably reduce some of the CMake complexity here, and I can be more lax on exposing dependencies through the install interface.

I updated how we find ICU to be more "correct" with CMake instead of just discovering whatever is on the library path to provide a better failure experience if ICU isn't found (the failure before would fail at link time during the build, now it will fail at CMake configure time).