CheckPublicHeaders.cmake
Go to the documentation of this file.
00001 ############################################################################## 00002 # @file CheckPublicHeaders.cmake 00003 # @brief CMake script used to check whether public headers were added/removed. 00004 # 00005 # This script removes the deprecated public headers from the build tree and 00006 # then throws a fatal error if public header files were added or removed to 00007 # the project. 00008 # 00009 # Copyright (c) 2011, 2012 University of Pennsylvania. All rights reserved.<br /> 00010 # See https://www.cbica.upenn.edu/sbia/software/license.html or COPYING file. 00011 # 00012 # Contact: SBIA Group <sbia-software at uphs.upenn.edu> 00013 # 00014 # @ingroup CMakeUtilities 00015 ############################################################################## 00016 00017 # ---------------------------------------------------------------------------- 00018 # check arguments 00019 if (NOT CMAKE_FILE) 00020 message (FATAL_ERROR "Missing argument CMAKE_FILE!") 00021 endif () 00022 00023 if (NOT REFERENCE_FILE) 00024 message (FATAL_ERROR "Missing argument REFERENCE_FILE!") 00025 endif () 00026 00027 if (NOT BINARY_INCLUDE_DIR) 00028 message (FATAL_ERROR "Missing argument BINARY_INCLUDE_DIR!") 00029 endif () 00030 00031 if (NOT PROJECT_INCLUDE_DIRS) 00032 message (FATAL_ERROR "Missing argument PROJECT_INCLUDE_DIRS!") 00033 endif () 00034 00035 if (NOT VARIABLE_NAME) 00036 set (VARIABLE_NAME "PUBLIC_HEADERS") 00037 endif () 00038 00039 # ---------------------------------------------------------------------------- 00040 # compare files 00041 execute_process ( 00042 COMMAND ${CMAKE_COMMAND} -E compare_files "${CMAKE_FILE}" "${REFERENCE_FILE}" 00043 RESULT_VARIABLE EXIT_CODE 00044 OUTPUT_QUIET 00045 ERROR_QUIET 00046 ) 00047 00048 if (EXIT_CODE EQUAL 0) 00049 set (CMAKE_FILE_DIFFERS FALSE) 00050 else () 00051 set (CMAKE_FILE_DIFFERS TRUE) 00052 endif () 00053 00054 # ---------------------------------------------------------------------------- 00055 # remove obsolete public headers 00056 if (CMAKE_FILE_DIFFERS) 00057 unset (${VARIABLE_NAME}) 00058 include ("${CMAKE_FILE}") 00059 set (_HEADERS "${${VARIABLE_NAME}}") 00060 unset (${VARIABLE_NAME}) 00061 include ("${REFERENCE_FILE}") 00062 foreach (H IN LISTS _HEADERS) 00063 list (FIND ${VARIABLE_NAME} "${H}" IDX) 00064 if (IDX EQUAL -1) 00065 string (REGEX REPLACE "^.*/include/" "" H "${H}") 00066 string (REGEX REPLACE "\\.in$" "" H "${H}") 00067 file (REMOVE "${BINARY_INCLUDE_DIR}/${H}") 00068 endif () 00069 endforeach () 00070 endif () 00071 00072 # ---------------------------------------------------------------------------- 00073 # remove files if different 00074 if (CMAKE_FILE_DIFFERS) 00075 file (REMOVE "${CMAKE_FILE}") 00076 file (REMOVE "${REFERENCE_FILE}") 00077 file (REMOVE "${REFERENCE_FILE}.update") 00078 endif () 00079 00080 # ---------------------------------------------------------------------------- 00081 # fatal error if files added/removed 00082 if (CMAKE_FILE_DIFFERS AND ERRORMSG) 00083 message (FATAL_ERROR "${ERRORMSG}") 00084 endif ()