Skip to content

Commit

Permalink
Trigger CMake reconfigure if iaito.pro changes and disallow in-source…
Browse files Browse the repository at this point in the history
… builds. (#184)

* Trigger CMake reconfigure if iaito.pro changes

* Disallow in-source builds with CMake

* CMake: move disallowing in source build to separate script
  • Loading branch information
thestr4ng3r authored and radare committed Jul 17, 2017
1 parent 6dd0bd1 commit 6c8adef
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/CMakeLists.txt
@@ -1,12 +1,13 @@

cmake_minimum_required(VERSION 3.1)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(DisallowInSource)

project(Iaito VERSION 1.0.0)

set(CMAKE_CXX_STANDARD 11)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
Expand Down Expand Up @@ -42,7 +43,10 @@ endif()

# Parse iaito.pro to get filenames
include(QMakeProParse)
parse_qmake_pro("${CMAKE_CURRENT_SOURCE_DIR}/iaito.pro" IAITO_PRO)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/iaito.pro"
"${CMAKE_CURRENT_BINARY_DIR}/iaito.pro"
COPYONLY) # trigger reconfigure if iaito.pro changes
parse_qmake_pro("${CMAKE_CURRENT_BINARY_DIR}/iaito.pro" IAITO_PRO)
set(SOURCE_FILES ${IAITO_PRO_SOURCES})
set(HEADER_FILES ${IAITO_PRO_HEADERS})
set(UI_FILES ${IAITO_PRO_FORMS})
Expand Down
13 changes: 13 additions & 0 deletions src/cmake/DisallowInSource.cmake
@@ -0,0 +1,13 @@
function(DisallowInSource)
get_filename_component(SRC_DIR_REALPATH "${CMAKE_SOURCE_DIR}" REALPATH)
get_filename_component(BINARY_DIR_REALPATH "${CMAKE_BINARY_DIR}" REALPATH)
if(SRC_DIR_REALPATH STREQUAL BINARY_DIR_REALPATH)
message(FATAL_ERROR " In-source builds are not allowed.
Please create a directory and run cmake from there:
mkdir build && cd build && cmake ..
This process created the file CMakeCache.txt and the directory CMakeFiles in ${CMAKE_SOURCE_DIR}.
Please delete them manually!")
endif()
endfunction()

DisallowInSource()

0 comments on commit 6c8adef

Please sign in to comment.