summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-03-01 19:55:01 (GMT)
committerKitware Robot <kwrobot@kitware.com>2021-03-01 19:55:10 (GMT)
commit7a10aa922d43bd32095516ecce0fef6c6c0f057e (patch)
tree8bfb6da8e31b6335f2c8a2a1a150d8b7df2ed1f0 /Modules
parent653b871cb782dd30d1139e09a8285ba072518ae9 (diff)
parenta9b11a06f56c79f13253c31c46c9e8405fdf6deb (diff)
downloadCMake-7a10aa922d43bd32095516ecce0fef6c6c0f057e.zip
CMake-7a10aa922d43bd32095516ecce0fef6c6c0f057e.tar.gz
CMake-7a10aa922d43bd32095516ecce0fef6c6c0f057e.tar.bz2
Merge topic 'FindIntl-FindIconv-versions'
a9b11a06f5 FindIntl: Add version support 01e9922db5 FindIconv: Add version support Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !5852
Diffstat (limited to 'Modules')
-rw-r--r--Modules/FindIconv.cmake44
-rw-r--r--Modules/FindIntl.cmake117
2 files changed, 139 insertions, 22 deletions
diff --git a/Modules/FindIconv.cmake b/Modules/FindIconv.cmake
index 41b7550..5ec12b2 100644
--- a/Modules/FindIconv.cmake
+++ b/Modules/FindIconv.cmake
@@ -25,6 +25,24 @@ The following variables are provided to indicate iconv support:
The iconv libraries to be linked.
+.. variable:: Iconv_VERSION
+
+ .. versionadded:: 3.21
+
+ The version of iconv found (x.y)
+
+.. variable:: Iconv_VERSION_MAJOR
+
+ .. versionadded:: 3.21
+
+ The major version of iconv
+
+.. variable:: Iconv_VERSION_MINOR
+
+ .. versionadded:: 3.21
+
+ The minor version of iconv
+
.. variable:: Iconv_IS_BUILT_IN
A variable indicating whether iconv support is stemming from the
@@ -51,6 +69,10 @@ The following cache variables may also be set:
On POSIX platforms, iconv might be part of the C library and the cache
variables ``Iconv_INCLUDE_DIR`` and ``Iconv_LIBRARY`` might be empty.
+.. note::
+ Some libiconv implementations don't embed the version number in their header files.
+ In this case the variables ``Iconv_VERSION*`` will be empty.
+
#]=======================================================================]
include(${CMAKE_CURRENT_LIST_DIR}/CMakePushCheckState.cmake)
@@ -118,9 +140,29 @@ find_library(Iconv_LIBRARY
mark_as_advanced(Iconv_INCLUDE_DIR)
mark_as_advanced(Iconv_LIBRARY)
+# NOTE: glibc's iconv.h does not define _LIBICONV_VERSION
+if(Iconv_INCLUDE_DIR AND NOT Iconv_IS_BUILT_IN)
+ file(STRINGS ${Iconv_INCLUDE_DIR}/iconv.h Iconv_VERSION_DEFINE REGEX "_LIBICONV_VERSION (.*)")
+
+ if(Iconv_VERSION_DEFINE MATCHES "(0x[A-Fa-f0-9]+)")
+ set(Iconv_VERSION_NUMBER "${CMAKE_MATCH_1}")
+ # encoding -> version number: (major<<8) + minor
+ math(EXPR Iconv_VERSION_MAJOR "${Iconv_VERSION_NUMBER} >> 8" OUTPUT_FORMAT HEXADECIMAL)
+ math(EXPR Iconv_VERSION_MINOR "${Iconv_VERSION_NUMBER} - (${Iconv_VERSION_MAJOR} << 8)" OUTPUT_FORMAT HEXADECIMAL)
+
+ math(EXPR Iconv_VERSION_MAJOR "${Iconv_VERSION_MAJOR}" OUTPUT_FORMAT DECIMAL)
+ math(EXPR Iconv_VERSION_MINOR "${Iconv_VERSION_MINOR}" OUTPUT_FORMAT DECIMAL)
+ set(Iconv_VERSION "${Iconv_VERSION_MAJOR}.${Iconv_VERSION_MINOR}")
+ endif()
+
+ unset(Iconv_VERSION_DEFINE)
+ unset(Iconv_VERSION_NUMBER)
+endif()
+
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
if(NOT Iconv_IS_BUILT_IN)
- find_package_handle_standard_args(Iconv REQUIRED_VARS Iconv_LIBRARY Iconv_INCLUDE_DIR)
+ find_package_handle_standard_args(Iconv REQUIRED_VARS Iconv_LIBRARY Iconv_INCLUDE_DIR
+ VERSION_VAR Iconv_VERSION)
else()
find_package_handle_standard_args(Iconv REQUIRED_VARS Iconv_LIBRARY)
endif()
diff --git a/Modules/FindIntl.cmake b/Modules/FindIntl.cmake
index 686c818..a1dfed1 100644
--- a/Modules/FindIntl.cmake
+++ b/Modules/FindIntl.cmake
@@ -10,27 +10,75 @@ FindIntl
Find the Gettext libintl headers and libraries.
This module reports information about the Gettext libintl
-installation in several variables. General variables::
+installation in several variables.
- Intl_FOUND - true if the libintl headers and libraries were found
- Intl_INCLUDE_DIRS - the directory containing the libintl headers
- Intl_LIBRARIES - libintl libraries to be linked
+.. variable:: Intl_FOUND
+
+ True if libintl is found.
+
+.. variable:: Intl_INCLUDE_DIRS
+
+ The directory containing the libintl headers.
+
+.. variable:: Intl_LIBRARIES
+
+ The intl libraries to be linked.
+
+.. variable:: Intl_VERSION
+
+ .. versionadded:: 3.21
+
+ The version of intl found (x.y.z)
+
+.. variable:: Intl_VERSION_MAJOR
+
+ .. versionadded:: 3.21
+
+ The major version of intl
+
+.. variable:: Intl_VERSION_MINOR
+
+ .. versionadded:: 3.21
+
+ The minor version of intl
+
+.. variable:: Intl_VERSION_PATCH
+
+ .. versionadded:: 3.21
+
+ The patch version of intl
.. versionadded:: 3.20
This module defines :prop_tgt:`IMPORTED` target ``Intl::Intl``.
-The following cache variables may also be set::
+The following cache variables may also be set:
- Intl_INCLUDE_DIR - the directory containing the libintl headers
- Intl_LIBRARY - the libintl library (if any)
- Intl_HAVE_GETTEXT_BUILTIN - check if gettext is in the C library
- Intl_HAVE_DCGETTEXT_BUILTIN - check if dcgettext is in the C library
- Intl_IS_BUILTIN - whether intl is a part of the C library determined
- from the result of Intl_HAVE_GETTEXT_BUILTIN and Intl_HAVE_DCGETTEXT_BUILTIN
+.. variable:: Intl_INCLUDE_DIR
-.. versionadded:: 3.20
- Added the ``Intl_HAVE_GETTEXT_BUILTIN``, ``Intl_HAVE_DCGETTEXT_BUILTIN`` and
- ``Intl_IS_BUILTIN`` variables.
+ The directory containing the libintl headers
+
+.. variable:: Intl_LIBRARY
+
+ The libintl library (if any)
+
+.. variable:: Intl_HAVE_GETTEXT_BUILTIN
+
+ .. versionadded:: 3.20
+
+ True if gettext is in the C library
+
+.. variable:: Intl_HAVE_DCGETTEXT_BUILTIN
+
+ .. versionadded:: 3.20
+
+ True if dcgettext is in the C library
+
+.. variable:: Intl_IS_BUILTIN
+
+ .. versionadded:: 3.20
+
+ whether intl is a part of the C library determined from the result of
+ Intl_HAVE_GETTEXT_BUILTIN and Intl_HAVE_DCGETTEXT_BUILTIN
.. note::
On some platforms, such as Linux with GNU libc, the gettext
@@ -39,6 +87,10 @@ The following cache variables may also be set::
case.
.. note::
+ Some libintl implementations don't embed the version number in their header files.
+ In this case the variables ``Intl_VERSION*`` will be empty.
+
+.. note::
If you wish to use the Gettext tools (``msgmerge``,
``msgfmt``, etc.), use :module:`FindGettext`.
#]=======================================================================]
@@ -69,20 +121,43 @@ find_path(Intl_INCLUDE_DIR
mark_as_advanced(Intl_INCLUDE_DIR)
# Find all Intl libraries
-set(Intl_REQUIRED_VARS)
if(NOT Intl_IS_BUILTIN)
- find_library(Intl_LIBRARY "intl" "libintl" NAMES_PER_DIR
- DOC "libintl libraries (if not in the C library)")
- mark_as_advanced(Intl_LIBRARY)
- list(APPEND Intl_REQUIRED_VARS Intl_LIBRARY)
+ set(Intl_LIBRARY_NAMES "intl" "libintl")
+else()
+ set(Intl_LIBRARY_NAMES "c")
+endif()
+
+find_library(Intl_LIBRARY ${Intl_LIBRARY_NAMES} NAMES_PER_DIR
+ DOC "intl library (potentially the C library)")
+mark_as_advanced(Intl_LIBRARY)
+
+# NOTE: glibc's libintl.h does not define LIBINTL_VERSION
+if(Intl_INCLUDE_DIR AND NOT Intl_IS_BUILTIN)
+ file(STRINGS ${Intl_INCLUDE_DIR}/libintl.h Intl_VERSION_DEFINE REGEX "LIBINTL_VERSION (.*)")
+
+ if(Intl_VERSION_DEFINE MATCHES "(0x[A-Fa-f0-9]+)")
+ set(Intl_VERSION_NUMBER "${CMAKE_MATCH_1}")
+ # encoding -> version number: (major<<16) + (minor<<8) + patch
+ math(EXPR Intl_VERSION_MAJOR "${Intl_VERSION_NUMBER} >> 16" OUTPUT_FORMAT HEXADECIMAL)
+ math(EXPR Intl_VERSION_MINOR "(${Intl_VERSION_NUMBER} - (${Intl_VERSION_MAJOR} << 16)) >> 8" OUTPUT_FORMAT HEXADECIMAL)
+ math(EXPR Intl_VERSION_PATCH "${Intl_VERSION_NUMBER} - ((${Intl_VERSION_MAJOR} << 16) + (${Intl_VERSION_MINOR} << 8))" OUTPUT_FORMAT HEXADECIMAL)
+
+ math(EXPR Intl_VERSION_MAJOR "${Intl_VERSION_MAJOR}" OUTPUT_FORMAT DECIMAL)
+ math(EXPR Intl_VERSION_MINOR "${Intl_VERSION_MINOR}" OUTPUT_FORMAT DECIMAL)
+ math(EXPR Intl_VERSION_PATCH "${Intl_VERSION_PATCH}" OUTPUT_FORMAT DECIMAL)
+ set(Intl_VERSION "${Intl_VERSION_MAJOR}.${Intl_VERSION_MINOR}.${Intl_VERSION_PATCH}")
+ endif()
+
+ unset(Intl_VERSION_DEFINE)
+ unset(Intl_VERSION_NUMBER)
endif()
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Intl
FOUND_VAR Intl_FOUND
- REQUIRED_VARS Intl_INCLUDE_DIR ${Intl_REQUIRED_VARS}
+ REQUIRED_VARS Intl_LIBRARY Intl_INCLUDE_DIR
+ VERSION_VAR Intl_VERSION
FAIL_MESSAGE "Failed to find Gettext libintl")
-unset(Intl_REQUIRED_VARS)
if(Intl_FOUND)
set(Intl_INCLUDE_DIRS "${Intl_INCLUDE_DIR}")