From 2af1671e51f9be897601fad28b1e28e226fbe5ac Mon Sep 17 00:00:00 2001 From: Igor Raits Date: Fri, 3 Jul 2020 17:12:56 +0200 Subject: [PATCH] Add out-of-source builds controlled by a macro This will allow us to port packages to the %cmake_build/%cmake_install even on older Fedora with possibility to easily opt-in for out-of-source builds by `%global __cmake_out_of_source_build 1`. In future we will make it opt-out (`%global __cmake_out_of_source_build 0` will do in-source builds again). Signed-off-by: Igor Raits --- cmake.spec | 5 ++++- macros.cmake | 12 ++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/cmake.spec b/cmake.spec index 264d11c..8fcaa99 100644 --- a/cmake.spec +++ b/cmake.spec @@ -67,7 +67,7 @@ Name: %{orig_name}%{?name_suffix} Version: %{major_version}.%{minor_version}.0 -Release: 0.5%{?relsuf}%{?dist} +Release: 0.6%{?relsuf}%{?dist} Summary: Cross-platform make system # most sources are BSD @@ -503,6 +503,9 @@ mv -f Modules/FindLibArchive.disabled Modules/FindLibArchive.cmake %changelog +* Fri Jul 03 2020 Igor Raits - 3.18.0-0.6.rc2 +- Add out-of-source builds controlled by a macro (%%__cmake_out_of_source_build) + * Wed Jul 01 2020 Igor Raits - 3.18.0-0.5.rc2 - Undo out-of-source-builds diff --git a/macros.cmake b/macros.cmake index 0bf1119..d0e524e 100644 --- a/macros.cmake +++ b/macros.cmake @@ -7,6 +7,8 @@ %_cmake_version @@CMAKE_VERSION@@ %__cmake /usr/bin/cmake %__ctest /usr/bin/ctest +%__cmake_out_of_source_build 0 +%__cmake_builddir %[%{?__cmake_out_of_source_build} ? "%{_vpath_builddir}" : "."] # - Set default compile flags # - CMAKE_*_FLAGS_RELEASE are added *after* the *FLAGS environment variables @@ -25,6 +27,8 @@ %{?__global_ldflags:LDFLAGS="${LDFLAGS:-%__global_ldflags}" ; export LDFLAGS ;} \ %endif \ %__cmake \\\ + -S "%{_vpath_srcdir}" \\\ + -B "%{__cmake_builddir}" \\\ -DCMAKE_C_FLAGS_RELEASE:STRING="-DNDEBUG" \\\ -DCMAKE_CXX_FLAGS_RELEASE:STRING="-DNDEBUG" \\\ -DCMAKE_Fortran_FLAGS_RELEASE:STRING="-DNDEBUG" \\\ @@ -37,16 +41,16 @@ %if "%{?_lib}" == "lib64" \ %{?_cmake_lib_suffix64} \\\ %endif \ - %{?_cmake_shared_libs} + %{?_cmake_shared_libs} %cmake_build \ - %__cmake --build "%{_vpath_builddir}" %{?_smp_mflags} --verbose + %__cmake --build "%{__cmake_builddir}" %{?_smp_mflags} --verbose %cmake_install \ - DESTDIR="%{buildroot}" %__cmake --install "%{_vpath_builddir}" + DESTDIR="%{buildroot}" %__cmake --install "%{__cmake_builddir}" %ctest(:-:) \ - cd "%{_vpath_builddir}" \ + cd "%{__cmake_builddir}" \ %__ctest --output-on-failure --force-new-ctest-process %{?_smp_mflags} %{**} \ cd -