forked from lijiext/lammps
cmake: prevent in-source build
This commit is contained in:
parent
e4d4f3a775
commit
2da999d864
|
@ -69,6 +69,8 @@ get_lammps_version(${LAMMPS_SOURCE_DIR}/version.h LAMMPS_VERSION)
|
|||
# Cmake modules/macros are in a subdirectory to keep this file cleaner
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/Modules)
|
||||
|
||||
include(PreventInSourceBuilds)
|
||||
|
||||
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CXX_FLAGS)
|
||||
#release comes with -O3 by default
|
||||
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE)
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
# - Prevent in-source builds.
|
||||
# https://stackoverflow.com/questions/1208681/with-cmake-how-would-you-disable-in-source-builds/
|
||||
|
||||
function(prevent_in_source_builds)
|
||||
# make sure the user doesn't play dirty with symlinks
|
||||
get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" REALPATH)
|
||||
get_filename_component(srcdir2 "${CMAKE_SOURCE_DIR}/.." REALPATH)
|
||||
get_filename_component(bindir "${CMAKE_BINARY_DIR}" REALPATH)
|
||||
|
||||
# disallow in-source builds
|
||||
if("${srcdir}" STREQUAL "${bindir}" OR "${srcdir2}" STREQUAL "${bindir}")
|
||||
message(FATAL_ERROR "\
|
||||
|
||||
CMake must not to be run in the source directory. \
|
||||
Rather create a dedicated build directory and run CMake there. \
|
||||
To clean up after this aborted in-place compilation:
|
||||
rm -r CMakeCache.txt CMakeFiles
|
||||
")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
prevent_in_source_builds()
|
Loading…
Reference in New Issue