From: Michael Wallner Date: Tue, 18 Aug 2020 07:31:43 +0000 (+0200) Subject: cmake: verify public header interface versions X-Git-Tag: 1.1.0-beta1~242 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=0eb039e8de2a95b35a082a21a103a68e1d08385f;p=m6w6%2Flibmemcached cmake: verify public header interface versions --- diff --git a/CMake/InstallPublicHeaders.cmake b/CMake/InstallPublicHeaders.cmake index 56ebb0c4..70cfe3d0 100644 --- a/CMake/InstallPublicHeaders.cmake +++ b/CMake/InstallPublicHeaders.cmake @@ -1,4 +1,35 @@ function(install_public_headers DIRECTORY) + # validate current directory + string(FIND ${CMAKE_CURRENT_SOURCE_DIR} /include/ INCDIR REVERSE) + string(FIND ${CMAKE_CURRENT_SOURCE_DIR} /src/ SRCDIR REVERSE) + if((INCDIR GREATER_EQUAL 0) OR (SRCDIR GREATER_EQUAL 0)) + if(INCDIR GREATER_EQUAL 0) + math(EXPR POSITION "${INCDIR} + 9") + else() + math(EXPR POSITION "${SRCDIR} + 5") + endif() + string(SUBSTRING ${CMAKE_CURRENT_SOURCE_DIR} ${POSITION} -1 CHKDIR) + if(NOT CHKDIR STREQUAL DIRECTORY) + message(SEND_ERROR "install_public_headers() directories do not match: ${CHKDIR} != ${DIRECTORY}") + set(ENV{INVALID_CONFIGURATION} 1) + endif() + endif() + + # validate public interface version + get_filename_component(TOP ${DIRECTORY} NAME) + string(FIND ${TOP} "-" DASH) + if(DASH GREATER 0) + string(SUBSTRING ${TOP} 0 ${DASH} LIBRARY) + string(TOUPPER ${LIBRARY} LIBRARY_UCASE) + math(EXPR DASH "${DASH} + 1") + string(SUBSTRING ${TOP} ${DASH} -1 VERSION) + if(NOT ${LIBRARY_UCASE}_VERSION_INC VERSION_EQUAL ${VERSION}) + message(SEND_ERROR "${LIBRARY} public include directory version ${VERSION} != " ${${LIBRARY_UCASE}_VERSION_INC}) + set(ENV{INVALID_CONFIGURATION} 1) + endif() + endif() + + # change local includes to system includes foreach(HEADER IN LISTS ARGN) file(READ ${HEADER} HEADER_IN) string(REGEX REPLACE "include *\"([^\"]+)\"" "include <\\1>" HEADER_OUT "${HEADER_IN}") diff --git a/CMakeLists.txt b/CMakeLists.txt index 2db4ab3a..f559febd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,4 +60,6 @@ if(BUILD_DOCS OR BUILD_DOCSONLY) add_subdirectory(docs) endif() - +if(ENV{INVALID_CONFIGURATION}) + message(FATAL_ERROR "invalid configuration -- giving up") +endif()