-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add config-style support for find_package(shapefile).
Also fix installation directories so that the package is relocatable.
- Loading branch information
Showing
4 changed files
with
205 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# config file support for find_package (shapelib). | ||
|
||
# Variables needed by ${PROJECT_NAME}-config-version.cmake | ||
if (MSVC) | ||
# For checking the compatibility of MSVC_TOOLSET_VERSION; see | ||
# https://docs.microsoft.com/en-us/cpp/porting/overview-of-potential-upgrade-issues-visual-cpp | ||
# Assume major version number is obtained by dropping the last decimal | ||
# digit. | ||
math (EXPR MSVC_TOOLSET_MAJOR "${MSVC_TOOLSET_VERSION}/10") | ||
else () | ||
set (MSVC_TOOLSET_VERSION 0) | ||
set (MSVC_TOOLSET_MAJOR 0) | ||
endif () | ||
if (CMAKE_CROSSCOMPILING) | ||
# Ensure that all "true" (resp. "false") settings are represented by | ||
# the same string. | ||
set (CMAKE_CROSSCOMPILING_STR "ON") | ||
else () | ||
set (CMAKE_CROSSCOMPILING_STR "OFF") | ||
endif () | ||
|
||
# Find root of install tree relative to CMAKE_INSTALL_CMAKEDIR | ||
file (RELATIVE_PATH PROJECT_ROOT_DIR | ||
"${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_CMAKEDIR}" "${CMAKE_INSTALL_PREFIX}") | ||
# strip trailing slash | ||
get_filename_component (PROJECT_ROOT_DIR "${PROJECT_ROOT_DIR}/." PATH) | ||
|
||
|
||
configure_file (project-config.cmake.in project-config.cmake @ONLY) | ||
configure_file (project-config-version.cmake.in | ||
project-config-version.cmake @ONLY) | ||
install (FILES | ||
"${CMAKE_CURRENT_BINARY_DIR}/project-config.cmake" | ||
DESTINATION "${CMAKE_INSTALL_CMAKEDIR}" | ||
RENAME "${PROJECT_NAME}-config.cmake") | ||
install (FILES | ||
"${CMAKE_CURRENT_BINARY_DIR}/project-config-version.cmake" | ||
DESTINATION "${CMAKE_INSTALL_CMAKEDIR}" | ||
RENAME "${PROJECT_NAME}-config-version.cmake") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Version checking for @PROJECT_NAME@ | ||
|
||
set (PACKAGE_VERSION "@PROJECT_VERSION@") | ||
set (PACKAGE_VERSION_MAJOR "@PROJECT_VERSION_MAJOR@") | ||
set (PACKAGE_VERSION_MINOR "@PROJECT_VERSION_MINOR@") | ||
set (PACKAGE_VERSION_PATCH "@PROJECT_VERSION_PATCH@") | ||
|
||
# These variable definitions parallel those in @PROJECT_NAME@'s | ||
# cmake/CMakeLists.txt. | ||
if (MSVC) | ||
# For checking the compatibility of MSVC_TOOLSET_VERSION; see | ||
# https://docs.microsoft.com/en-us/cpp/porting/overview-of-potential-upgrade-issues-visual-cpp | ||
# Assume major version number is obtained by dropping the last decimal | ||
# digit. | ||
math (EXPR MSVC_TOOLSET_MAJOR "${MSVC_TOOLSET_VERSION}/10") | ||
endif () | ||
if (CMAKE_CROSSCOMPILING) | ||
# Ensure that all "true" (resp. "false") settings are represented by | ||
# the same string. | ||
set (CMAKE_CROSSCOMPILING_STR "ON") | ||
else () | ||
set (CMAKE_CROSSCOMPILING_STR "OFF") | ||
endif () | ||
|
||
if (NOT PACKAGE_FIND_NAME STREQUAL "@PROJECT_NAME@") | ||
# Check package name (in particular, because of the way cmake finds | ||
# package config files, the capitalization could easily be "wrong"). | ||
# This is necessary to ensure that the automatically generated | ||
# variables, e.g., <package>_FOUND, are consistently spelled. | ||
set (REASON "package = @PROJECT_NAME@, NOT ${PACKAGE_FIND_NAME}") | ||
set (PACKAGE_VERSION_UNSUITABLE TRUE) | ||
elseif (NOT (APPLE OR (NOT DEFINED CMAKE_SIZEOF_VOID_P) OR | ||
CMAKE_SIZEOF_VOID_P EQUAL @CMAKE_SIZEOF_VOID_P@)) | ||
# Reject if there's a 32-bit/64-bit mismatch (not necessary with Apple | ||
# since a multi-architecture library is built for that platform). | ||
set (REASON "sizeof(*void) = @CMAKE_SIZEOF_VOID_P@") | ||
set (PACKAGE_VERSION_UNSUITABLE TRUE) | ||
elseif (MSVC AND NOT ( | ||
# toolset version must be at least as great as @PROJECT_NAME@'s | ||
MSVC_TOOLSET_VERSION GREATER_EQUAL @MSVC_TOOLSET_VERSION@ | ||
# and major versions must match | ||
AND MSVC_TOOLSET_MAJOR EQUAL @MSVC_TOOLSET_MAJOR@ )) | ||
# Reject if there's a mismatch in MSVC compiler versions | ||
set (REASON "MSVC_TOOLSET_VERSION = @MSVC_TOOLSET_VERSION@") | ||
set (PACKAGE_VERSION_UNSUITABLE TRUE) | ||
elseif (NOT CMAKE_CROSSCOMPILING_STR STREQUAL "@CMAKE_CROSSCOMPILING_STR@") | ||
# Reject if there's a mismatch in ${CMAKE_CROSSCOMPILING} | ||
set (REASON "cross-compiling = @CMAKE_CROSSCOMPILING@") | ||
set (PACKAGE_VERSION_UNSUITABLE TRUE) | ||
elseif (CMAKE_CROSSCOMPILING AND | ||
NOT (CMAKE_SYSTEM_NAME STREQUAL "@CMAKE_SYSTEM_NAME@" AND | ||
CMAKE_SYSTEM_PROCESSOR STREQUAL "@CMAKE_SYSTEM_PROCESSOR@")) | ||
# Reject if cross-compiling and there's a mismatch in the target system | ||
set (REASON "target = @CMAKE_SYSTEM_NAME@-@CMAKE_SYSTEM_PROCESSOR@") | ||
set (PACKAGE_VERSION_UNSUITABLE TRUE) | ||
elseif (PACKAGE_FIND_VERSION) | ||
if (PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION) | ||
set (PACKAGE_VERSION_EXACT TRUE) | ||
elseif (PACKAGE_FIND_VERSION VERSION_LESS PACKAGE_VERSION | ||
AND PACKAGE_FIND_VERSION_MAJOR EQUAL PACKAGE_VERSION_MAJOR) | ||
set (PACKAGE_VERSION_COMPATIBLE TRUE) | ||
endif () | ||
endif () | ||
|
||
# If unsuitable, append the reason to the package version so that it's | ||
# visible to the user. | ||
if (PACKAGE_VERSION_UNSUITABLE) | ||
set (PACKAGE_VERSION "${PACKAGE_VERSION} (${REASON})") | ||
endif () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Configure @PROJECT_NAME@ | ||
# | ||
# Set | ||
# @PROJECT_NAME@_FOUND = 1 | ||
# @PROJECT_NAME@_INCLUDE_DIRS = /usr/local/include | ||
# @PROJECT_NAME@_LIBRARIES = shapelib::shp | ||
# @PROJECT_NAME@_LIBRARY_DIRS = /usr/local/lib | ||
# @PROJECT_NAME@_BINARY_DIRS = /usr/local/bin | ||
# @PROJECT_NAME@_VERSION = 1.5.0 (for example) | ||
|
||
message (STATUS "Reading ${CMAKE_CURRENT_LIST_FILE}") | ||
# @PROJECT_NAME@_VERSION is set by version file | ||
message (STATUS | ||
"@PROJECT_NAME@ configuration, version ${@PROJECT_NAME@_VERSION}") | ||
|
||
# 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_NAME@_INCLUDE_DIRS "${_ROOT}/@CMAKE_INSTALL_INCLUDEDIR@") | ||
set (@PROJECT_NAME@_LIBRARY_DIRS "${_ROOT}/@CMAKE_INSTALL_LIBDIR@") | ||
set (@PROJECT_NAME@_BINARY_DIRS "${_ROOT}/@CMAKE_INSTALL_BINDIR@") | ||
|
||
set (@PROJECT_NAME@_LIBRARIES shapelib::shp) | ||
# Read in the exported definition of the library | ||
include ("${_DIR}/@PROJECT_NAME@-targets.cmake") | ||
|
||
unset (_ROOT) | ||
unset (_DIR) | ||
|