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 Config-file package #260

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ add_library (utf8proc
)

# expose header path, for when this is part of a larger cmake project
target_include_directories(utf8proc PUBLIC .)
target_include_directories(utf8proc PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> $<INSTALL_INTERFACE:include>)

if (BUILD_SHARED_LIBS)
# Building shared library
Expand Down Expand Up @@ -55,14 +55,34 @@ set_target_properties (utf8proc PROPERTIES

if (UTF8PROC_INSTALL)
include(GNUInstallDirs)
install(FILES utf8proc.h DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}")
install(FILES utf8proc.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
install(TARGETS utf8proc
ARCHIVE DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}"
EXPORT utf8proc-targets
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
)
configure_file(libutf8proc.pc.cmakein libutf8proc.pc @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libutf8proc.pc" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libutf8proc.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
# Install CMake targets file.
install(EXPORT utf8proc-targets FILE utf8proc-targets.cmake DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/utf8proc" NAMESPACE utf8proc::)
include (CMakePackageConfigHelpers)
kevinAlbs marked this conversation as resolved.
Show resolved Hide resolved
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/utf8proc-config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/utf8proc-config.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/utf8proc"
NO_SET_AND_CHECK_MACRO
kevinAlbs marked this conversation as resolved.
Show resolved Hide resolved
)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/utf8proc-config-version.cmake"
COMPATIBILITY AnyNewerVersion
Copy link

Choose a reason for hiding this comment

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

It seems that utf8proc follows the semantic versioning. SameMajorVersion may be better.

)
install (FILES
"${CMAKE_CURRENT_BINARY_DIR}/utf8proc-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/utf8proc-config-version.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/utf8proc"
)

kevinAlbs marked this conversation as resolved.
Show resolved Hide resolved
endif()

if(UTF8PROC_ENABLE_TESTING)
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ cmake -S . -B build
cmake --build build
```

## Using with CMake

A CMake Config-file package is provided. To use utf8proc in a CMake project:

```cmake
add_executable (app app.c)
find_package (utf8proc 2.9.0 REQUIRED)
target_link_libraries (app PRIVATE utf8proc::utf8proc)
```

Copy link

Choose a reason for hiding this comment

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

It seems that Using other compilers is a subsection of Quick Start.
How about moving this after Using other compilers?

### Using other compilers
The included `Makefile` supports GNU/Linux flavors and MacOS with `gcc`-like compilers; Windows users will typically use `cmake`.

Expand Down
5 changes: 5 additions & 0 deletions cmake/utf8proc-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/utf8proc-targets.cmake")
# `check_required_components` is used to ensure consumer did not erroneously request components.
# No components are currently defined.
check_required_components(utf8proc)