-
Notifications
You must be signed in to change notification settings - Fork 5
/
cleanup.cmake
60 lines (42 loc) · 2.22 KB
/
cleanup.cmake
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# cmake/cleanup.cmake
##########################################################################################################
## CMake custom target to clean up the project and its working build directory
##########################################################################################################
# Clean build artifacts
# Remove CMake-generated build directory contents
file(REMOVE_RECURSE "${CMAKE_BINARY_DIR}/CMakeFiles")
file(REMOVE "${CMAKE_BINARY_DIR}/Makefile")
# Remove additional build artifacts and directories
file(REMOVE_RECURSE "${CMAKE_BINARY_DIR}/src")
file(REMOVE_RECURSE "${CMAKE_BINARY_DIR}/test")
file(REMOVE "${CMAKE_BINARY_DIR}/black_scholes_cpp")
##########################################################################################################
# Clean compiled object files and libraries
# Gather a list of generated object files and libraries
file(GLOB_RECURSE cmake_generated_files "${CMAKE_BINARY_DIR}/*.o" "${CMAKE_BINARY_DIR}/*.a")
# Iterate through the list and remove each file
foreach(file ${cmake_generated_files})
file(REMOVE "${file}")
endforeach()
##########################################################################################################
# Clean compiled executables
# Gather a list of generated executables
file(GLOB cmake_executables "${CMAKE_BINARY_DIR}/*")
# Iterate through the list and remove each file or directory
foreach(file ${cmake_executables})
# If the current item in the list is a directory and not the 'cmake' directory,
if(IS_DIRECTORY "${file}" AND NOT "${file}" STREQUAL "${CMAKE_BINARY_DIR}/cmake")
## recursively remove the directory and its contents.
file(REMOVE_RECURSE "${file}")
# Else if the current item is not a directory and not the 'CMake' directory,
elseif(NOT "${file}" STREQUAL "${CMAKE_BINARY_DIR}/cmake")
## remove the individual file.
file(REMOVE "${file}")
endif()
endforeach()
##########################################################################################################
# Clean CTest artifacts
# Remove CTest-generated testing artifacts
file(REMOVE_RECURSE "${CMAKE_BINARY_DIR}/Testing")
# Display successful cleanup message
message(STATUS "Build artifacts cleaned.")