From bf64f1248765470b023d49e311cdcfc4b7b4fc7a Mon Sep 17 00:00:00 2001
From: Antonio Ospite <ao2@ao2.it>
Date: Fri, 2 Mar 2018 13:40:48 +0100
Subject: [PATCH] CMakeLists.txt: use GNUInstallDirs
X-Face: z*RaLf`X<@C75u6Ig9}{oW$H;1_\2t5)({*|jhM<pyWR#k60!#=#>/Vb;]yA5<GWI5`6u&+
 ;6b'@y|8w"wB;4/e!7wYYrcqdJFY,~%Gk_4]cq$Ei/7<j&N3ah(m`ku?pX.&+~:_/wC~dwn^)MizBG
 !pE^+iDQQ1yC6^,)YDKkxDd!T>\I~93>J<_`<4)A{':UrE

This fixes installation in multi-arch paths on systems which supports that.
---
 CMakeLists.txt          | 2 ++
 doc/CMakeLists.txt      | 2 +-
 doc/man/CMakeLists.txt  | 2 +-
 examples/CMakeLists.txt | 6 +++---
 src/CMakeLists.txt      | 8 ++++----
 src/libam7xxx.pc.in     | 6 ++----
 6 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 73657f8..f234866 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,6 +1,8 @@
 cmake_minimum_required(VERSION 2.6)
 project(libam7xxx C)
 
+include (GNUInstallDirs)
+
 set(PROJECT_DESCRIPTION
   "Communication library for Actions Micro AM7XXX based USB projectors and DPFs")
 
diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt
index 6ccf100..0335a2e 100644
--- a/doc/CMakeLists.txt
+++ b/doc/CMakeLists.txt
@@ -17,7 +17,7 @@ if(DOXYGEN_FOUND)
   install(CODE "execute_process(COMMAND ${CMAKE_BUILD_TOOL} doc)")
 
   install(DIRECTORY ${DOC_OUTPUT_PATH}/html
-    DESTINATION "${CMAKE_INSTALL_PREFIX}/share/doc/${CMAKE_PROJECT_NAME}"
+    DESTINATION ${CMAKE_INSTALL_DOCDIR}
     COMPONENT doc)
 
 endif(DOXYGEN_FOUND)
diff --git a/doc/man/CMakeLists.txt b/doc/man/CMakeLists.txt
index c7ce4bb..f97b1cb 100644
--- a/doc/man/CMakeLists.txt
+++ b/doc/man/CMakeLists.txt
@@ -20,7 +20,7 @@ if(ASCIIDOC_FOUND)
     ${DOC_OUTPUT_PATH}/man/am7xxx-play.1
     ${DOC_OUTPUT_PATH}/man/am7xxx-modeswitch.1
     ${DOC_OUTPUT_PATH}/man/picoproj.1
-    DESTINATION "${CMAKE_INSTALL_PREFIX}/share/man/man1/"
+    DESTINATION "${CMAKE_INSTALL_MANDIR}/man1/"
     COMPONENT manpages)
 
 endif(ASCIIDOC_FOUND)
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index d44a26f..f624ba5 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -9,7 +9,7 @@ if(BUILD_PICOPROJ)
   add_executable(picoproj picoproj.c)
   target_link_libraries(picoproj am7xxx)
   install(TARGETS picoproj
-    DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
+    DESTINATION ${CMAKE_INSTALL_BINDIR})
 endif()
 
 # Build a more complete example
@@ -58,7 +58,7 @@ if(BUILD_AM7XXX-PLAY)
     ${FFMPEG_LIBSWSCALE_LIBRARIES}
     ${OPTIONAL_LIBRARIES})
   install(TARGETS am7xxx-play
-    DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
+    DESTINATION ${CMAKE_INSTALL_BINDIR})
 endif()
 
 # Build a simple usb-modeswitch clone for am7xxx devices
@@ -71,6 +71,6 @@ if(BUILD_am7xxx-modeswitch)
   add_executable(am7xxx-modeswitch am7xxx-modeswitch.c)
   target_link_libraries(am7xxx-modeswitch ${LIBUSB_1_LIBRARIES})
   install(TARGETS am7xxx-modeswitch
-    DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
+    DESTINATION ${CMAKE_INSTALL_BINDIR})
 endif()
 
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index d6cdaad..9422436 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -17,7 +17,7 @@ set_target_properties(am7xxx PROPERTIES
   VERSION ${PROJECT_VER}
   SOVERSION ${PROJECT_APIVER})
 install(TARGETS am7xxx
-  DESTINATION "${CMAKE_INSTALL_PREFIX}/lib")
+  DESTINATION "${CMAKE_INSTALL_LIBDIR}")
 
 add_library(am7xxx-static STATIC ${SRC})
 set_target_properties(am7xxx-static PROPERTIES OUTPUT_NAME am7xxx)
@@ -25,7 +25,7 @@ if(UNIX AND NOT APPLE)
   set_target_properties(am7xxx-static PROPERTIES COMPILE_FLAGS "-fPIC")
 endif()
 install(TARGETS am7xxx-static
-   DESTINATION "${CMAKE_INSTALL_PREFIX}/lib")
+  DESTINATION "${CMAKE_INSTALL_LIBDIR}")
 
 if(NOT WIN32)
   find_library(MATH_LIB m)
@@ -39,11 +39,11 @@ target_link_libraries(am7xxx-static ${MATH_LIB} ${LIBUSB_1_LIBRARIES})
 
 # Install the header files
 install(FILES "am7xxx.h"
-  DESTINATION "${CMAKE_INSTALL_PREFIX}/include")
+  DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
 
 if(UNIX AND NOT APPLE)
   # Produce a pkg-config file for linking against the shared lib
   configure_file("libam7xxx.pc.in" "libam7xxx.pc" @ONLY)
   install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libam7xxx.pc"
-    DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig")
+    DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
 endif()
diff --git a/src/libam7xxx.pc.in b/src/libam7xxx.pc.in
index dff65c6..a596abc 100644
--- a/src/libam7xxx.pc.in
+++ b/src/libam7xxx.pc.in
@@ -1,7 +1,5 @@
-prefix=@CMAKE_INSTALL_PREFIX@
-exec_prefix=${prefix}
-libdir=${exec_prefix}/lib
-includedir=${prefix}/include
+libdir=@CMAKE_INSTALL_FULL_LIBDIR@
+includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
 
 Name: @PROJECT_NAME@
 Description: @PROJECT_DESCRIPTION@
-- 
2.16.2

