1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-08-07 06:42:56 +03:00

Merge pull request #8851 from billatarm/mbedtls-2.28-add-pc-files

Mbedtls 2.28 add pc files
This commit is contained in:
Gilles Peskine
2024-03-12 11:30:30 +00:00
committed by GitHub
10 changed files with 105 additions and 3 deletions

View File

@@ -39,6 +39,8 @@ else()
project("Mbed TLS" C) project("Mbed TLS" C)
endif() endif()
include(GNUInstallDirs)
# Set the project root directory. # Set the project root directory.
set(MBEDTLS_DIR ${CMAKE_CURRENT_SOURCE_DIR}) set(MBEDTLS_DIR ${CMAKE_CURRENT_SOURCE_DIR})
@@ -259,8 +261,7 @@ if(CMAKE_BUILD_TYPE STREQUAL "Coverage")
endif(CMAKE_BUILD_TYPE STREQUAL "Coverage") endif(CMAKE_BUILD_TYPE STREQUAL "Coverage")
if(LIB_INSTALL_DIR) if(LIB_INSTALL_DIR)
else() set(CMAKE_INSTALL_LIBDIR "${LIB_INSTALL_DIR}")
set(LIB_INSTALL_DIR lib)
endif() endif()
if(ENABLE_ZLIB_SUPPORT) if(ENABLE_ZLIB_SUPPORT)
@@ -278,6 +279,8 @@ list(APPEND libs ${thirdparty_lib})
add_subdirectory(library) add_subdirectory(library)
add_subdirectory(pkgconfig)
# #
# The C files in tests/src directory contain test code shared among test suites # The C files in tests/src directory contain test code shared among test suites
# and programs. This shared test code is compiled and linked to test suites and # and programs. This shared test code is compiled and linked to test suites and

View File

@@ -0,0 +1,5 @@
Changes
* cmake: Use GnuInstallDirs to customize install directories
Replace custom LIB_INSTALL_DIR variable with standard CMAKE_INSTALL_LIBDIR
variable. For backward compatibility, set CMAKE_INSTALL_LIBDIR if
LIB_INSTALL_DIR is set.

View File

@@ -0,0 +1,3 @@
Features
* Add pc files for pkg-config. eg.:
pkg-config --cflags --libs (mbedtls|mbedcrypto|mbedx509)

View File

@@ -239,7 +239,7 @@ foreach(target IN LISTS target_libraries)
PUBLIC MBEDTLS_USER_CONFIG_FILE="${MBEDTLS_USER_CONFIG_FILE}") PUBLIC MBEDTLS_USER_CONFIG_FILE="${MBEDTLS_USER_CONFIG_FILE}")
endif() endif()
install(TARGETS ${target} install(TARGETS ${target}
DESTINATION ${LIB_INSTALL_DIR} DESTINATION ${CMAKE_INSTALL_LIBDIR}
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ) PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
endforeach(target) endforeach(target)

28
pkgconfig/CMakeLists.txt Normal file
View File

@@ -0,0 +1,28 @@
if(NOT DISABLE_PACKAGE_CONFIG_AND_INSTALL)
include(JoinPaths.cmake)
join_paths(PKGCONFIG_INCLUDEDIR "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
join_paths(PKGCONFIG_LIBDIR "\${prefix}" "${CMAKE_INSTALL_LIBDIR}")
#define these manually since minimum CMAKE version is not 3.9 for DESCRIPTION and 3.12 for HOMEPAGE_URL usage in project() below.
# Prefix with something that won't clash with newer versions of CMAKE.
set(PKGCONFIG_PROJECT_DESCRIPTION "Mbed TLS is a C library that implements cryptographic primitives, X.509 certificate manipulation and the SSL/TLS and DTLS protocols. Its small code footprint makes it suitable for embedded systems.")
set(PKGCONFIG_PROJECT_HOMEPAGE_URL "https://www.trustedfirmware.org/projects/mbed-tls/")
# Following the conventsion for DESCRIPTION and HOMEPAGE_URL, VERSION wasn't added until 3.0 and depends on policy CMP0048
set(PKGCONFIG_VERSION 2.28.7)
configure_file(mbedcrypto.pc.in mbedcrypto.pc @ONLY)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/mbedcrypto.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
configure_file(mbedtls.pc.in mbedtls.pc @ONLY)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/mbedtls.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
configure_file(mbedx509.pc.in mbedx509.pc @ONLY)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/mbedx509.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
endif()

27
pkgconfig/JoinPaths.cmake Normal file
View File

@@ -0,0 +1,27 @@
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
# This module provides function for joining paths
# known from most languages
#
# Copyright The Mbed TLS Contributors
#
# This script originates from:
# - https://github.com/jtojnar/cmake-snips
# Jan has provided re-licensing under Apache 2.0 and GPL 2.0+ and
# allowed for the change of Copyright.
#
# Modelled after Pythons os.path.join
# https://docs.python.org/3.7/library/os.path.html#os.path.join
# Windows not supported
function(join_paths joined_path first_path_segment)
set(temp_path "${first_path_segment}")
foreach(current_segment IN LISTS ARGN)
if(NOT ("${current_segment}" STREQUAL ""))
if(IS_ABSOLUTE "${current_segment}")
set(temp_path "${current_segment}")
else()
set(temp_path "${temp_path}/${current_segment}")
endif()
endif()
endforeach()
set(${joined_path} "${temp_path}" PARENT_SCOPE)
endfunction()

View File

@@ -0,0 +1,10 @@
prefix=@CMAKE_INSTALL_PREFIX@
includedir=@PKGCONFIG_INCLUDEDIR@
libdir=@PKGCONFIG_LIBDIR@
Name: @PROJECT_NAME@
Description: @PKGCONFIG_PROJECT_DESCRIPTION@
URL: @PKGCONFIG_PROJECT_HOMEPAGE_URL@
Version: @PKGCONFIG_VERSION@
Cflags: -I"${includedir}"
Libs: -L"${libdir}" -lmbedcrypto

11
pkgconfig/mbedtls.pc.in Normal file
View File

@@ -0,0 +1,11 @@
prefix=@CMAKE_INSTALL_PREFIX@
includedir=@PKGCONFIG_INCLUDEDIR@
libdir=@PKGCONFIG_LIBDIR@
Name: @PROJECT_NAME@
Description: @PKGCONFIG_PROJECT_DESCRIPTION@
URL: @PKGCONFIG_PROJECT_HOMEPAGE_URL@
Version: @PKGCONFIG_VERSION@
Requires.private: mbedcrypto mbedx509
Cflags: -I"${includedir}"
Libs: -L"${libdir}" -lmbedtls

11
pkgconfig/mbedx509.pc.in Normal file
View File

@@ -0,0 +1,11 @@
prefix=@CMAKE_INSTALL_PREFIX@
includedir=@PKGCONFIG_INCLUDEDIR@
libdir=@PKGCONFIG_LIBDIR@
Name: @PROJECT_NAME@
Description: @PKGCONFIG_PROJECT_DESCRIPTION@
URL: @PKGCONFIG_PROJECT_HOMEPAGE_URL@
Version: @PKGCONFIG_VERSION@
Requires.private: mbedcrypto
Cflags: -I"${includedir}"
Libs: -L"${libdir}" -lmbedx509

View File

@@ -67,6 +67,10 @@ then
exit 1 exit 1
fi fi
[ $VERBOSE ] && echo "Bumping PKGCONFIG_VERSION in pkgconfig/CMakeLists.txt"
sed -e "s/PKGCONFIG_VERSION [0-9.]\{1,\}/PKGCONFIG_VERSION $VERSION/g" < pkgconfig/CMakeLists.txt > tmp
mv tmp pkgconfig/CMakeLists.txt
[ $VERBOSE ] && echo "Bumping VERSION in library/CMakeLists.txt" [ $VERBOSE ] && echo "Bumping VERSION in library/CMakeLists.txt"
sed -e "s/ VERSION [0-9.]\{1,\}/ VERSION $VERSION/g" < library/CMakeLists.txt > tmp sed -e "s/ VERSION [0-9.]\{1,\}/ VERSION $VERSION/g" < library/CMakeLists.txt > tmp
mv tmp library/CMakeLists.txt mv tmp library/CMakeLists.txt