Improvements in install target generated by CMake

There are two changes in this patch but they are related because they
both improve install target generated by CMake.

1) GNUInstallDirs is now used to determine name of the folders where
libraries and headers are installed. On RedHat based Linux
distributions, usual folder for x86-64 libraries is lib64 and not just
simply lib. GNUInstallDirs takes care of deciding which name to use.

2) Pkgconfig file was not installed when CMake was used. Adding pc file
to the installation process of CMake install target allows package
maintainers to easily provide packages which work both with pkgconfig
and CMake.

Fixes #215.

Change-Id: Icc9636039e5456df78323b7ae1b89e0d27be7fbf
Reviewed-on: https://code-review.googlesource.com/c/re2/+/43990
Reviewed-by: Paul Wankadia <junyer@google.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 976c3da..768371c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,6 +11,7 @@
 
 project(RE2 CXX)
 include(CTest)
+include(GNUInstallDirs)
 
 option(BUILD_SHARED_LIBS "build shared libraries" OFF)
 option(USEPCRE "use PCRE in tests and benchmarks" OFF)
@@ -146,6 +147,18 @@
     re2/stringpiece.h
     )
 
-install(FILES ${RE2_HEADERS} DESTINATION include/re2)
-install(TARGETS re2 EXPORT re2Config ARCHIVE DESTINATION lib LIBRARY DESTINATION lib RUNTIME DESTINATION bin INCLUDES DESTINATION include)
-install(EXPORT re2Config DESTINATION lib/cmake/re2 NAMESPACE re2::)
+set(includedir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR})
+set(libdir     ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/re2.pc ${CMAKE_CURRENT_BINARY_DIR}/re2.pc @ONLY)
+
+install(FILES ${RE2_HEADERS}
+        DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/re2)
+install(TARGETS re2 EXPORT re2Config
+        ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+        RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+        INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
+install(EXPORT re2Config
+        DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/re2 NAMESPACE re2::)
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/re2.pc
+        DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)