From 357ed48e0ec0df8cda9899fe59ff9af5228ca922 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 29 Oct 2020 12:57:30 +0300 Subject: [PATCH] Add PreventInSourceBuild.cmake. GitOrigin-RevId: a774b5aa7adbeb3ba974ff55a3de52f7d6371a49 --- CMake/PreventInSourceBuild.cmake | 14 ++++++++++++++ CMakeLists.txt | 26 +++++++------------------- 2 files changed, 21 insertions(+), 19 deletions(-) create mode 100644 CMake/PreventInSourceBuild.cmake diff --git a/CMake/PreventInSourceBuild.cmake b/CMake/PreventInSourceBuild.cmake new file mode 100644 index 000000000..1815e82a2 --- /dev/null +++ b/CMake/PreventInSourceBuild.cmake @@ -0,0 +1,14 @@ +function(prevent_in_source_build) + get_filename_component(REAL_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" REALPATH) + get_filename_component(REAL_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}" REALPATH) + + if (REAL_BINARY_DIR STREQUAL REAL_SOURCE_DIR) + message(" Out-of-source build must be used. Remove the files already") + message(" created by CMake and rerun CMake from a new directory:") + message(" rm -rf CMakeFiles CMakeCache.txt") + message(" mkdir build") + message(" cd build") + message(" cmake ..") + message(FATAL_ERROR "In-source build failed.") + endif() +endfunction() diff --git a/CMakeLists.txt b/CMakeLists.txt index bf0e1b38b..6878514d2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,11 @@ cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR) project(TDLib VERSION 1.6.9 LANGUAGES CXX C) +if (NOT DEFINED CMAKE_MODULE_PATH) + set(CMAKE_MODULE_PATH "") +endif() +set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake" "${CMAKE_MODULE_PATH}") + if (NOT DEFINED CMAKE_INSTALL_LIBDIR) set(CMAKE_INSTALL_LIBDIR "lib") endif() @@ -17,20 +22,8 @@ if (POLICY CMP0054) cmake_policy(SET CMP0054 NEW) endif() -# Prevent in-source build -get_filename_component(TD_REAL_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" REALPATH) -get_filename_component(TD_REAL_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}" REALPATH) - -if (TD_REAL_BINARY_DIR STREQUAL TD_REAL_SOURCE_DIR) - message(" Out-of-source build should be used to build TDLib.") - message(" You need to remove the files already created by CMake and") - message(" rerun CMake from a new directory:") - message(" rm -rf CMakeFiles CMakeCache.txt") - message(" mkdir build") - message(" cd build") - message(" cmake ..") - message(FATAL_ERROR "In-source build failed.") -endif() +include(PreventInSourceBuild) +prevent_in_source_build() option(TD_ENABLE_JNI "Use \"ON\" to enable JNI-compatible TDLib API.") option(TD_ENABLE_DOTNET "Use \"ON\" to enable generation of C++/CLI or C++/CX TDLib API bindings.") @@ -39,11 +32,6 @@ if (TD_ENABLE_DOTNET AND (CMAKE_VERSION VERSION_LESS "3.1.0")) message(FATAL_ERROR "CMake 3.1.0 or higher is required. You are running version ${CMAKE_VERSION}.") endif() -if (NOT DEFINED CMAKE_MODULE_PATH) - set(CMAKE_MODULE_PATH "") -endif() -set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake" "${CMAKE_MODULE_PATH}") - set(CMAKE_EXPORT_COMPILE_COMMANDS 1) set(CMAKE_POSITION_INDEPENDENT_CODE ON)