[CMake] generate pkg-config flatbuffers.pc file (#6455)
authorMillian Poquet <millian.poquet@gmail.com>
Mon, 22 Feb 2021 18:23:38 +0000 (19:23 +0100)
committerGitHub <noreply@github.com>
Mon, 22 Feb 2021 18:23:38 +0000 (10:23 -0800)
This commit enables CMake to generate a flatbuffers.pc file on install.

pkg-config eases the utilization of software libraries by enabling the
developers of a library to define how the library should be used.

It can be used as a tool by build systems to find and manage dependencies,
this is notably the default Meson behavior and optionally used by CMake.

CMake/flatbuffers.pc.in [new file with mode: 0644]
CMakeLists.txt

diff --git a/CMake/flatbuffers.pc.in b/CMake/flatbuffers.pc.in
new file mode 100644 (file)
index 0000000..110770a
--- /dev/null
@@ -0,0 +1,9 @@
+libdir=@CMAKE_INSTALL_FULL_LIBDIR@
+includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
+
+Name: FlatBuffers
+Description: Memory Efficient Serialization Library
+Version: @VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@
+
+Libs: -L${libdir} -lflatbuffers
+Cflags: -I${includedir}
index a7c0b0a..f56f844 100644 (file)
@@ -629,6 +629,14 @@ if(FLATBUFFERS_INSTALL)
       DESTINATION ${FB_CMAKE_DIR}
     )
   endif()
+
+  if(FLATBUFFERS_BUILD_SHAREDLIB OR FLATBUFFERS_BUILD_FLATLIB)
+      configure_file(CMake/flatbuffers.pc.in flatbuffers.pc @ONLY)
+      install(
+        FILES "${CMAKE_CURRENT_BINARY_DIR}/flatbuffers.pc"
+        DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
+      )
+  endif()
 endif()
 
 if(FLATBUFFERS_BUILD_TESTS)