Description: install a convenience GNAT project for the Ada binding
 It is more and more common to build Ada sources with gprbuild.
Author: Nicolas Boulenguez <nicolas@debian.org>
Forwarded: https://sourceforge.net/p/plplot/mailman/message/37743447/
Reviewed-By: Rafael Laboissière <rafael@debian.org>
Last-Update: 2022-11-30

--- a/bindings/ada/CMakeLists.txt
+++ b/bindings/ada/CMakeLists.txt
@@ -144,4 +144,9 @@
   # See remarks above concerning why plplot has to be public.
   pkg_config_file("ada" "Ada" " Ada binding" "plplotada" "" "${GNAT_LIB}" "-lplplot")
 
+  configure_file(${CMAKE_CURRENT_SOURCE_DIR}/plplotada.gpr.in
+                 ${CMAKE_CURRENT_BINARY_DIR}/plplotada.gpr)
+  install(FILES       ${CMAKE_CURRENT_BINARY_DIR}/plplotada.gpr
+          DESTINATION ${GNAT_PROJECT_DIR})
+
 endif(ENABLE_ada)
--- /dev/null
+++ b/bindings/ada/plplotada.gpr.in
@@ -0,0 +1,11 @@
+library project Plplotada is
+   for Library_Name use "plplotada";
+   for Library_Kind use "dynamic";
+   for Source_Dirs use ("/@ADA_INCLUDE_DIR@");
+   for Library_Ali_Dir use "/@ADA_LIB_DIR@";
+   for Library_Dir use "/@CMAKE_INSTALL_LIBDIR@";
+   for Externally_Built use "true";
+   package Linker is
+     for Linker_Options use ("-lplplot");
+   end Linker;
+end Plplotada;
--- a/cmake/modules/ada.cmake
+++ b/cmake/modules/ada.cmake
@@ -65,6 +65,16 @@
     )
   list(APPEND INSTALL_LOCATION_VARIABLES_LIST ADA_LIB_DIR)
 
+  # This default is one of the default gnat search paths, but not the
+  # most common one (DATADIR/gpr) because we expect the project to
+  # contain architecture-specific contents, namely ADA_LIB_DIR.
+  set(
+    GNAT_PROJECT_DIR
+    ${CMAKE_INSTALL_LIBDIR}/gnat
+    CACHE PATH "PLplot install location for GNAT projects (*.gpr)"
+    )
+  list(APPEND INSTALL_LOCATION_VARIABLES_LIST GNAT_PROJECT_DIR)
+
   # Find the gnat version used in order to search for the right version of libgnat
   execute_process(COMMAND ${CMAKE_Ada_COMPILER} --version OUTPUT_VARIABLE ADA_OUTPUT)
   string(REGEX MATCH "gcc.* [(][^)]*[)] ([0-9]*)([.][0-9]*)[.][0-9]" ADA_OUTPUT_TRIM ${ADA_OUTPUT})
