Is there anyway to run custom clean commands?

I'm using a CMake wrapper so a Makefile based project can build, and code navigation works in CLion. Everything pretty much works, except for clean, install, and uninstall commands in the Makefile. I know set_directory_properties can be used for cleaning specific files, but it doesn't look like it will work for running make clean. Is there anyway to add a custom command that runs when clean, install, or uninstall are invoked?

Current CMakeLists.txt (this works despite clion complaining about not being able to find running kernel headers):

cmake_minimum_required(VERSION 3.5)
project(razer-drivers)

set(SOURCES
driver/razermouse_driver.c
driver/razerfirefly_driver.c
driver/razerkbd_driver.c
driver/razercommon.c
driver/razerchromacommon.c
)

set(HEADERS
driver/razermouse_driver.h
driver/razerfirefly_driver.h
driver/razerkbd_driver.h
driver/razercommon.h
driver/razerchromacommon.h
)
#TODO add custom install, uninstall, and clean commands
add_custom_target(driver
COMMAND make driver
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
SOURCES ${HEADERS} ${SOURCES}
)

add_custom_target(driver-verbose
COMMAND make driver_verbose
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
SOURCES ${HEADERS} ${SOURCES}
)
add_custom_target(driver-clean
COMMAND make driver_clean
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
SOURCES ${HEADERS} ${SOURCES}
)
add_custom_target(driver-install
COMMAND make driver_install
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
SOURCES ${HEADERS} ${SOURCES}
)
add_custom_target(driver-uninstall
COMMAND make driver_uninstall
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
SOURCES ${HEADERS} ${SOURCES}
)
add_custom_target(lp-driver
COMMAND make lp_driver
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
SOURCES ${HEADERS} ${SOURCES}
)
add_custom_target(lp-driver-clean
COMMAND make lp_driver_clean
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
SOURCES ${HEADERS} ${SOURCES}
)

add_custom_target(daemon-install
COMMAND make daemon_install
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
SOURCES ${HEADERS} ${SOURCES}
)
add_custom_target(daemon-uninstall
COMMAND make daemon_uninstall
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
SOURCES ${HEADERS} ${SOURCES}
)
add_custom_target(python-library-install
COMMAND make python_library_install
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
SOURCES ${HEADERS} ${SOURCES}
)
add_custom_target(python-library-uninstall
COMMAND make python_library_uninstall
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
SOURCES ${HEADERS} ${SOURCES}
)
add_custom_target(setup-dkms
COMMAND make setup_dkms
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
SOURCES ${HEADERS} ${SOURCES}
)

add_custom_target(udev-install
COMMAND make udev_install
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
SOURCES ${HEADERS} ${SOURCES}
)

add_custom_target(udev-uninstall
COMMAND make udev_uninstall
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
SOURCES ${HEADERS} ${SOURCES}
)
add_custom_target(ubuntu-install
COMMAND make ubuntu_install
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
SOURCES ${HEADERS} ${SOURCES}
)

add_custom_target(fedora-install
COMMAND makefedora_install
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
SOURCES ${HEADERS} ${SOURCES}
)

 

 

1 comment
Comment actions Permalink

I too am wrapping a make-based build system for cross-platform apps and the 'clean' command is the one thing that doesn't work. It'd be great if this could be addressed.

0

Please sign in to leave a comment.