| 1 |
cmake_minimum_required(VERSION 3.15) |
| 2 |
|
| 3 |
# This CMake script will delete build directories and files to bring the |
| 4 |
# package back to it's distribution state |
| 5 |
|
| 6 |
# We want to start from the top of the source dir, so if we are in build |
| 7 |
# we want to start one directory up |
| 8 |
GET_FILENAME_COMPONENT(BASEDIR ${CMAKE_SOURCE_DIR} NAME) |
| 9 |
IF(${BASEDIR} STREQUAL "build") |
| 10 |
SET(TOPDIR "${CMAKE_SOURCE_DIR}/..") |
| 11 |
ELSE() |
| 12 |
SET(TOPDIR "${CMAKE_SOURCE_DIR}") |
| 13 |
ENDIF() |
| 14 |
|
| 15 |
MACRO(GET_PARENT_DIRECTORIES search_string return_list grandparents) |
| 16 |
FILE(GLOB_RECURSE new_list ${search_string}) |
| 17 |
SET(dir_list "") |
| 18 |
FOREACH(file_path ${new_list}) |
| 19 |
GET_FILENAME_COMPONENT(dir_path ${file_path} PATH) |
| 20 |
# Remove an extra directory component to return grandparent |
| 21 |
IF(${grandparents}) |
| 22 |
# Tack on a fake extension to trick CMake into removing a second |
| 23 |
# path component |
| 24 |
SET(dir_path "${dir_path}.tmp") |
| 25 |
GET_FILENAME_COMPONENT(dir_path ${dir_path} PATH) |
| 26 |
ENDIF(${grandparents}) |
| 27 |
SET(dir_list ${dir_list} ${dir_path}) |
| 28 |
ENDFOREACH() |
| 29 |
LIST(REMOVE_DUPLICATES dir_list) |
| 30 |
SET(${return_list} ${dir_list}) |
| 31 |
ENDMACRO() |
| 32 |
|
| 33 |
# Find directories and files that we will want to remove |
| 34 |
FILE(GLOB EGGS "${TOPDIR}/*.egg-info" "${TOPDIR}/python/*.egg-info") |
| 35 |
FILE(GLOB PYCACHE "${TOPDIR}/python/npspec/tests/__pycache__") |
| 36 |
FILE(GLOB_RECURSE PYC "${TOPDIR}/*.pyc") |
| 37 |
FILE(GLOB_RECURSE CBP "${TOPDIR}/*.cbp") |
| 38 |
FILE(GLOB PYBUILDTEMP "${TOPDIR}/build/temp*") |
| 39 |
FILE(GLOB PYBUILDLIB "${TOPDIR}/build/lib*") |
| 40 |
FILE(GLOB PYBUILDBDIST "${TOPDIR}/build/bdist*") |
| 41 |
FILE(GLOB_RECURSE CMAKECACHE "${TOPDIR}/*CMakeCache.txt") |
| 42 |
FILE(GLOB_RECURSE CMAKEINSTALL "${TOPDIR}/*cmake_install.cmake") |
| 43 |
FILE(GLOB_RECURSE MAKEFILE "${TOPDIR}/*Makefile") |
| 44 |
FILE(GLOB_RECURSE CMAKETESTFILES "${TOPDIR}/*CTestTestfile.cmake") |
| 45 |
FILE(GLOB TOPDIRECTORIES "${TOPDIR}/lib" |
| 46 |
"${TOPDIR}/dist" |
| 47 |
"${TOPDIR}/test" |
| 48 |
) |
| 49 |
FILE(GLOB_RECURSE LIB "${TOPDIR}/*.a") |
| 50 |
FILE(GLOB_RECURSE OBJ "${TOPDIR}/*.cpp.o") |
| 51 |
|
| 52 |
# Delete files and directories specific to this project |
| 53 |
FILE(GLOB JSON "compile_commands.json") |
| 54 |
FILE(GLOB CMAKEFILES "${TOPDIR}/CMakeFiles") |
| 55 |
FILE(GLOB CMAKEFILES_NESTED "${TOPDIR}/*/CMakeFiles") |
| 56 |
FILE(GLOB CMAKEFILES_NESTED2 "${TOPDIR}/*/*/CMakeFiles") |
| 57 |
FILE(GLOB CMAKEFILES_NESTED3 "${TOPDIR}/*/*/*/CMakeFiles") |
| 58 |
|
| 59 |
# Place these files and directories into a list |
| 60 |
SET(DEL ${TOPDIRECTORIES} |
| 61 |
${EGGS} |
| 62 |
${PYCACHE} |
| 63 |
${PYC} |
| 64 |
${CBP} |
| 65 |
${LIB} |
| 66 |
${OBJ} |
| 67 |
${PYBUILDTEMP} |
| 68 |
${PYBUILDLIB} |
| 69 |
${PYBUILDBDIST} |
| 70 |
${CMAKECACHE} |
| 71 |
${CMAKEINSTALL} |
| 72 |
${MAKEFILE} |
| 73 |
${CMAKETESTFILES} |
| 74 |
${CMAKEFILES} |
| 75 |
${CMAKEFILES_NESTED} |
| 76 |
${CMAKEFILES_NESTED2} |
| 77 |
${CMAKEFILES_NESTED3} |
| 78 |
${JSON} |
| 79 |
) |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
# If we are not in the build dir, delete that as well |
| 84 |
IF(NOT (${BASEDIR} STREQUAL "build")) |
| 85 |
FILE(GLOB BUILD "${TOPDIR}/build") |
| 86 |
SET(DEL ${DEL} ${BUILD}) |
| 87 |
ENDIF() |
| 88 |
|
| 89 |
# Loop over the directories and delete each one |
| 90 |
FOREACH(D ${DEL}) |
| 91 |
IF(EXISTS ${D}) |
| 92 |
FILE(REMOVE_RECURSE ${D}) |
| 93 |
ENDIF() |
| 94 |
ENDFOREACH() |