Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use GNUInstallDirs for cmake install locations #3150

Merged
merged 9 commits into from
Apr 7, 2022
18 changes: 4 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -286,18 +286,8 @@ link_directories(${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
# Installation
################################################################################
include(ProjInstallPath)
set(BINDIR "${DEFAULT_BINDIR}"
CACHE PATH "The directory to install binaries into.")
set(LIBDIR "${DEFAULT_LIBDIR}"
CACHE PATH "The directory to install libraries into.")
set(DATADIR "${DEFAULT_DATADIR}"
CACHE PATH "The directory to install data files into.")
set(DOCDIR "${DEFAULT_DOCDIR}"
CACHE PATH "The directory to install doc files into.")
set(INCLUDEDIR "${DEFAULT_INCLUDEDIR}"
CACHE PATH "The directory to install includes into.")
set(CMAKECONFIGDIR "${DEFAULT_CMAKEDIR}"
CACHE PATH "Parent of the directory to install cmake config files into.")
include(GNUInstallDirs)
set(PROJ_LIB_PATH "${CMAKE_INSTALL_FULL_DATADIR}/proj")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe that's not the best name for data.


################################################################################
# Tests
Expand Down Expand Up @@ -326,7 +316,7 @@ endif()

set(docfiles COPYING NEWS AUTHORS)
install(FILES ${docfiles}
DESTINATION "${DOCDIR}")
DESTINATION ${CMAKE_INSTALL_DOCDIR})

################################################################################
# pkg-config support
Expand All @@ -335,7 +325,7 @@ configure_proj_pc()

install(FILES
${CMAKE_CURRENT_BINARY_DIR}/proj.pc
DESTINATION ${LIBDIR}/pkgconfig)
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")

################################################################################
# "make dist" workalike
Expand Down
5 changes: 1 addition & 4 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ string (TOLOWER "${PROJECT_LEGACY_NAME}" PROJECT_LEGACY_LOWER)
#
# At some more distant date, the PROJ4::proj target will be retired.
#
# To support this change, the CACHE variables PROJ_CMAKE_SUBDIR (and
# CMAKECONFIGDIR) is now the "Parent of directory to install cmake
# config files into".
#
# All this messiness is confined to
#
Expand Down Expand Up @@ -95,7 +92,7 @@ endif ()

foreach (PROJECT_VARIANT_NAME ${PROJECT_NAME} ${PROJECT_LEGACY_NAME})
string (TOLOWER "${PROJECT_VARIANT_NAME}" PROJECT_VARIANT_LOWER)
set (CMAKECONFIGSUBDIR "${CMAKECONFIGDIR}/${PROJECT_VARIANT_LOWER}")
set (CMAKECONFIGSUBDIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_VARIANT_LOWER}")
# proj-config.cmake for the install tree. It's installed in
# ${CMAKECONFIGSUBDIR} and @PROJECT_ROOT_DIR@ is the relative
# path to the root from there. (Note that the whole install tree can
Expand Down
55 changes: 0 additions & 55 deletions cmake/ProjInstallPath.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,58 +21,3 @@ endif()

#TODO
# for data install testing the PROJ_LIB envVar

string(TOLOWER "${PROJECT_NAME}" PROJECT_NAME_LOWER)
if(UNIX OR MINGW)
include(GNUInstallDirs)
set(DEFAULT_BIN_SUBDIR ${CMAKE_INSTALL_BINDIR})
set(DEFAULT_LIB_SUBDIR ${CMAKE_INSTALL_LIBDIR})
set(DEFAULT_DATA_SUBDIR ${CMAKE_INSTALL_DATAROOTDIR}/proj)
set(DEFAULT_INCLUDE_SUBDIR ${CMAKE_INSTALL_INCLUDEDIR})
set(DEFAULT_DOC_SUBDIR share/doc/${PROJECT_NAME_LOWER})
set(DEFAULT_CMAKE_SUBDIR ${CMAKE_INSTALL_LIBDIR}/cmake)
else()
# Common locations for Unix and Mac OS X
set(DEFAULT_BIN_SUBDIR bin)
set(DEFAULT_LIB_SUBDIR lib)
set(DEFAULT_DATA_SUBDIR share/proj)
set(DEFAULT_DOC_SUBDIR doc/proj)
set(DEFAULT_INCLUDE_SUBDIR include)
set(DEFAULT_DOC_SUBDIR share/doc/proj)
set(DEFAULT_CMAKE_SUBDIR lib/cmake)
# Used for proj.pc
set(CMAKE_INSTALL_DATAROOTDIR share)
endif()

# Locations are changeable by user to customize layout of PROJ installation
# (default values are platform-specific)
set(PROJ_BIN_SUBDIR ${DEFAULT_BIN_SUBDIR} CACHE STRING
"Subdirectory where executables will be installed")
set(PROJ_LIB_SUBDIR ${DEFAULT_LIB_SUBDIR} CACHE STRING
"Subdirectory where libraries will be installed")
set(PROJ_INCLUDE_SUBDIR ${DEFAULT_INCLUDE_SUBDIR} CACHE STRING
"Subdirectory where header files will be installed")
set(PROJ_DATA_SUBDIR ${DEFAULT_DATA_SUBDIR} CACHE STRING
"Subdirectory where data will be installed")
set(PROJ_DOC_SUBDIR ${DEFAULT_DOC_SUBDIR} CACHE STRING
"Subdirectory where doc will be installed")
set(PROJ_CMAKE_SUBDIR ${DEFAULT_CMAKE_SUBDIR} CACHE STRING
"Parent of subdirectory where cmake proj-config file will be installed")

# Mark *DIR variables as advanced and dedicated to use by power-users only.
mark_as_advanced(
PROJ_ROOT_DIR
PROJ_BIN_SUBDIR
PROJ_LIB_SUBDIR
PROJ_INCLUDE_SUBDIR
PROJ_DATA_SUBDIR
PROJ_DOC_SUBDIR
PROJ_CMAKE_SUBDIR
)

set(DEFAULT_BINDIR "${PROJ_BIN_SUBDIR}")
set(DEFAULT_LIBDIR "${PROJ_LIB_SUBDIR}")
set(DEFAULT_DATADIR "${PROJ_DATA_SUBDIR}")
set(DEFAULT_DOCDIR "${PROJ_DOC_SUBDIR}")
set(DEFAULT_INCLUDEDIR "${PROJ_INCLUDE_SUBDIR}")
set(DEFAULT_CMAKEDIR "${PROJ_CMAKE_SUBDIR}")
4 changes: 3 additions & 1 deletion cmake/ProjMac.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ if(APPLE)
option(BUILD_FRAMEWORKS_AND_BUNDLE
"if set to ON, build a library framework and application bundle, \
otherwise install classical UNIX bin/lib" OFF)
set(DEFAULT_BINDIR ${BUNDLEDIR})
if(BUILD_FRAMEWORKS_AND_BUNDLE)
set(CMAKE_INSTALL_BINDIR ${BUNDLEDIR})
endif()
print_variable(BUNDLEDIR)
print_variable(PROJ_INSTALL_NAME_DIR)
print_variable(FRAMEWORKDIR)
Expand Down
7 changes: 3 additions & 4 deletions cmake/ProjUtilities.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,9 @@ endfunction()
#

function(configure_proj_pc)
set(prefix "${CMAKE_INSTALL_PREFIX}")
set(exec_prefix "$\{prefix\}")
set(libdir "$\{exec_prefix\}/${PROJ_LIB_SUBDIR}")
set(includedir "$\{prefix\}/${PROJ_INCLUDE_SUBDIR}")
set(prefix ${CMAKE_INSTALL_PREFIX})
set(libdir "$\{prefix\}/${CMAKE_INSTALL_LIBDIR}")
set(includedir "$\{prefix\}/${CMAKE_INSTALL_INCLUDEDIR}")
set(datarootdir "$\{prefix\}/${CMAKE_INSTALL_DATAROOTDIR}")
set(datadir "$\{datarootdir\}")
set(PACKAGE "proj")
Expand Down
6 changes: 3 additions & 3 deletions cmake/project-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
# Tell the user project where to find our headers and libraries
get_filename_component (_DIR ${CMAKE_CURRENT_LIST_FILE} PATH)
get_filename_component (_ROOT "${_DIR}/@PROJECT_ROOT_DIR@" ABSOLUTE)
set (@PROJECT_VARIANT_NAME@_INCLUDE_DIRS "${_ROOT}/@INCLUDEDIR@")
set (@PROJECT_VARIANT_NAME@_LIBRARY_DIRS "${_ROOT}/@LIBDIR@")
set (@PROJECT_VARIANT_NAME@_BINARY_DIRS "${_ROOT}/@BINDIR@")
set (@PROJECT_VARIANT_NAME@_INCLUDE_DIRS ${CMAKE_INSTALL_INCLUDEDIR})
set (@PROJECT_VARIANT_NAME@_LIBRARY_DIRS ${CMAKE_INSTALL_LIBDIR})
set (@PROJECT_VARIANT_NAME@_BINARY_DIRS ${CMAKE_INSTALL_BINDIR})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this should rather be:

Suggested change
set (@PROJECT_VARIANT_NAME@_INCLUDE_DIRS ${CMAKE_INSTALL_INCLUDEDIR})
set (@PROJECT_VARIANT_NAME@_LIBRARY_DIRS ${CMAKE_INSTALL_LIBDIR})
set (@PROJECT_VARIANT_NAME@_BINARY_DIRS ${CMAKE_INSTALL_BINDIR})
set (@PROJECT_VARIANT_NAME@_INCLUDE_DIRS "${_ROOT}/@CMAKE_INSTALL_INCLUDEDIR@")
set (@PROJECT_VARIANT_NAME@_LIBRARY_DIRS "${_ROOT}/@CMAKE_INSTALL_LIBDIR@")
set (@PROJECT_VARIANT_NAME@_BINARY_DIRS "${_ROOT}/@CMAKE_INSTALL_BINDIR@")

as _ROOT must remain referenced

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CMAKE_INSTALL_<dir> are relative paths, meant to be used with install( ... DESTINATION ...).

For absolute paths, there is CMAKE_INSTALL_FULL_<dir>. This takes into account CMAKE_INSTALL_PREFIX (but breaks CMAKE_STAGING_PREFIX).

Now what is _ROOT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which do we think it should be? I think it is wrong the way it is, too.

If these variables should be the include, library, and binary directories of install, then the FULL variables from GNUInstallDirs will do fine as @dg0yt says I think

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now what is _ROOT?

As far as I can see, this is a way to figure out the (actual) installation prefix from where the CMake config file is located.

If these variables should be the include, library, and binary directories of install, then the FULL variables from GNUInstallDirs will do fine

yeah that was my first thought too. But it seems the existing logic in the file was to make it possibly relocatable. And I hope that what I proposed would make it still possible

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I missed part of the context. Basically @rouault is right, and I see where _ROOT comes from now.

I will test the PR in the next days.


set (@PROJECT_VARIANT_NAME@_LIBRARIES @PROJECT_VARIANT_NAME@::proj)
# Read in the exported definition of the library
Expand Down
2 changes: 1 addition & 1 deletion data/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,5 @@ set(ALL_DATA_FILE
)
install(
FILES ${ALL_DATA_FILE}
DESTINATION ${DATADIR}
DESTINATION ${PROJ_LIB_PATH}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... but this looks strange.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's after PROJ_LIB

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The naming isn't straightforward. In the context of cmake, this implies the library install path I think, though we know what PROJ_LIB means outside of cmake (the link above was what I was thinking of when I named it). What's the best name for this? DATADIR isn't too clear either

)
2 changes: 1 addition & 1 deletion include/proj/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set(installdest ${INCLUDEDIR}/proj)
set(installdest ${CMAKE_INSTALL_INCLUDEDIR}/proj)
mwtoews marked this conversation as resolved.
Show resolved Hide resolved

install(
FILES util.hpp metadata.hpp common.hpp crs.hpp datum.hpp
Expand Down
1 change: 0 additions & 1 deletion proj.pc.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
datarootdir=@datarootdir@
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ add_subdirectory(tests)

if(APPLE)
# Directory name for installed targets
set(CMAKE_INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/${LIBDIR}")
set(CMAKE_INSTALL_NAME_DIR ${CMAKE_INSTALL_LIBDIR})
mwtoews marked this conversation as resolved.
Show resolved Hide resolved
endif()
4 changes: 2 additions & 2 deletions src/apps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ if(NOT MSVC)

# Use relative path so that package is relocatable
if(APPLE)
set(CMAKE_INSTALL_RPATH "@loader_path/../${LIBDIR}")
set(CMAKE_INSTALL_RPATH "@loader_path/../${CMAKE_INSTALL_LIBDIR}")
else()
set(CMAKE_INSTALL_RPATH "\$ORIGIN/../${LIBDIR}")
set(CMAKE_INSTALL_RPATH "\$ORIGIN/../${CMAKE_INSTALL_LIBDIR}")
endif()
# Other apps can link to libproj using e.g. LDFLAGS -Wl,-rpath,${prefix}/lib

Expand Down
2 changes: 1 addition & 1 deletion src/apps/bin_cct.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ add_executable(cct ${CCT_SRC} ${CCT_INCLUDE})
target_link_libraries(cct PRIVATE ${PROJ_LIBRARIES})

install(TARGETS cct
DESTINATION ${BINDIR})
DESTINATION ${CMAKE_INSTALL_BINDIR})
2 changes: 1 addition & 1 deletion src/apps/bin_cs2cs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ add_executable(cs2cs ${CS2CS_SRC} ${CS2CS_INCLUDE})
target_link_libraries(cs2cs PRIVATE ${PROJ_LIBRARIES})

install(TARGETS cs2cs
DESTINATION ${BINDIR})
DESTINATION ${CMAKE_INSTALL_BINDIR})
6 changes: 3 additions & 3 deletions src/apps/bin_geod.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ add_executable(geod ${GEOD_SRC} ${GEOD_INCLUDE})
target_link_libraries(geod PRIVATE ${PROJ_LIBRARIES})

install(TARGETS geod
DESTINATION ${BINDIR})
DESTINATION ${CMAKE_INSTALL_BINDIR})

# invgeod target: symlink or copy of geod executable

Expand All @@ -32,14 +32,14 @@ if(UNIX)

add_custom_target(invgeod ALL DEPENDS ${link_target})

install(FILES ${link_target} DESTINATION ${BINDIR})
install(FILES ${link_target} DESTINATION ${CMAKE_INSTALL_BINDIR})

else()

add_executable(invgeod ${GEOD_SRC} ${GEOD_INCLUDE})
target_link_libraries(invgeod PRIVATE ${PROJ_LIBRARIES})

install(TARGETS invgeod
DESTINATION ${BINDIR})
DESTINATION ${CMAKE_INSTALL_BINDIR})

endif()
2 changes: 1 addition & 1 deletion src/apps/bin_gie.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ target_link_libraries(gie PRIVATE ${PROJ_LIBRARIES})

if(BUILD_GIE)
install(TARGETS gie
DESTINATION ${BINDIR})
DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
6 changes: 3 additions & 3 deletions src/apps/bin_proj.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ set_target_properties(binproj
target_link_libraries(binproj PRIVATE ${PROJ_LIBRARIES})

install(TARGETS binproj
DESTINATION ${BINDIR})
DESTINATION ${CMAKE_INSTALL_BINDIR})

# invproj target: symlink or copy of proj executable

Expand All @@ -33,14 +33,14 @@ if(UNIX)

add_custom_target(invproj ALL DEPENDS ${link_target})

install(FILES ${link_target} DESTINATION ${BINDIR})
install(FILES ${link_target} DESTINATION ${CMAKE_INSTALL_BINDIR})

else()

add_executable(invproj ${PROJ_SRC})
target_link_libraries(invproj PRIVATE ${PROJ_LIBRARIES})

install(TARGETS invproj
DESTINATION ${BINDIR})
DESTINATION ${CMAKE_INSTALL_BINDIR})

endif()
2 changes: 1 addition & 1 deletion src/apps/bin_projinfo.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ add_executable(projinfo ${PROJINFO_SRC})
target_link_libraries(projinfo PRIVATE ${PROJ_LIBRARIES})

install(TARGETS projinfo
DESTINATION ${BINDIR})
DESTINATION ${CMAKE_INSTALL_BINDIR})

if(CURL_ENABLED)
target_compile_definitions(projinfo PRIVATE -DCURL_ENABLED)
Expand Down
2 changes: 1 addition & 1 deletion src/apps/bin_projsync.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ add_executable(projsync ${PROJSYNC_SRC})
target_link_libraries(projsync PRIVATE ${PROJ_LIBRARIES})

install(TARGETS projsync
DESTINATION ${BINDIR})
DESTINATION ${CMAKE_INSTALL_BINDIR})
12 changes: 6 additions & 6 deletions src/lib_proj.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR})
source_group("CMake Files" FILES CMakeLists.txt)

# Embed PROJ_LIB data files location
add_definitions(-DPROJ_LIB="${CMAKE_INSTALL_PREFIX}/${DATADIR}")
add_definitions(-DPROJ_LIB="${PROJ_LIB_PATH}")


###########################################################
Expand Down Expand Up @@ -399,7 +399,7 @@ endif()
target_include_directories(proj INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${PROJ_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${INCLUDEDIR}>)
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)

if(WIN32)
set_target_properties(proj
Expand Down Expand Up @@ -487,14 +487,14 @@ endif()
##############################################
install(TARGETS proj
EXPORT targets
RUNTIME DESTINATION ${BINDIR}
LIBRARY DESTINATION ${LIBDIR}
ARCHIVE DESTINATION ${LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
FRAMEWORK DESTINATION ${FRAMEWORKDIR})

if(NOT BUILD_FRAMEWORKS_AND_BUNDLE)
install(FILES ${ALL_LIBPROJ_HEADERS}
DESTINATION ${INCLUDEDIR})
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif()

##############################################
Expand Down