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

Make PROJ the CMake project name addressing first stage of #1885 #1910

Merged
merged 1 commit into from Feb 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 4 additions & 6 deletions CMakeLists.txt
Expand Up @@ -11,9 +11,7 @@
################################################################################
cmake_minimum_required(VERSION 3.9 FATAL_ERROR)

# For historic reasons, the CMake PROJECT-NAME is PROJ4
project(PROJ4 LANGUAGES C CXX)
set(PROJECT_INTERN_NAME PROJ)
project(PROJ LANGUAGES C CXX)

# Only interpret if() arguments as variables or keywords when unquoted
cmake_policy(SET CMP0054 NEW)
Expand Down Expand Up @@ -92,7 +90,7 @@ set(PROJ_CXX_WARN_FLAGS "${PROJ_CXX_WARN_FLAGS}"
# PROJ CMake modules
################################################################################
# Path to additional CMake modules
set(CMAKE_MODULE_PATH ${PROJ4_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
set(CMAKE_MODULE_PATH ${PROJ_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})

include(ProjUtilities)

Expand Down Expand Up @@ -235,7 +233,7 @@ set(DOCDIR "${DEFAULT_DOCDIR}"
set(INCLUDEDIR "${DEFAULT_INCLUDEDIR}"
CACHE PATH "The directory to install includes into.")
set(CMAKECONFIGDIR "${DEFAULT_CMAKEDIR}"
CACHE PATH "The directory to install cmake config files into.")
CACHE PATH "Parent of the directory to install cmake config files into.")

################################################################################
# Tests
Expand All @@ -256,7 +254,7 @@ endif()
################################################################################
# Build configured components
################################################################################
include_directories(${PROJ4_SOURCE_DIR}/src)
include_directories(${PROJ_SOURCE_DIR}/src)

message(STATUS "")
add_subdirectory(data)
Expand Down
132 changes: 108 additions & 24 deletions cmake/CMakeLists.txt
@@ -1,9 +1,78 @@
# proj-config.cmake for the install tree. It's installed in
# ${INSTALL_CMAKE_DIR} and @PROJECT_ROOT_DIR@ is the relative
# path to the root from there. (Note that the whole install tree can
# be relocated.)
file(RELATIVE_PATH PROJECT_ROOT_DIR
${CMAKE_INSTALL_PREFIX}/${CMAKECONFIGDIR} ${CMAKE_INSTALL_PREFIX})
# The old CMake PROJECT-NAME was PROJ4.
set (PROJECT_LEGACY_NAME PROJ4)
string (TOLOWER "${PROJECT_NAME}" PROJECT_NAME_LOWER)
string (TOLOWER "${PROJECT_LEGACY_NAME}" PROJECT_LEGACY_LOWER)

# Starting with version 7.0, we install config-style find package
# files so that PROJ can be found with both
#
# find_package(PROJ)
# find_package(PROJ4)
#
# Here are the details... The command
#
# find_package(PROJ)
#
# if successful, will define variables
#
# PROJ_FOUND
# PROJ_VERSION
# PROJ_LIBRARIES = PROJ::proj
# PROJ_INCLUDE_DIRS
# etc
#
# and will define targets
#
# PROJ::proj
# PROJ4::proj
#
# Similarly
#
# find_package(PROJ4)
#
# if successful, will define variables
#
# PROJ4_FOUND
# PROJ4_VERSION
# PROJ4_LIBRARIES = PROJ4::proj
# PROJ4_INCLUDE_DIRS
# etc
#
# and will define targets
#
# PROJ::proj
# PROJ4::proj
#
# Note that targets PROJ::proj and PROJ4::proj are provided in both
# cases. However, no attempt is made to define both sets of variables
# with the two find_package options. Doing so would just lead to user
# confusion.
#
# Because pre-7.0 versions of PROJ do not support find_package (PROJ)
# and do not define a target PROJ::proj
#
# find_package(PROJ4)
#
# (instead of PROJ) should be used in any development scenarios which
# might involve (even indirectly) pre-7.0 versions of PROJ.
#
# At some future dates, find_package (PROJ4) will
#
# define PROJ4_LIBRARIES = PROJ::proj
# give WARNING message suggesting migration to find_package(PROJ)
# be disallowed via the version checking code
#
# 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
#
# cmake/CMakeLists.txt (this file)
# cmake/project-config.cmake.in
# cmake/project-config-version.cmake.in

# Variables needed by ${PROJECT_NAME_LOWER}-config-version.cmake
if (MSVC)
Expand All @@ -24,21 +93,36 @@ else ()
set (CMAKE_CROSSCOMPILING_STR "OFF")
endif ()

string(TOLOWER "${PROJECT_NAME}" PROJECT_NAME_LOWER)
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 "${CMAKECONFIGDIR}"
RENAME "${PROJECT_NAME_LOWER}-config.cmake")
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/project-config-version.cmake"
DESTINATION "${CMAKECONFIGDIR}"
RENAME "${PROJECT_NAME_LOWER}-config-version.cmake")
# Make information about the cmake targets (the library and the tools)
# available.
install(EXPORT targets
NAMESPACE ${PROJECT_NAME}::
FILE ${PROJECT_NAME_LOWER}-targets.cmake
DESTINATION "${CMAKECONFIGDIR}")
foreach (PROJECT_VARIANT_NAME ${PROJECT_NAME} ${PROJECT_LEGACY_NAME})
string (TOLOWER "${PROJECT_VARIANT_NAME}" PROJECT_VARIANT_LOWER)
set (CMAKECONFIGSUBDIR "${CMAKECONFIGDIR}/${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
# be relocated.)
file (RELATIVE_PATH PROJECT_ROOT_DIR
${CMAKE_INSTALL_PREFIX}/${CMAKECONFIGSUBDIR} ${CMAKE_INSTALL_PREFIX})
configure_file (project-config.cmake.in
project-${PROJECT_VARIANT_LOWER}-config.cmake @ONLY)
configure_file (project-config-version.cmake.in
project-${PROJECT_VARIANT_LOWER}-version.cmake @ONLY)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/project-${PROJECT_VARIANT_LOWER}-config.cmake"
DESTINATION "${CMAKECONFIGSUBDIR}"
RENAME "${PROJECT_VARIANT_LOWER}-config.cmake")
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/project-${PROJECT_VARIANT_LOWER}-version.cmake"
DESTINATION "${CMAKECONFIGSUBDIR}"
RENAME "${PROJECT_VARIANT_LOWER}-config-version.cmake")
# Make information about the cmake targets (the library and the tools)
# available.
install(EXPORT targets
NAMESPACE ${PROJECT_NAME}::
FILE ${PROJECT_NAME_LOWER}-targets.cmake
DESTINATION "${CMAKECONFIGSUBDIR}")
install(EXPORT targets
NAMESPACE ${PROJECT_LEGACY_NAME}::
FILE ${PROJECT_LEGACY_LOWER}-targets.cmake
DESTINATION "${CMAKECONFIGSUBDIR}")
endforeach ()

4 changes: 2 additions & 2 deletions cmake/ProjConfig.cmake
Expand Up @@ -32,10 +32,10 @@ check_library_exists(m ceil "" HAVE_LIBM)
set(PACKAGE "proj")
set(PACKAGE_BUGREPORT "https://github.com/OSGeo/PROJ/issues")
set(PACKAGE_NAME "PROJ")
set(PACKAGE_STRING "PROJ ${${PROJECT_INTERN_NAME}_VERSION}")
set(PACKAGE_STRING "PROJ ${${PROJECT_NAME}_VERSION}")
set(PACKAGE_TARNAME "proj")
set(PACKAGE_URL "https://proj.org")
set(PACKAGE_VERSION "${${PROJECT_INTERN_NAME}_VERSION}")
set(PACKAGE_VERSION "${${PROJECT_NAME}_VERSION}")

# check if a second proj_config.h exists (created by ./configure)
# as this is within CMake's C_INCLUDES / CXX_INCLUDES
Expand Down
6 changes: 3 additions & 3 deletions cmake/ProjInstallPath.cmake
Expand Up @@ -30,7 +30,7 @@ if(UNIX)
set(DEFAULT_DATA_SUBDIR ${CMAKE_INSTALL_DATAROOTDIR}/proj)
set(DEFAULT_INCLUDE_SUBDIR ${CMAKE_INSTALL_INCLUDEDIR})
set(DEFAULT_DOC_SUBDIR ${CMAKE_INSTALL_DOCDIR})
set(DEFAULT_CMAKE_SUBDIR ${CMAKE_INSTALL_LIBDIR}/cmake/${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)
Expand All @@ -39,7 +39,7 @@ else()
set(DEFAULT_DOC_SUBDIR doc/proj)
set(DEFAULT_INCLUDE_SUBDIR include)
set(DEFAULT_DOC_SUBDIR share/doc/proj)
set(DEFAULT_CMAKE_SUBDIR lib/cmake/${PROJECT_NAME_LOWER})
set(DEFAULT_CMAKE_SUBDIR lib/cmake)
endif()

# Locations are changeable by user to customize layout of PROJ installation
Expand All @@ -55,7 +55,7 @@ set(PROJ_DATA_SUBDIR ${DEFAULT_DATA_SUBDIR} CACHE STRING
set(PROJ_DOC_SUBDIR ${DEFAULT_DOC_SUBDIR} CACHE STRING
"Subdirectory where doc will be installed")
set(PROJ_CMAKE_SUBDIR ${DEFAULT_CMAKE_SUBDIR} CACHE STRING
"Subdirectory where cmake proj-config file will be installed")
"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(
Expand Down
8 changes: 4 additions & 4 deletions cmake/ProjUtilities.cmake
Expand Up @@ -98,17 +98,17 @@ function(proj_target_output_name TARGET_NAME OUTPUT_NAME)
message(SEND_ERROR "Error, the variable TARGET_NAME is not defined!")
endif()

if(NOT DEFINED ${PROJECT_INTERN_NAME}_VERSION)
if(NOT DEFINED ${PROJECT_NAME}_VERSION)
message(SEND_ERROR
"Error, the variable ${${PROJECT_INTERN_NAME}_VERSION} is not defined!")
"Error, the variable ${${PROJECT_NAME}_VERSION} is not defined!")
endif()

# On Windows, ABI version is specified using binary file name suffix.
# On Unix, suffix is empty and SOVERSION is used instead.
if(WIN32)
string(LENGTH "${${PROJECT_INTERN_NAME}_ABI_VERSION}" abilen)
string(LENGTH "${${PROJECT_NAME}_ABI_VERSION}" abilen)
if(abilen GREATER 0)
set(SUFFIX "_${${PROJECT_INTERN_NAME}_ABI_VERSION}")
set(SUFFIX "_${${PROJECT_NAME}_ABI_VERSION}")
endif()
endif()

Expand Down
24 changes: 12 additions & 12 deletions cmake/ProjVersion.cmake
Expand Up @@ -27,27 +27,27 @@ macro(proj_version)
${ARGN})

# Set version components
set(${PROJECT_INTERN_NAME}_VERSION_MAJOR ${THIS_VERSION_MAJOR})
set(${PROJECT_INTERN_NAME}_VERSION_MINOR ${THIS_VERSION_MINOR})
set(${PROJECT_INTERN_NAME}_VERSION_PATCH ${THIS_VERSION_PATCH})
set(${PROJECT_NAME}_VERSION_MAJOR ${THIS_VERSION_MAJOR})
set(${PROJECT_NAME}_VERSION_MINOR ${THIS_VERSION_MINOR})
set(${PROJECT_NAME}_VERSION_PATCH ${THIS_VERSION_PATCH})

# Set VERSION string
set(${PROJECT_INTERN_NAME}_VERSION
"${${PROJECT_INTERN_NAME}_VERSION_MAJOR}.\
${${PROJECT_INTERN_NAME}_VERSION_MINOR}.\
${${PROJECT_INTERN_NAME}_VERSION_PATCH}")
set(${PROJECT_NAME}_VERSION
"${${PROJECT_NAME}_VERSION_MAJOR}.\
${${PROJECT_NAME}_VERSION_MINOR}.\
${${PROJECT_NAME}_VERSION_PATCH}")

# Set ABI version string used to name binary output
# On Windows, ABI version is specified using binary file name suffix.
if(WIN32)
set(${PROJECT_INTERN_NAME}_ABI_VERSION
"${${PROJECT_INTERN_NAME}_VERSION_MAJOR}_\
${${PROJECT_INTERN_NAME}_VERSION_MINOR}")
set(${PROJECT_NAME}_ABI_VERSION
"${${PROJECT_NAME}_VERSION_MAJOR}_\
${${PROJECT_NAME}_VERSION_MINOR}")
endif()

message(STATUS "")
boost_report_value(${PROJECT_INTERN_NAME}_VERSION)
boost_report_value(${PROJECT_NAME}_VERSION)
if(WIN32)
boost_report_value(${PROJECT_INTERN_NAME}_ABI_VERSION)
boost_report_value(${PROJECT_NAME}_ABI_VERSION)
endif()
endmacro()
6 changes: 3 additions & 3 deletions cmake/project-config-version.cmake.in
@@ -1,4 +1,4 @@
# Version checking for @PROJECT_NAME@
# Version checking for @PROJECT_VARIANT_NAME@

set (PACKAGE_VERSION "@PROJ_VERSION@")
set (PACKAGE_VERSION_MAJOR "@PROJ_VERSION_MAJOR@")
Expand All @@ -22,12 +22,12 @@ else ()
set (CMAKE_CROSSCOMPILING_STR "OFF")
endif ()

if (NOT PACKAGE_FIND_NAME STREQUAL "@PROJECT_NAME@")
if (NOT PACKAGE_FIND_NAME STREQUAL "@PROJECT_VARIANT_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 (REASON "package = @PROJECT_VARIANT_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@))
Expand Down
33 changes: 19 additions & 14 deletions cmake/project-config.cmake.in
@@ -1,31 +1,36 @@
# Configure @PROJECT_NAME@
#
# Set
# @PROJECT_NAME@_FOUND = 1
# @PROJECT_NAME@_INCLUDE_DIRS = /usr/local/include
# @PROJECT_NAME@_LIBRARIES = proj
# @PROJECT_NAME@_LIBRARY_DIRS = /usr/local/lib
# @PROJECT_NAME@_BINARY_DIRS = /usr/local/bin
# @PROJECT_NAME@_VERSION = 4.9.1 (for example)
# @PROJECT_VARIANT_NAME@_FOUND = 1
# @PROJECT_VARIANT_NAME@_INCLUDE_DIRS = /usr/local/include
# @PROJECT_VARIANT_NAME@_LIBRARIES = @PROJECT_VARIANT_NAME@::proj
# @PROJECT_VARIANT_NAME@_LIBRARY_DIRS = /usr/local/lib
# @PROJECT_VARIANT_NAME@_BINARY_DIRS = /usr/local/bin
# @PROJECT_VARIANT_NAME@_VERSION = 4.9.1 (for example)

message (STATUS "Reading ${CMAKE_CURRENT_LIST_FILE}")
# @PROJECT_NAME@_VERSION is set by version file
# @PROJECT_VARIANT_NAME@_VERSION is set by version file
message (STATUS
"@PROJECT_NAME@ configuration, version ${@PROJECT_NAME@_VERSION}")
"@PROJECT_VARIANT_NAME@ configuration, \
version ${@PROJECT_VARIANT_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}/@INCLUDEDIR@")
set (@PROJECT_NAME@_LIBRARY_DIRS "${_ROOT}/@LIBDIR@")
set (@PROJECT_NAME@_BINARY_DIRS "${_ROOT}/@BINDIR@")
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_NAME@_LIBRARIES @PROJECT_NAME@::proj)
set (@PROJECT_VARIANT_NAME@_LIBRARIES @PROJECT_VARIANT_NAME@::proj)
# Read in the exported definition of the library
include ("${_DIR}/@PROJECT_NAME_LOWER@-targets.cmake")
include ("${_DIR}/@PROJECT_LEGACY_LOWER@-targets.cmake")

unset (_ROOT)
unset (_DIR)

# For backward compatibility with old releases of libgeotiff
set (@PROJECT_NAME@_INCLUDE_DIR ${@PROJECT_NAME@_INCLUDE_DIRS})
if ("@PROJECT_VARIANT_NAME@" STREQUAL "PROJ4")
# For backward compatibility with old releases of libgeotiff
set (@PROJECT_VARIANT_NAME@_INCLUDE_DIR
${@PROJECT_VARIANT_NAME@_INCLUDE_DIRS})
endif ()
25 changes: 19 additions & 6 deletions docs/source/development/cmake.rst
Expand Up @@ -5,26 +5,39 @@ Using PROJ in CMake projects
********************************************************************************

The recommended way to use the PROJ library in a CMake project is to
link to the imported library target ``${PROJ4_LIBRARIES}`` provided by
link to the imported library target ``${PROJ_LIBRARIES}`` provided by
the CMake configuration which comes with the library. Typical usage is:

.. code::

find_package(PROJ4)
find_package(PROJ)

target_link_libraries(MyApp ${PROJ4_LIBRARIES})
target_link_libraries(MyApp ${PROJ_LIBRARIES})

By adding the imported library target ``${PROJ4_LIBRARIES}`` to the
By adding the imported library target ``${PROJ_LIBRARIES}`` to the
target link libraries, CMake will also pass the include directories to
the compiler. This requires that you use CMake version 2.8.11 or later.
If you are using an older version of CMake, then add

.. code::

include_directories(${PROJ4_INCLUDE_DIRS})
include_directories(${PROJ_INCLUDE_DIRS})

The CMake command ``find_package`` will look for the configuration in a
number of places. The lookup can be adjusted for all packages by setting
the cache variable or environment variable ``CMAKE_PREFIX_PATH``. In
particular, CMake will consult (and set) the cache variable
``PROJ4_DIR``.
``PROJ_DIR``.

The old CMake name for the PROJ project was "PROJ4" and the switch to
the name "PROJ" was made with version 7.0. So if you expect your
package to work with pre-7.0 versions of PROJ, you will need to use

.. code::

find_package(PROJ4)
target_link_libraries(MyApp ${PROJ4_LIBRARIES})
include_directories(${PROJ4_INCLUDE_DIRS})

This will also find version 7.0. This use of the PROJ4 name will be
phased out at some point.