]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
CMake: Generate and install liblzma.pc if not using MSVC.
authorLasse Collin <lasse.collin@tukaani.org>
Fri, 29 Sep 2023 23:14:25 +0000 (02:14 +0300)
committerLasse Collin <lasse.collin@tukaani.org>
Thu, 26 Oct 2023 18:46:06 +0000 (21:46 +0300)
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.

CMakeLists.txt

index ad63d8494f89e33925c10ac10db8f3a8bd437da6..0437d7fb3bcc08cd2dc214f90acf53687163c340 100644 (file)
@@ -111,6 +111,7 @@ if((MINGW OR CYGWIN OR MSYS) AND (
     # 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
     # 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(REPLACE " " "\\x20" PACKAGE_NAME_DEFINITION "${PACKAGE_NAME}")
 else()
@@ -152,6 +153,9 @@ tuklib_use_system_extensions(ALL)
 # This is needed by liblzma and xz.
 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
 # that we know there if CLOCK_MONOTONIC is available.
 check_symbol_exists(clock_gettime time.h HAVE_CLOCK_GETTIME)
@@ -167,6 +171,7 @@ if(NOT HAVE_CLOCK_GETTIME)
     # CMAKE_REQUIRED_LIBRARIES for further tests too.
     if(HAVE_CLOCK_GETTIME_LIBRT)
         link_libraries(rt)
+        set(LIBS "-lrt") # For liblzma.pc
     else()
         list(REMOVE_AT CMAKE_REQUIRED_LIBRARIES 0)
     endif()
@@ -1004,6 +1009,16 @@ file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/liblzma-config.cmake"
 # Set CMAKE_INSTALL_LIBDIR and friends.
 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
 # is exported for other projects to use but it doesn't install any files.
 install(TARGETS liblzma EXPORT liblzmaTargets
@@ -1039,6 +1054,12 @@ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/liblzma-config.cmake"
         DESTINATION "${liblzma_INSTALL_CMAKEDIR}"
         COMPONENT liblzma_Development)
 
+if(NOT MSVC)
+    install(FILES "${CMAKE_CURRENT_BINARY_DIR}/liblzma.pc"
+            DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
+            COMPONENT liblzma_Development)
+endif()
+
 
 #############################################################################
 # libgnu (getopt_long)