Recognizing incompatible API changes between release versions through the CMake Config
It seems that certain aspects of the API have changed between versions 5.0.0 and 6.0.0, specifically as it relates to the definition of Hybrid function families: XC_FAMILY_HYB_*
no longer exist. Currently, the LibxcConfigVersion.cmake
generation specifies AnyNewerVersion
, from the CMake docs:
The COMPATIBILITY mode AnyNewerVersion means that the installed package version will be considered compatible if it is newer or exactly the same as the requested version. This mode should be used for packages which are fully backward compatible, also across major versions
As such, the following does not recognize the API break
find_package( Libxc 5.0.0 CONFIG REQUIRED )
One way to fix this would be to generate the version file with ExactVersion
, but that might be overkill if future versions of Libxc are compatible. Unfortunately, CMake does not provide generators for specific versions which break compatibility, so this would have to be done manually. The following would likely suffice for this purpose
# LibxcConfigVersion.cmake.in
set( PACKAGE_VERSION @PACKAGE_VERSION@ )
set( PACKAGE_VERSION_API_BREAK "6.0.0" ) # Or the exact version number that breaks API
# This checks the limit of backwards compatibility
if(PACKAGE_FIND_VERSION VERSION_LESS PACKAGE_VERSION_API_BREAK)
set(PACKAGE_VERSION_COMPATIBLE FALSE)
# This is the standard stuff that CMake Generates
elseif(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 "8" 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 "8")
math(EXPR installedBits "8 * 8")
set(PACKAGE_VERSION "${PACKAGE_VERSION} (${installedBits}bit)")
set(PACKAGE_VERSION_UNSUITABLE TRUE)
endif()