Commit ba74457fb46aa4def2978b713eb0ea0f182ff6f0

czurnieden 2022-03-02T22:28:49

Build and install libtommath.pc

diff --git a/CMakeLists.txt b/CMakeLists.txt
index d74e866..474ae69 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -171,6 +171,19 @@ install(FILES ${HEADERS}
     DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
 )
 
+# Install libtommath.pc for pkg-config if we build a shared library
+if(BUILD_SHARED_LIBS)
+    configure_file(
+        ${CMAKE_CURRENT_SOURCE_DIR}/lib${PROJECT_NAME}.pc.in
+        ${CMAKE_CURRENT_BINARY_DIR}/lib${PROJECT_NAME}.pc
+        @ONLY
+    )
+
+    install(FILES ${CMAKE_CURRENT_BINARY_DIR}/lib${PROJECT_NAME}.pc
+        DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig
+    )
+endif()
+
 # generate package version file
 write_basic_package_version_file(
     ${PROJECT_VERSION_FILE}
diff --git a/libtommath.pc.in b/libtommath.pc.in
index 099b1cd..ad8f5c3 100644
--- a/libtommath.pc.in
+++ b/libtommath.pc.in
@@ -1,10 +1,9 @@
-prefix=@to-be-replaced@
-exec_prefix=${prefix}
-libdir=${exec_prefix}/lib
-includedir=${prefix}/include
+prefix=@CMAKE_INSTALL_PREFIX@
+libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
+includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/@PROJECT_NAME@
 
 Name: LibTomMath
 Description: public domain library for manipulating large integer numbers
-Version: @to-be-replaced@
+Version: @PROJECT_VERSION@
 Libs: -L${libdir} -ltommath
 Cflags: -I${includedir}