summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-10-23 17:14:06 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2018-10-15 18:22:47 +0200
commitf36be2b942ac8d3b97c7966826a50d6e3f62a649 (patch)
treedeb6b37018132f51a31ef8b3a3a366deb8ce5d17
parent3c80b5cecf1f60dbda11cada5f7c98ce833dfc86 (diff)
Disallow build in-source.
Change-Id: If606d1ad283a37b7a2c1d4e45d8459ace2ba76c5 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
-rw-r--r--cmake/cmake.d/03-macros.cmake63
1 files changed, 37 insertions, 26 deletions
diff --git a/cmake/cmake.d/03-macros.cmake b/cmake/cmake.d/03-macros.cmake
index 3602aa8..bf297a2 100644
--- a/cmake/cmake.d/03-macros.cmake
+++ b/cmake/cmake.d/03-macros.cmake
@@ -23,34 +23,45 @@
# Customise your preferences in "./conf.d/cmake/config.cmake"
#--------------------------------------------------------------------------
# CMake 3.6 imported macros to simulate list(FILTER ...) subcommand
-# -----------------------
+#--------------------------------------------------------------------------
+MACRO(prevent_in_source_build)
+ execute_process(COMMAND rm -rf ${CMAKE_SOURCE_DIR}/CMakeCache.txt ${CMAKE_SOURCE_DIR}/CMakeCacheForScript.cmake ${CMAKE_SOURCE_DIR}/CMakeFiles ${CMAKE_SOURCE_DIR}/cmake_install.cmake)
+
+ get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" REALPATH)
+ get_filename_component(bindir "${CMAKE_BINARY_DIR}" REALPATH)
+
+ if(${srcdir} STREQUAL ${bindir})
+ message(FATAL_ERROR "${Red}**** ERROR: You trying to build the project from the source directory or a previous build in-source occured. This isn't allowed, you have to clean CMakeCache.txt file from your source directory (${srcdir}), and build from a separate directory. ****\n")
+ endif()
+ENDMACRO(prevent_in_source_build)
+
MACRO(PARSE_ARGUMENTS prefix arg_names option_names)
-SET(DEFAULT_ARGS)
-FOREACH(arg_name ${arg_names})
- SET(${prefix}_${arg_name})
-ENDFOREACH(arg_name)
-FOREACH(option ${option_names})
- SET(${prefix}_${option} FALSE)
-ENDFOREACH(option)
-
-SET(current_arg_name DEFAULT_ARGS)
-SET(current_arg_list)
-FOREACH(arg ${ARGN})
- LIST_CONTAINS(is_arg_name ${arg} ${arg_names})
- IF (is_arg_name)
- SET(${prefix}_${current_arg_name} ${current_arg_list})
- SET(current_arg_name ${arg})
+ SET(DEFAULT_ARGS)
+ FOREACH(arg_name ${arg_names})
+ SET(${prefix}_${arg_name})
+ ENDFOREACH(arg_name)
+ FOREACH(option ${option_names})
+ SET(${prefix}_${option} FALSE)
+ ENDFOREACH(option)
+
+ SET(current_arg_name DEFAULT_ARGS)
SET(current_arg_list)
- ELSE (is_arg_name)
- LIST_CONTAINS(is_option ${arg} ${option_names})
- IF (is_option)
- SET(${prefix}_${arg} TRUE)
- ELSE (is_option)
- SET(current_arg_list ${current_arg_list} ${arg})
- ENDIF (is_option)
- ENDIF (is_arg_name)
-ENDFOREACH(arg)
-SET(${prefix}_${current_arg_name} ${current_arg_list})
+ FOREACH(arg ${ARGN})
+ LIST_CONTAINS(is_arg_name ${arg} ${arg_names})
+ IF (is_arg_name)
+ SET(${prefix}_${current_arg_name} ${current_arg_list})
+ SET(current_arg_name ${arg})
+ SET(current_arg_list)
+ ELSE (is_arg_name)
+ LIST_CONTAINS(is_option ${arg} ${option_names})
+ IF (is_option)
+ SET(${prefix}_${arg} TRUE)
+ ELSE (is_option)
+ SET(current_arg_list ${current_arg_list} ${arg})
+ ENDIF (is_option)
+ ENDIF (is_arg_name)
+ ENDFOREACH(arg)
+ SET(${prefix}_${current_arg_name} ${current_arg_list})
ENDMACRO(PARSE_ARGUMENTS)
MACRO(LIST_CONTAINS var value)