Skip to content

Commit e8ac980

Browse files
pedro-wSiegeLord
authored andcommitted
Add check to prevent in-source builds
Also update minimum cmake version in README.md to match CMakeLists.txt
1 parent 0aeca8c commit e8ac980

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ string(REPLACE "." "" ALLEGRO_DLL_SHORTVER ${ALLEGRO_SOVERSION})
5959
# Search in the `cmake' directory for additional CMake modules.
6060
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
6161

62+
# Reject in-source builds
63+
include(PreventInSourceBuilds)
64+
6265
# Search in `deps' directories for dependency files.
6366
file(GLOB deps_subdirs
6467
"${PROJECT_SOURCE_DIR}/deps"

README.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Requirements
4141
We assume you have C and C++ compilers installed and functioning.
4242
We support gcc, clang and MSVC.
4343

44-
Allegro also requires CMake 2.8.5 or later to build.
44+
Allegro also requires CMake 3.0 or later to build.
4545
You may download it from <http://www.cmake.org/>
4646

4747

@@ -166,6 +166,16 @@ installed on your system. At the same time, you may select options to
166166
customise your build. If you are unsure of what you are doing, leave all the
167167
options at the defaults.
168168

169+
You must configure Allegro with a separate build directory. For example,
170+
171+
mkdir build
172+
cd build
173+
cmake ..
174+
175+
If you configure Allegro to build in the source directory (i.e. `cmake .`)
176+
you will get an error message. Delete `CMakeCache.txt` and the `CMakeFiles`
177+
directory and re-configure as described above.
178+
169179
Once the configuration step is successful, you will invoke another tool to
170180
build Allegro. The tool depends on your compiler, but is usually either
171181
`make`, or your IDE.

cmake/PreventInSourceBuilds.cmake

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# This function will prevent in-source builds
2+
# Based on https://github.com/InsightSoftwareConsortium/ITK/blob/1b5da45dc706e6d6803b52740fa50e0e5e7705e9/CMake/PreventInSourceBuilds.cmake
3+
function(PreventInSourceBuilds)
4+
# make sure the user doesn't play dirty with symlinks
5+
get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" REALPATH)
6+
get_filename_component(bindir "${CMAKE_BINARY_DIR}" REALPATH)
7+
8+
# disallow in-source builds
9+
if("${srcdir}" STREQUAL "${bindir}")
10+
message(FATAL_ERROR
11+
"Allegro must not be configured to build in the source directory.\n"
12+
"Please refer to README.md\n"
13+
"Quitting configuration step")
14+
endif()
15+
endfunction()
16+
17+
PreventInSourceBuilds()

0 commit comments

Comments
 (0)