aboutsummaryrefslogtreecommitdiff
path: root/modules/check_installed_exports_file.cmake
blob: ab36b9cfe541aaf5b9111d3a5fd3583c61fd2f3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# INSTALL_DIR - set it to the install destination
# INSTALL_PREFIX - set it to CMAKE_INSTALL_PREFIX
# CURRENT_BINARY_DIR - set it to CMAKE_CURRENT_BINARY_DIR
# FILENAME  - the filename of the exports file

# get the absolute install directory, consider absolute and relative paths and also DESTDIR
if(IS_ABSOLUTE "${INSTALL_DIR}")
   set(installDir "$ENV{DESTDIR}${INSTALL_DIR}")
else(IS_ABSOLUTE "${INSTALL_DIR}")
   set(installDir "$ENV{DESTDIR}${INSTALL_PREFIX}/${INSTALL_DIR}")
endif(IS_ABSOLUTE "${INSTALL_DIR}")

set(installedExportsFile "${installDir}/${FILENAME}")


# if the file already exists at the install location, and if we can
# find the exports file in the build dir, read both, and if their contents differ,
# remove all configuration-specific exports files from the install dir, since
# they may create conflicts if the new targets have been added/targets have been 
# removed/ targets have been renamed/ the namespace for the exported targets has changed
if(EXISTS "${installedExportsFile}")
   if (${INSTALL_DIR} MATCHES "^(/)(.+)$")
      set(binaryDirExportFileDir "_${CMAKE_MATCH_2}")
      set(binaryDirExportsFile "${CURRENT_BINARY_DIR}/CMakeFiles/Export/${binaryDirExportFileDir}/${FILENAME}")
   else (${INSTALL_DIR} MATCHES "^(/)(.+)$")
      set(binaryDirExportsFile "${CURRENT_BINARY_DIR}/CMakeFiles/Export/${INSTALL_DIR}/${FILENAME}")
   endif (${INSTALL_DIR} MATCHES "^(/)(.+)$")

   if(EXISTS "${binaryDirExportsFile}") 
      file(READ "${installedExportsFile}" installedExportsFileContents)
      file(READ "${binaryDirExportsFile}" binaryDirExportsFileContents)

      if(NOT "${installedExportsFileContents}" STREQUAL "${binaryDirExportsFileContents}")

         if("${FILENAME}" MATCHES "^(.+)(\\.cmake)$")
            message(STATUS "Installed and new ${FILENAME} differ, removing installed ${CMAKE_MATCH_1}-*.cmake files")
            file(GLOB files "${installDir}/${CMAKE_MATCH_1}-*.cmake")
            file(REMOVE ${files})
         endif("${FILENAME}" MATCHES "^(.+)(\\.cmake)$")
      else(NOT "${installedExportsFileContents}" STREQUAL "${binaryDirExportsFileContents}")
         message(STATUS "FILES are the same")
      endif(NOT "${installedExportsFileContents}" STREQUAL "${binaryDirExportsFileContents}")

   endif(EXISTS "${binaryDirExportsFile}") 

endif(EXISTS "${installedExportsFile}")