mirror of
https://gitlab.freedesktop.org/uchardet/uchardet.git
synced 2025-12-06 08:46:40 +08:00
cmake exported targets
The minimum required cmake version is raised to 3.1, because the exported targets started at that version. The build system creates the exported targets: - The executable uchardet::uchardet - The library uchardet::libuchardet - The static library uchardet::libuchardet_static A downstream project using CMake can find and link the library target directly with cmake (without needing pkg-config) this way: ~~~ project(sample LANGUAGES C) find_package ( uchardet ) if (uchardet_FOUND) add_executable( sample sample.c ) target_link_libraries ( sample PRIVATE uchardet::libuchardet ) endif () ~~~ After installing uchardet in a prefix like "$HOME/uchardet/": cmake -DCMAKE_PREFIX_PATH="$HOME/uchardet/;..." Instead installing, the build directory can be used directly, for instance: cmake -Duchardet_DIR="$HOME/uchardet-0.1.0/build/" ...
This commit is contained in:
parent
6f38ab95f5
commit
d7dad549bd
@ -1,5 +1,5 @@
|
||||
######## Project settings
|
||||
cmake_minimum_required(VERSION 2.8.5)
|
||||
cmake_minimum_required(VERSION 3.1)
|
||||
include(CheckCCompilerFlag)
|
||||
set (PACKAGE_NAME uchardet)
|
||||
project (${PACKAGE_NAME} CXX C)
|
||||
@ -72,3 +72,39 @@ install(
|
||||
add_subdirectory(src)
|
||||
add_subdirectory(doc)
|
||||
add_subdirectory(test)
|
||||
|
||||
######## Exported targets
|
||||
|
||||
install(
|
||||
EXPORT UchardetTargets
|
||||
FILE ${PACKAGE_NAME}-targets.cmake
|
||||
NAMESPACE ${PACKAGE_NAME}::
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PACKAGE_NAME}
|
||||
)
|
||||
|
||||
export(
|
||||
EXPORT UchardetTargets
|
||||
FILE "${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}-targets.cmake"
|
||||
NAMESPACE ${PACKAGE_NAME}::
|
||||
)
|
||||
|
||||
include(CMakePackageConfigHelpers)
|
||||
write_basic_package_version_file(
|
||||
${PACKAGE_NAME}-config-version.cmake
|
||||
VERSION ${UCHARDET_VERSION}
|
||||
COMPATIBILITY AnyNewerVersion
|
||||
)
|
||||
|
||||
configure_file(
|
||||
${PACKAGE_NAME}-config.cmake.in
|
||||
${PACKAGE_NAME}-config.cmake
|
||||
@ONLY
|
||||
)
|
||||
|
||||
install (
|
||||
FILES
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}-config.cmake"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake"
|
||||
DESTINATION
|
||||
${CMAKE_INSTALL_LIBDIR}/cmake/${PACKAGE_NAME}
|
||||
)
|
||||
|
||||
@ -84,6 +84,12 @@ if(BUILD_SHARED_LIBS)
|
||||
target_compile_definitions("${UCHARDET_LIBRARY}" PUBLIC UCHARDET_SHARED)
|
||||
endif()
|
||||
|
||||
target_include_directories(${UCHARDET_LIBRARY}
|
||||
PUBLIC
|
||||
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
|
||||
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PACKAGE_NAME}>"
|
||||
)
|
||||
|
||||
if (UCHARDET_STATIC_LIBRARY)
|
||||
add_library(
|
||||
${UCHARDET_STATIC_LIBRARY}
|
||||
@ -91,6 +97,12 @@ if (UCHARDET_STATIC_LIBRARY)
|
||||
${UCHARDET_SOURCES}
|
||||
)
|
||||
target_compile_definitions("${UCHARDET_STATIC_LIBRARY}" PRIVATE BUILDING_UCHARDET)
|
||||
|
||||
target_include_directories(${UCHARDET_STATIC_LIBRARY}
|
||||
PUBLIC
|
||||
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
|
||||
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PACKAGE_NAME}>"
|
||||
)
|
||||
endif (UCHARDET_STATIC_LIBRARY)
|
||||
|
||||
set_target_properties(
|
||||
@ -121,6 +133,8 @@ if (NOT WIN32)
|
||||
install(
|
||||
TARGETS
|
||||
${UCHARDET_LIBRARY}
|
||||
EXPORT
|
||||
UchardetTargets
|
||||
LIBRARY DESTINATION
|
||||
${CMAKE_INSTALL_LIBDIR}
|
||||
ARCHIVE DESTINATION
|
||||
@ -130,6 +144,8 @@ else (NOT WIN32)
|
||||
install(
|
||||
TARGETS
|
||||
${UCHARDET_LIBRARY}
|
||||
EXPORT
|
||||
UchardetTargets
|
||||
RUNTIME DESTINATION
|
||||
${CMAKE_INSTALL_BINDIR}
|
||||
ARCHIVE DESTINATION
|
||||
@ -141,6 +157,8 @@ if (UCHARDET_STATIC_LIBRARY)
|
||||
install(
|
||||
TARGETS
|
||||
${UCHARDET_STATIC_LIBRARY}
|
||||
EXPORT
|
||||
UchardetTargets
|
||||
ARCHIVE DESTINATION
|
||||
${CMAKE_INSTALL_LIBDIR}
|
||||
)
|
||||
|
||||
@ -35,6 +35,8 @@ target_link_libraries(
|
||||
install(
|
||||
TARGETS
|
||||
${UCHARDET_BINARY}
|
||||
EXPORT
|
||||
UchardetTargets
|
||||
RUNTIME DESTINATION
|
||||
${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
|
||||
19
uchardet-config.cmake.in
Normal file
19
uchardet-config.cmake.in
Normal file
@ -0,0 +1,19 @@
|
||||
# This file may optionally do:
|
||||
#
|
||||
# 1. Check for dependencies of exported targets. Example:
|
||||
#
|
||||
# include(CMakeFindDependencyMacro)
|
||||
# find_dependency(MYDEP REQUIRED)
|
||||
#
|
||||
# find_dependency() has the same syntax as find_package()
|
||||
#
|
||||
# 2. Capture values from configuration. Example:
|
||||
#
|
||||
# set(my-config-var @my-config-var@)
|
||||
#
|
||||
# 3. Other required setup when importing targets from another project
|
||||
#
|
||||
# See also:
|
||||
# https://cliutils.gitlab.io/modern-cmake/chapters/install.html
|
||||
#
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/uchardet-targets.cmake")
|
||||
Loading…
x
Reference in New Issue
Block a user