diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index b540e35..b94c3fe 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -21,7 +21,7 @@ jobs: - name: Build run: | mkdir build - cmake -S . -B build -DBUILD_SHARED_LIBS=${{ matrix.shared }} -DUTF8PROC_ENABLE_TESTING=ON + cmake -S . -B build -DBUILD_SHARED_LIBS=${{ matrix.shared }} -DUTF8PROC_ENABLE_TESTING=ON -DCMAKE_INSTALL_PREFIX=tmp/install cmake --build build - name: Run Test run: ctest --test-dir build -V @@ -33,6 +33,21 @@ jobs: path: | build/libutf8proc.* build/Debug/utf8proc.* + - name: Test Consuming (Windows) + if: runner.os == 'Windows' + run: | + cmake --install build --config Debug + cmake -S test/app -B test/app/build -DCMAKE_INSTALL_PREFIX=tmp/install + cmake --build test/app/build + $Env:PATH = "$PWD\tmp\install\bin;$Env:PATH" + test/app/build/Debug/app.exe + - name: Test Consuming (Unix) + if: runner.os != 'Windows' + run: | + cmake --install build + cmake -S test/app -B test/app/build -DCMAKE_INSTALL_PREFIX=tmp/install + cmake --build test/app/build + test/app/build/app mingw: strategy: @@ -52,7 +67,7 @@ jobs: - name: Build run: | mkdir build - cmake -S . -B build -DBUILD_SHARED_LIBS=${{ matrix.shared }} -DUTF8PROC_ENABLE_TESTING=ON -G'MSYS Makefiles' + cmake -S . -B build -DBUILD_SHARED_LIBS=${{ matrix.shared }} -DUTF8PROC_ENABLE_TESTING=ON -G'MSYS Makefiles' -DCMAKE_INSTALL_PREFIX=tmp/install cmake --build build - name: Run Test run: ctest --test-dir build -V @@ -62,3 +77,10 @@ jobs: with: name: windows-mingw64 path: build/libutf8proc.* + - name: Test Consuming + run: | + cmake --install build + cmake -S test/app -B test/app/build -DCMAKE_INSTALL_PREFIX=tmp/install -G'MSYS Makefiles' + cmake --build test/app/build + PATH="$(pwd)/tmp/install/bin:$PATH" + test/app/build/app.exe diff --git a/CMakeLists.txt b/CMakeLists.txt index e6f99d1..f13bb7d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,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 $ $) if (BUILD_SHARED_LIBS) # Building shared library @@ -53,14 +53,33 @@ 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) + 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 + ) + write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/utf8proc-config-version.cmake" + COMPATIBILITY SameMajorVersion + ) + install(FILES + "${CMAKE_CURRENT_BINARY_DIR}/utf8proc-config.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/utf8proc-config-version.cmake" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/utf8proc" + ) endif() if(UTF8PROC_ENABLE_TESTING) diff --git a/README.md b/README.md index f652477..553494e 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,16 @@ gmake CC=/opt/aCC/bin/aCC CFLAGS="+O2" PICFLAG="+z" C99FLAG="-Ae" WCFLAGS="+w" L ``` To run `gmake install` you will need GNU coreutils for the `install` command, and you may want to pass `prefix=/opt libdir=/opt/lib/hpux32` or similar to change the installation location. +### 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) +``` + ## General Information The C library is found in this directory after successful compilation diff --git a/cmake/utf8proc-config.cmake.in b/cmake/utf8proc-config.cmake.in new file mode 100644 index 0000000..b9149bc --- /dev/null +++ b/cmake/utf8proc-config.cmake.in @@ -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) diff --git a/test/app/CMakeLists.txt b/test/app/CMakeLists.txt new file mode 100644 index 0000000..9d9786c --- /dev/null +++ b/test/app/CMakeLists.txt @@ -0,0 +1,6 @@ +# This is a test app to test consuming utf8proc with CMake. +cmake_minimum_required(VERSION 3.16) +project(utf8proc-test) +find_package(utf8proc REQUIRED) +add_executable(app app.c) +target_link_libraries(app utf8proc::utf8proc) diff --git a/test/app/app.c b/test/app/app.c new file mode 100644 index 0000000..4b6f8be --- /dev/null +++ b/test/app/app.c @@ -0,0 +1,9 @@ +#include +#include + +int +main(void) +{ + printf("%s\n", utf8proc_version()); + return 0; +}