HowardHinnant / date

A date and time library based on the C++11/14/17 <chrono> header
Other
3.08k stars 669 forks source link

build: use standard `CMAKE_INSTALL_INCLUDEDIR` for header install folder #753

Open OlivierLDff opened 1 year ago

OlivierLDff commented 1 year ago

This gives user control over which folder header should be installed to instead of using hardcoded value include/. Variable CMAKE_INSTALL_INCLUDEDIR is provided after a call to include(GNUInstallDirs) More info can be found about usage in docs: https://cmake.org/cmake/help/latest/command/install.html

This PR basically replace all $<INSTALL_INTERFACE:include> with $<INSTALL_INTERFACE:include>.


It was already correctly used here: https://github.com/HowardHinnant/date/blob/22ceabf205d8d678710a43154da5a06b701c5830/CMakeLists.txt#L173 here: https://github.com/HowardHinnant/date/blob/22ceabf205d8d678710a43154da5a06b701c5830/CMakeLists.txt#L178 and here: https://github.com/HowardHinnant/date/blob/22ceabf205d8d678710a43154da5a06b701c5830/CMakeLists.txt#L184


This fix a bug if user provide -DCMAKE_INSTALL_INCLUDEDIR=customfolder, right now generated CMake/dateTargets.cmake output a file with:

set_target_properties(date::date PROPERTIES
  INTERFACE_COMPILE_DEFINITIONS "ONLY_C_LOCALE=0"
  INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include"
  INTERFACE_SOURCES "${_IMPORT_PREFIX}/include/date/date.h"
)

With this PR, generated file will be:

set_target_properties(date::date PROPERTIES
  INTERFACE_COMPILE_DEFINITIONS "ONLY_C_LOCALE=0"
  INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/customfolder"
  INTERFACE_SOURCES "${_IMPORT_PREFIX}/customfolder/date/date.h"
)