In my CMake project, I’m using the code below to detect in-source builds:
cmake_minimum_required(VERSION 3.29)
project( NoInSource )
function( NoInSourceBuilds )
if ( ${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR} )
execute_process(COMMAND ${CMAKE_COMMAND} -E rm CMakeCache.txt)
message(FATAL_ERROR "In-source builds are not allowed!")
endif()
endfunction()
NoInSourceBuilds()
message( "Won't get here")
(Base on code from: Preventing in-source builds)
Is there a way to remove the generated files prior to exiting?
The code above fails to delete the CMakeCache.txt file 🙁