Commit 647cea86 authored by Harris Hancock's avatar Harris Hancock Committed by Harris Hancock

autotools: CMake package version compatibility checking

Closes #523.

Copied CMake's bundled AnyNewerVersion template to our local cmake/ directory, and modified both CMake and autotools scripts to configure/install it.
parent 088b09a6
...@@ -57,6 +57,7 @@ ...@@ -57,6 +57,7 @@
/c++/capnp /c++/capnp
/c++/capnp-evolution-test /c++/capnp-evolution-test
/c++/cmake/CapnProtoConfig.cmake /c++/cmake/CapnProtoConfig.cmake
/c++/cmake/CapnProtoConfigVersion.cmake
/c++/pkgconfig/*.pc /c++/pkgconfig/*.pc
/c++/capnp-test /c++/capnp-test
/c++/capnpc-c++ /c++/capnpc-c++
......
...@@ -81,11 +81,17 @@ add_subdirectory(src) ...@@ -81,11 +81,17 @@ add_subdirectory(src)
# Install ====================================================================== # Install ======================================================================
include(CMakePackageConfigHelpers) include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/cmake/CapnProtoConfigVersion.cmake" # We used to use write_basic_package_version_file(), but since the autotools build needs to install
VERSION ${VERSION} # a config version script as well, I copied the AnyNewerVersion template from my CMake Modules
COMPATIBILITY AnyNewerVersion # directory to Cap'n Proto's cmake/ directory (alternatively, we could make the autotools build
) # depend on CMake).
#
# We might as well use the local copy of the template. In the future we can modify the project's
# version compatibility policy just by changing that file.
set(PACKAGE_VERSION ${VERSION})
configure_file(cmake/CapnProtoConfigVersion.cmake.in cmake/CapnProtoConfigVersion.cmake @ONLY)
set(CONFIG_PACKAGE_LOCATION ${CMAKE_INSTALL_LIBDIR}/cmake/CapnProto) set(CONFIG_PACKAGE_LOCATION ${CMAKE_INSTALL_LIBDIR}/cmake/CapnProto)
configure_package_config_file(cmake/CapnProtoConfig.cmake.in configure_package_config_file(cmake/CapnProtoConfig.cmake.in
......
# This is a copy of /usr/share/cmake-3.5/Modules/BasicConfigVersion-AnyNewerVersion.cmake.in, with
# the following change:
# - @CVF_VERSION renamed to @PACKAGE_VERSION@. Autoconf defines a PACKAGE_VERSION
# output variable for us, so might as well take advantage of that.
# This is a basic version file for the Config-mode of find_package().
# It is used by write_basic_package_version_file() as input file for configure_file()
# to create a version-file which can be installed along a config.cmake file.
#
# The created file sets PACKAGE_VERSION_EXACT if the current version string and
# the requested version string are exactly the same and it sets
# PACKAGE_VERSION_COMPATIBLE if the current version is >= requested version.
# The variable PACKAGE_VERSION must be set before calling configure_file().
set(PACKAGE_VERSION "@PACKAGE_VERSION@")
if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
set(PACKAGE_VERSION_COMPATIBLE FALSE)
else()
set(PACKAGE_VERSION_COMPATIBLE TRUE)
if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION)
set(PACKAGE_VERSION_EXACT TRUE)
endif()
endif()
# if the installed or the using project don't have CMAKE_SIZEOF_VOID_P set, ignore it:
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "" OR "@CMAKE_SIZEOF_VOID_P@" STREQUAL "")
return()
endif()
# check that the installed version has the same 32/64bit-ness as the one which is currently searching:
if(NOT CMAKE_SIZEOF_VOID_P STREQUAL "@CMAKE_SIZEOF_VOID_P@")
math(EXPR installedBits "@CMAKE_SIZEOF_VOID_P@ * 8")
set(PACKAGE_VERSION "${PACKAGE_VERSION} (${installedBits}bit)")
set(PACKAGE_VERSION_UNSUITABLE TRUE)
endif()
...@@ -12,8 +12,6 @@ ...@@ -12,8 +12,6 @@
# #
# -DCapnProto_DEBUG=ON # -DCapnProto_DEBUG=ON
# #
# TODO(soon): Implement CapnProtoConfigVersion.cmake, too.
#
# TODO(someday): Distinguish between debug and release builds. I.e., set IMPORTED_LOCATION_RELEASE # TODO(someday): Distinguish between debug and release builds. I.e., set IMPORTED_LOCATION_RELEASE
# rather than IMPORTED_LOCATION, etc., if this installation was configured as a release build. But # rather than IMPORTED_LOCATION, etc., if this installation was configured as a release build. But
# how do we tell? grep for -g in CXXFLAGS? # how do we tell? grep for -g in CXXFLAGS?
......
...@@ -116,6 +116,7 @@ AC_DEFUN([CAPNP_PKG_CONFIG_FILES], [ \ ...@@ -116,6 +116,7 @@ AC_DEFUN([CAPNP_PKG_CONFIG_FILES], [ \
]) ])
AC_DEFUN([CAPNP_CMAKE_CONFIG_FILES], [ \ AC_DEFUN([CAPNP_CMAKE_CONFIG_FILES], [ \
cmake/CapnProtoConfig.cmake \ cmake/CapnProtoConfig.cmake \
cmake/CapnProtoConfigVersion.cmake \
]) ])
[CAPNP_PKG_CONFIG_FILES]="CAPNP_PKG_CONFIG_FILES" [CAPNP_PKG_CONFIG_FILES]="CAPNP_PKG_CONFIG_FILES"
...@@ -129,5 +130,10 @@ PACKAGE_CMAKE_INSTALL_FULL_INCLUDEDIR="${CMAKE_CURRENT_LIST_DIR}/../../include" ...@@ -129,5 +130,10 @@ PACKAGE_CMAKE_INSTALL_FULL_INCLUDEDIR="${CMAKE_CURRENT_LIST_DIR}/../../include"
AC_SUBST([PACKAGE_INIT]) AC_SUBST([PACKAGE_INIT])
AC_SUBST([PACKAGE_CMAKE_INSTALL_FULL_INCLUDEDIR]) AC_SUBST([PACKAGE_CMAKE_INSTALL_FULL_INCLUDEDIR])
# CapnProtoConfigVersion.cmake.in needs PACKAGE_VERSION (already defined by AC_INIT) and
# CMAKE_SIZEOF_VOID_P output variables.
AC_CHECK_SIZEOF([void *])
AC_SUBST(CMAKE_SIZEOF_VOID_P, $ac_cv_sizeof_void_p)
AC_CONFIG_FILES([Makefile] CAPNP_PKG_CONFIG_FILES CAPNP_CMAKE_CONFIG_FILES) AC_CONFIG_FILES([Makefile] CAPNP_PKG_CONFIG_FILES CAPNP_CMAKE_CONFIG_FILES)
AC_OUTPUT AC_OUTPUT
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment