2022-10-01 13:42:36 +00:00
|
|
|
|
#[=======================================================================[.rst:
|
|
|
|
|
|
|
|
|
|
Запись результатов сборки проекта внутрь иерархии каталогов с исходными текстами
|
|
|
|
|
приводит к засорению файлами формируемыми на этапе сборки, которые затрудняют
|
|
|
|
|
разработку, поиск в оригинальных файлах и мешают ориентироваться в проекте.
|
|
|
|
|
При работе с несколькими типами сборки, например, отладка и выпуск, появляется
|
|
|
|
|
необходимость корректного полного удаления результатов предыдущего варианта.
|
|
|
|
|
|
|
|
|
|
#]=======================================================================]
|
2022-09-28 23:46:29 +00:00
|
|
|
|
|
|
|
|
|
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)
|
2022-10-04 03:59:45 +00:00
|
|
|
|
myx_message_fatal_error(
|
2022-09-28 23:46:29 +00:00
|
|
|
|
"Myx: Cannot install into build directory ${CMAKE_INSTALL_PREFIX}.")
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(cmake_install_prefix STREQUAL cmake_source_dir)
|
2022-10-04 03:59:45 +00:00
|
|
|
|
myx_message_fatal_error(
|
2022-09-28 23:46:29 +00:00
|
|
|
|
"Myx: Cannot install into source directory ${CMAKE_INSTALL_PREFIX}.")
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(cmake_install_prefix STREQUAL project_binary_dir)
|
2022-10-04 03:59:45 +00:00
|
|
|
|
myx_message_fatal_error(
|
2022-09-28 23:46:29 +00:00
|
|
|
|
"Myx: Cannot install into build directory ${CMAKE_INSTALL_PREFIX}.")
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(cmake_install_prefix STREQUAL project_source_dir)
|
2022-10-04 03:59:45 +00:00
|
|
|
|
myx_message_fatal_error(
|
2022-09-28 23:46:29 +00:00
|
|
|
|
"Myx: Cannot install into source directory ${CMAKE_INSTALL_PREFIX}.")
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(cmake_binary_dir STREQUAL cmake_source_dir)
|
2022-10-04 03:59:45 +00:00
|
|
|
|
myx_message_fatal_error(
|
2022-09-28 23:46:29 +00:00
|
|
|
|
"Myx: Cannot build in source directory ${CMAKE_SOURCE_DIR}")
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
if(project_binary_dir STREQUAL project_source_dir)
|
2022-10-04 03:59:45 +00:00
|
|
|
|
myx_message_fatal_error(
|
2022-09-28 23:46:29 +00:00
|
|
|
|
"Myx: Cannot build in source directory ${CMAKE_SOURCE_DIR}")
|
|
|
|
|
endif()
|
|
|
|
|
|
2022-10-06 13:15:46 +00:00
|
|
|
|
# Очистка от сгенерированных файлов
|
|
|
|
|
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)
|
2022-09-28 23:46:29 +00:00
|
|
|
|
unset(cmake_source_dir)
|
|
|
|
|
unset(cmake_binary_dir)
|
|
|
|
|
unset(project_source_dir)
|
|
|
|
|
unset(project_binary_dir)
|
|
|
|
|
unset(cmake_install_prefix)
|