Skip to content

Commit

Permalink
Adds the following advantages:
Browse files Browse the repository at this point in the history
 - utf8::cpp is available, even when installed
 - cmake is aware of the library version
 - compatible with previous usage: target utf8cpp available when installed
  • Loading branch information
Finkman committed Nov 22, 2022
1 parent 3ca904b commit 73b347f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
25 changes: 22 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,36 @@ target_include_directories(utf8cpp INTERFACE
add_library(utf8::cpp ALIAS utf8cpp)

if(UTF8_INSTALL)
include(CMakePackageConfigHelpers)
if(MSVC)
set(DEF_INSTALL_CMAKE_DIR CMake)
else()
include(GNUInstallDirs) # define CMAKE_INSTALL_*
set(DEF_INSTALL_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/utf8cpp)
endif()

write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/utf8cppConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)

configure_package_config_file(
${PROJECT_SOURCE_DIR}/utf8cppConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/utf8cppConfig.cmake
INSTALL_DESTINATION ${DEF_INSTALL_CMAKE_DIR}
)

install(DIRECTORY source/ DESTINATION include/utf8cpp)
install(TARGETS utf8cpp EXPORT utf8cppConfig)
install(EXPORT utf8cppConfig DESTINATION ${DEF_INSTALL_CMAKE_DIR})
export(EXPORT utf8cppConfig)
install(TARGETS utf8cpp EXPORT utf8cppTargets)
install(EXPORT utf8cppTargets DESTINATION ${DEF_INSTALL_CMAKE_DIR})
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/utf8cppConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/utf8cppConfigVersion.cmake
DESTINATION
${DEF_INSTALL_CMAKE_DIR}
)
endif()

if(UTF8_SAMPLES)
Expand Down
6 changes: 6 additions & 0 deletions utf8cppConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/utf8cppTargets.cmake")
check_required_components( "utf8cpp" )

add_library(utf8::cpp ALIAS utf8cpp)

0 comments on commit 73b347f

Please sign in to comment.