pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

pkgsrc: add CMAKE_PKGSRC_BUILD_FLAGS for pkgsrc build to set opts



details:   https://anonhg.NetBSD.org/pkgsrc/rev/4100ec36e9bc
branches:  trunk
changeset: 306013:4100ec36e9bc
user:      chuck <chuck%pkgsrc.org@localhost>
date:      Sun Apr 08 19:09:45 2018 +0000
description:
add CMAKE_PKGSRC_BUILD_FLAGS for pkgsrc build to set opts

With pkgsrc built packages, the goal is to have the user's compiler
optimization flags set by the user using CFLAGS, etc.   To that end,
the cmake Makefile has subst.mk code to "sed -e 's,-O.,,'" out opt.
flags in Modules/Compiler/*.cmake for cmake compiles with the
CMAKE_BUILD_TYPE set (e.g. to Release).

Unfortunately, this sed-based approach has two drawbacks: First, it
gets applied to packages build with cmake outside of pkgsrc (changing
the semantics of -DCMAKE_BUILD_TYPE=Release in an unexpected way by
remove -O flags from it).   Second, the sed expression damages some
of the Modules/Compiler/*.cmake as not all opt flags match the "-O."
regular expression.

To address this we:
  1. remove the subst.mk sed operation on Modules/Compiler/*.cmake
  2. add a new config variable CMAKE_PKGSRC_BUILD_FLAGS that should
     be set for pkgsrc-based cmake builds (e.g. in mk/configure/cmake.mk)
  3. we add a patch for Modules/Compiler/GNU.cmake to look for
     CMAKE_PKGSRC_BUILD_FLAGS and choose a set of non-opt compiler
     flags when this is set (to provide the desired behavior under pksrc).
     note that the GNU.cmake file is also used by clang.   We can
     make the corresponding changes to other compilers if desired.

The result is that cmake compiles under pkgsrc set CMAKE_PKGSRC_BUILD_FLAGS
and follow CFLAGS, etc. (bypassing CMAKE_BUILD_TYPE), but cmake compiles
outside of pkgsrc follow the standard cmake semantics for CMAKE_BUILD_TYPE.
Also, we no longer damage Modules/Compiler/*.cmake with sed.

diffstat:

 devel/cmake/Makefile                                 |  10 +-----
 devel/cmake/distinfo                                 |   3 +-
 devel/cmake/patches/patch-Modules_Compiler_GNU.cmake |  27 ++++++++++++++++++++
 3 files changed, 31 insertions(+), 9 deletions(-)

diffs (72 lines):

diff -r 01947be22b0e -r 4100ec36e9bc devel/cmake/Makefile
--- a/devel/cmake/Makefile      Sun Apr 08 11:51:30 2018 +0000
+++ b/devel/cmake/Makefile      Sun Apr 08 19:09:45 2018 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.141 2018/04/02 19:36:44 adam Exp $
+# $NetBSD: Makefile,v 1.142 2018/04/08 19:09:45 chuck Exp $
 
 .include "Makefile.version"
 
@@ -51,14 +51,8 @@
 SUBST_FILES.cmake+=    Modules/Platform/UnixPaths.cmake
 SUBST_VARS.cmake=      LOCALBASE X11BASE
 
-SUBST_CLASSES+=                flags
-SUBST_STAGE.flags=     pre-configure
-SUBST_MESSAGE.flags=   Fixing compiler flags.
-SUBST_FILES.flags=     Modules/Compiler/*.cmake
-SUBST_SED.flags=       -e 's,-O.,,'
-
 pre-configure:
-       ${RM} -f ${WRKSRC}/Modules/*.orig ${WRKSRC}/Modules/Platform/*.orig
+       ${RM} -f ${WRKSRC}/Modules/*.orig ${WRKSRC}/Modules/Compiler/*.orig ${WRKSRC}/Modules/Platform/*.orig
        ${LN} -f ${WRKSRC}/Modules/Platform/OpenBSD.cmake ${WRKSRC}/Modules/Platform/MirBSD.cmake
 .for lang in C CXX Fortran
        ${LN} -f ${WRKSRC}/Modules/Platform/SunOS-GNU-${lang}.cmake \
diff -r 01947be22b0e -r 4100ec36e9bc devel/cmake/distinfo
--- a/devel/cmake/distinfo      Sun Apr 08 11:51:30 2018 +0000
+++ b/devel/cmake/distinfo      Sun Apr 08 19:09:45 2018 +0000
@@ -1,10 +1,11 @@
-$NetBSD: distinfo,v 1.115 2018/04/02 19:36:44 adam Exp $
+$NetBSD: distinfo,v 1.116 2018/04/08 19:09:45 chuck Exp $
 
 SHA1 (cmake-3.11.0.tar.gz) = 7851f87185f80e260ea634d5985ec9215fe408c8
 RMD160 (cmake-3.11.0.tar.gz) = 66ae49e6e10679dd56aa05269a6321b9269a5cd5
 SHA512 (cmake-3.11.0.tar.gz) = 03b058483d236d4f4427c93cc41af77068c243fc4b6f24aeaf2daf97af215bc664bc1b733195463af4cfc94ec70076710f425661859d752ddf3b9610adca9834
 Size (cmake-3.11.0.tar.gz) = 7948287 bytes
 SHA1 (patch-CMakeLists.txt) = a0b03f2fad5ea174095c4fe52cea67d94cf46e2d
+SHA1 (patch-Modules_Compiler_GNU.cmake) = e091c53ac3f3a6cd811119d3231563df32e76bf9
 SHA1 (patch-Modules_FindCurses.cmake) = 09fcd7adfbc2dfc2cd8af4e047d870a5243d77dc
 SHA1 (patch-Modules_FindPythonInterp.cmake) = d1b39bdcd654f2a4fc63463cd20de656cce3cf8f
 SHA1 (patch-Modules_FindPythonLibs.cmake) = b5cedc6a2354beaf08e06d416c150154a7dc1f05
diff -r 01947be22b0e -r 4100ec36e9bc devel/cmake/patches/patch-Modules_Compiler_GNU.cmake
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/devel/cmake/patches/patch-Modules_Compiler_GNU.cmake      Sun Apr 08 19:09:45 2018 +0000
@@ -0,0 +1,27 @@
+$NetBSD: patch-Modules_Compiler_GNU.cmake,v 1.1 2018/04/08 19:09:46 chuck Exp $
+
+Add CMAKE_PKGSRC_BUILD_FLAGS to allow pkgsrc-based builds to set
+compiler optimizer flags (overrides CMAKE_BUILD_TYPE).  Also enabled
+for CMAKE_BOOTSTRAP so it is applied to the build of cmake itself.
+
+--- Modules/Compiler/GNU.cmake.orig    2018-03-16 07:16:31.000000000 -0400
++++ Modules/Compiler/GNU.cmake 2018-04-07 16:23:51.000000000 -0400
+@@ -39,9 +39,15 @@
+   # Initial configuration flags.
+   string(APPEND CMAKE_${lang}_FLAGS_INIT " ")
+   string(APPEND CMAKE_${lang}_FLAGS_DEBUG_INIT " -g")
+-  string(APPEND CMAKE_${lang}_FLAGS_MINSIZEREL_INIT " -Os -DNDEBUG")
+-  string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT " -O3 -DNDEBUG")
+-  string(APPEND CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT " -O2 -g -DNDEBUG")
++  if(CMAKE_BOOTSTRAP OR CMAKE_PKGSRC_BUILD_FLAGS)
++    string(APPEND CMAKE_${lang}_FLAGS_MINSIZEREL_INIT " -DNDEBUG")
++    string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT " -DNDEBUG")
++    string(APPEND CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT " -g -DNDEBUG")
++  else()
++    string(APPEND CMAKE_${lang}_FLAGS_MINSIZEREL_INIT " -Os -DNDEBUG")
++    string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT " -O3 -DNDEBUG")
++    string(APPEND CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT " -O2 -g -DNDEBUG")
++  endif()
+   set(CMAKE_${lang}_CREATE_PREPROCESSED_SOURCE "<CMAKE_${lang}_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
+   set(CMAKE_${lang}_CREATE_ASSEMBLY_SOURCE "<CMAKE_${lang}_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -S <SOURCE> -o <ASSEMBLY_SOURCE>")
+   if(NOT APPLE OR NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 4) # work around #4462



Home | Main Index | Thread Index | Old Index