Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CMake imported target for docopt library #159

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

eaaltonen
Copy link
Contributor

This PR writes the CMake config-file package using CMakePackageConfigHelpers and exports the target as a Docopt::docopt imported target.

This allows developers to install and use the library without necessarily requiring root permission by:

  1. Installing docopt with -DCMAKE_INSTALL_PREFIX="${HOME}/wherever"
  2. then using with -DCMAKE_PREFIX_PATH="${HOME}/wherever" and linking to imported target Docopt::docopt.

Keeping in mind the newly released FetchContent and find_package() integration, also add an alias target so that Docopt::docopt can be linked to regardless of whether the build uses a prebuilt package or fetches the sources.

Using a separate build directory is a very common way of using CMake so
add an ignore pattern for those.
DESTINATION "${CMAKE_INSTALL_LIBDIR}/${ConfigPackageLocation}")
install(EXPORT ${export_name}
DESTINATION "${CMAKE_INSTALL_LIBDIR}/${ConfigPackageLocation}"
NAMESPACE Docopt::)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the name:

  • is current Docopt::docopt good
  • should it be Docopt.cpp::docopt
  • something else ?

install(FILES docopt-config.cmake ${PROJECT_BINARY_DIR}/docopt-config-version.cmake DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/docopt")
install(EXPORT ${export_name} DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/docopt")
set(ConfigPackageLocation "cmake/docopt")
# Unix layout, ref https://cmake.org/cmake/help/latest/command/find_package.html#config-mode-search-procedure
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's at least two valid choices here, so I'd like to check the project author's preference here:

  • unix layout (current)
  • picking a layout according the current / specified OS.

Write our CMake config-file package using the
`configure_package_config_file` function defined in
CMakePackageConfigHelpers.cmake
and export our library in a namespace so that it can be used as an
imported target.
With the alias, the `Docopt::docopt` target can be linked to regardless
of whether the consuming project uses `find_package` or
`add_subdirectory`.
@eaaltonen
Copy link
Contributor Author

added missing newline to docopt-config.cmake.in.

@eaaltonen
Copy link
Contributor Author

@jaredgrubb : if you could take a look? I will be submitting packaging to Buildroot soonish.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant