CMake: Generate and install liblzma.pc if not using MSVC.

Autotools based build uses -pthread and thus adds it to Libs.private
in liblzma.pc. CMake doesn't use -pthread at all if pthread functions
are available in libc so Libs.private doesn't get -pthread either.
This commit is contained in:
Lasse Collin 2023-09-30 02:14:25 +03:00 committed by Jia Tan
parent 983f3b458d
commit 989c8c354c
1 changed files with 21 additions and 0 deletions

View File

@ -113,6 +113,7 @@ if((MINGW OR CYGWIN OR MSYS) AND (
# Use workarounds with GNU windres and llvm-windres >= 17.0.0. The \x20 # Use workarounds with GNU windres and llvm-windres >= 17.0.0. The \x20
# in PACKAGE_NAME_DEFINITION works with gcc and clang too so we don't need # in PACKAGE_NAME_DEFINITION works with gcc and clang too so we don't need
# to worry how to pass different flags to windres and the C compiler. # to worry how to pass different flags to windres and the C compiler.
# Keep the original PACKAGE_NAME intact for generation of liblzma.pc.
string(APPEND CMAKE_RC_FLAGS " --use-temp-file") string(APPEND CMAKE_RC_FLAGS " --use-temp-file")
string(REPLACE " " "\\x20" PACKAGE_NAME_DEFINITION "${PACKAGE_NAME}") string(REPLACE " " "\\x20" PACKAGE_NAME_DEFINITION "${PACKAGE_NAME}")
else() else()
@ -154,6 +155,9 @@ tuklib_use_system_extensions(ALL)
# This is needed by liblzma and xz. # This is needed by liblzma and xz.
tuklib_integer(ALL) tuklib_integer(ALL)
# This is used for liblzma.pc generation to add -lrt if needed.
set(LIBS)
# Check for clock_gettime(). Do this before checking for threading so # Check for clock_gettime(). Do this before checking for threading so
# that we know there if CLOCK_MONOTONIC is available. # that we know there if CLOCK_MONOTONIC is available.
if(NOT WIN32) if(NOT WIN32)
@ -170,6 +174,7 @@ if(NOT WIN32)
# CMAKE_REQUIRED_LIBRARIES for further tests too. # CMAKE_REQUIRED_LIBRARIES for further tests too.
if(HAVE_CLOCK_GETTIME_LIBRT) if(HAVE_CLOCK_GETTIME_LIBRT)
link_libraries(rt) link_libraries(rt)
set(LIBS "-lrt") # For liblzma.pc
else() else()
list(REMOVE_AT CMAKE_REQUIRED_LIBRARIES 0) list(REMOVE_AT CMAKE_REQUIRED_LIBRARIES 0)
endif() endif()
@ -968,6 +973,16 @@ file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/liblzma-config.cmake"
# Set CMAKE_INSTALL_LIBDIR and friends. # Set CMAKE_INSTALL_LIBDIR and friends.
include(GNUInstallDirs) include(GNUInstallDirs)
# Create liblzma.pc.
set(prefix "${CMAKE_INSTALL_PREFIX}")
set(exec_prefix "${CMAKE_INSTALL_PREFIX}")
set(libdir "${CMAKE_INSTALL_FULL_LIBDIR}")
set(includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}")
set(PTHREAD_CFLAGS "${CMAKE_THREAD_LIBS_INIT}")
configure_file(src/liblzma/liblzma.pc.in liblzma.pc
@ONLY
NEWLINE_STYLE LF)
# Install the library binary. The INCLUDES specifies the include path that # Install the library binary. The INCLUDES specifies the include path that
# is exported for other projects to use but it doesn't install any files. # is exported for other projects to use but it doesn't install any files.
install(TARGETS liblzma EXPORT liblzmaTargets install(TARGETS liblzma EXPORT liblzmaTargets
@ -1003,6 +1018,12 @@ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/liblzma-config.cmake"
DESTINATION "${liblzma_INSTALL_CMAKEDIR}" DESTINATION "${liblzma_INSTALL_CMAKEDIR}"
COMPONENT liblzma_Development) COMPONENT liblzma_Development)
if(NOT MSVC)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/liblzma.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
COMPONENT liblzma_Development)
endif()
############################################################################# #############################################################################
# getopt_long # getopt_long