75 lines
2.9 KiB
CMake
75 lines
2.9 KiB
CMake
#[=======================================================================[.rst:
|
||
|
||
Запись результатов сборки проекта внутрь иерархии каталогов с исходными текстами
|
||
приводит к засорению файлами формируемыми на этапе сборки, которые затрудняют
|
||
разработку, поиск в оригинальных файлах и мешают ориентироваться в проекте.
|
||
При работе с несколькими типами сборки, например, отладка и выпуск, появляется
|
||
необходимость корректного полного удаления результатов предыдущего варианта.
|
||
|
||
#]=======================================================================]
|
||
|
||
include_guard(GLOBAL)
|
||
|
||
get_filename_component(cmake_source_dir "${CMAKE_SOURCE_DIR}" REALPATH)
|
||
get_filename_component(cmake_binary_dir "${CMAKE_BINARY_DIR}" REALPATH)
|
||
get_filename_component(project_source_dir "${PROJECT_SOURCE_DIR}" REALPATH)
|
||
get_filename_component(project_binary_dir "${PROJECT_BINARY_DIR}" REALPATH)
|
||
get_filename_component(cmake_install_prefix "${CMAKE_INSTALL_PREFIX}" REALPATH)
|
||
|
||
if(cmake_install_prefix STREQUAL cmake_binary_dir)
|
||
myx_message_fatal_error(
|
||
"Myx: Cannot install into build directory ${CMAKE_INSTALL_PREFIX}.")
|
||
endif()
|
||
|
||
if(cmake_install_prefix STREQUAL cmake_source_dir)
|
||
myx_message_fatal_error(
|
||
"Myx: Cannot install into source directory ${CMAKE_INSTALL_PREFIX}.")
|
||
endif()
|
||
|
||
if(cmake_install_prefix STREQUAL project_binary_dir)
|
||
myx_message_fatal_error(
|
||
"Myx: Cannot install into build directory ${CMAKE_INSTALL_PREFIX}.")
|
||
endif()
|
||
|
||
if(cmake_install_prefix STREQUAL project_source_dir)
|
||
myx_message_fatal_error(
|
||
"Myx: Cannot install into source directory ${CMAKE_INSTALL_PREFIX}.")
|
||
endif()
|
||
|
||
if(cmake_binary_dir STREQUAL cmake_source_dir)
|
||
myx_message_fatal_error(
|
||
"Myx: Cannot build in source directory ${CMAKE_SOURCE_DIR}")
|
||
endif()
|
||
|
||
if(project_binary_dir STREQUAL project_source_dir)
|
||
myx_message_fatal_error(
|
||
"Myx: Cannot build in source directory ${CMAKE_SOURCE_DIR}")
|
||
endif()
|
||
|
||
# Очистка от сгенерированных файлов
|
||
file(GLOB_RECURSE cmakelists_files RELATIVE ${cmake_source_dir} CMakeLists.txt)
|
||
foreach(it ${cmakelists_files})
|
||
get_filename_component(file ${it} REALPATH)
|
||
get_filename_component(dir ${file} DIRECTORY)
|
||
file(REMOVE_RECURSE
|
||
${dir}/.cmake
|
||
${dir}/CMakeFiles)
|
||
file(REMOVE
|
||
${dir}/CMakeFiles
|
||
${dir}/CMakeCache.txt
|
||
${dir}/cmake_install.cmake
|
||
${dir}/compile_commands.json
|
||
${dir}/Makefile
|
||
${dir}/.ninja_deps
|
||
${dir}/.ninja_logs
|
||
${dir}/build.ninja
|
||
${dir}/rules.ninja)
|
||
endforeach()
|
||
|
||
unset(cmakelists_files)
|
||
unset(cmake_source_dir)
|
||
unset(cmake_binary_dir)
|
||
unset(project_source_dir)
|
||
unset(project_binary_dir)
|
||
unset(cmake_install_prefix)
|