On 2020/11/20 20:49, Rafael Sadowski wrote: > I would like to add an new cmake module option. > > MODCMAKE_PORT_BUILD: > If set to `Yes', CMake will set all necessary options for a port build. > This does not change any default settings for use outside the ports > tree. Default value is `Yes'. > > I have tested it with some ports and it works as desired. > > I look forward to feedback and OKs. > > Rafael > > > Index: port-modules.5 > =================================================================== > RCS file: /cvs/src/share/man/man5/port-modules.5,v > retrieving revision 1.248 > diff -u -p -r1.248 port-modules.5 > --- port-modules.5 9 Oct 2020 13:24:43 -0000 1.248 > +++ port-modules.5 17 Nov 2020 20:33:05 -0000 > @@ -567,6 +567,10 @@ Changes > to `test' as this is standard for CMake projects. > Also this module has the following knobs: > .Bl -tag -width Ds > +.It MODCMAKE_PORT_BUILD > +If set to `Yes', CMake will set all necessary options for a port build. > +This does not change any default settings for use outside the ports > +tree. Default value is `Yes'. > .It MODCMAKE_WANTCOLOR > If set to `Yes', CMake will colorize its output. > Should not be used in ports Makefiles.
I'd prefer to skip the port-modules variable unless there's a real need (I don't think there will be though, do you?) i.e. like the diff below. Index: Makefile =================================================================== RCS file: /cvs/ports/devel/cmake/Makefile,v retrieving revision 1.187 diff -u -p -r1.187 Makefile --- Makefile 23 Oct 2020 13:44:30 -0000 1.187 +++ Makefile 20 Nov 2020 19:58:26 -0000 @@ -8,6 +8,7 @@ VER = 3.17.5 EPOCH = 0 DISTNAME = cmake-${VER} CATEGORIES = devel +REVISION = 0 HOMEPAGE = https://www.cmake.org/ Index: cmake.port.mk =================================================================== RCS file: /cvs/ports/devel/cmake/cmake.port.mk,v retrieving revision 1.67 diff -u -p -r1.67 cmake.port.mk --- cmake.port.mk 17 Nov 2020 19:33:55 -0000 1.67 +++ cmake.port.mk 20 Nov 2020 20:02:08 -0000 @@ -121,6 +121,9 @@ TEST_TARGET ?= test MODCMAKE_WANTCOLOR ?= No MODCMAKE_VERBOSE ?= Yes +# Disable cmake's default optimization flags, putting them under ports control +MAKE_ENV += MODCMAKE_PORT_BUILD=yes + .if ${MODCMAKE_WANTCOLOR:L} == "yes" && defined(TERM) MAKE_ENV += TERM=${TERM} .endif @@ -128,4 +131,3 @@ MAKE_ENV += TERM=${TERM} .if ${MODCMAKE_VERBOSE:L} == "yes" MAKE_ENV += VERBOSE=1 .endif - Index: patches/patch-Modules_Compiler_G95-Fortran_cmake =================================================================== RCS file: /cvs/ports/devel/cmake/patches/patch-Modules_Compiler_G95-Fortran_cmake,v retrieving revision 1.4 diff -u -p -r1.4 patch-Modules_Compiler_G95-Fortran_cmake --- patches/patch-Modules_Compiler_G95-Fortran_cmake 28 Nov 2016 09:15:13 -0000 1.4 +++ patches/patch-Modules_Compiler_G95-Fortran_cmake 20 Nov 2020 19:58:26 -0000 @@ -1,13 +1,22 @@ $OpenBSD: patch-Modules_Compiler_G95-Fortran_cmake,v 1.4 2016/11/28 09:15:13 dcoppa Exp $ ---- Modules/Compiler/G95-Fortran.cmake.orig Sat Nov 26 12:29:14 2016 -+++ Modules/Compiler/G95-Fortran.cmake Sat Nov 26 12:29:44 2016 -@@ -1,8 +1,6 @@ +Index: Modules/Compiler/G95-Fortran.cmake +--- Modules/Compiler/G95-Fortran.cmake.orig ++++ Modules/Compiler/G95-Fortran.cmake +@@ -1,8 +1,13 @@ string(APPEND CMAKE_Fortran_FLAGS_INIT " ") - string(APPEND CMAKE_Fortran_FLAGS_DEBUG_INIT " -g") +-string(APPEND CMAKE_Fortran_FLAGS_DEBUG_INIT " -g") -string(APPEND CMAKE_Fortran_FLAGS_MINSIZEREL_INIT " -Os") -string(APPEND CMAKE_Fortran_FLAGS_RELEASE_INIT " -O3") -string(APPEND CMAKE_Fortran_FLAGS_RELWITHDEBINFO_INIT " -O2 -g") -+string(APPEND CMAKE_Fortran_FLAGS_RELWITHDEBINFO_INIT " -g") ++if(DEFINED ENV{MODCMAKE_PORT_BUILD}) ++ string(APPEND CMAKE_Fortran_FLAGS_DEBUG_INIT " -g") ++ string(APPEND CMAKE_Fortran_FLAGS_RELWITHDEBINFO_INIT " -g") ++else() ++ string(APPEND CMAKE_Fortran_FLAGS_DEBUG_INIT " -g") ++ string(APPEND CMAKE_Fortran_FLAGS_MINSIZEREL_INIT " -Os") ++ string(APPEND CMAKE_Fortran_FLAGS_RELEASE_INIT " -O3") ++ string(APPEND CMAKE_Fortran_FLAGS_RELWITHDEBINFO_INIT " -O2 -g") ++endif() set(CMAKE_Fortran_MODDIR_FLAG "-fmod=") set(CMAKE_Fortran_VERBOSE_FLAG "-v") set(CMAKE_Fortran_FORMAT_FIXED_FLAG "-ffixed-form") Index: patches/patch-Modules_Compiler_GNU-Fortran_cmake =================================================================== RCS file: /cvs/ports/devel/cmake/patches/patch-Modules_Compiler_GNU-Fortran_cmake,v retrieving revision 1.8 diff -u -p -r1.8 patch-Modules_Compiler_GNU-Fortran_cmake --- patches/patch-Modules_Compiler_GNU-Fortran_cmake 21 Aug 2019 05:47:40 -0000 1.8 +++ patches/patch-Modules_Compiler_GNU-Fortran_cmake 20 Nov 2020 19:58:26 -0000 @@ -2,14 +2,18 @@ $OpenBSD: patch-Modules_Compiler_GNU-For Index: Modules/Compiler/GNU-Fortran.cmake --- Modules/Compiler/GNU-Fortran.cmake.orig +++ Modules/Compiler/GNU-Fortran.cmake -@@ -12,10 +12,6 @@ set(CMAKE_Fortran_FORMAT_FREE_FLAG "-ffree-form") +@@ -12,9 +12,11 @@ set(CMAKE_Fortran_FORMAT_FREE_FLAG "-ffree-form") set(CMAKE_Fortran_POSTPROCESS_FLAG "-fpreprocessed") -# No -DNDEBUG for Fortran. -string(APPEND CMAKE_Fortran_FLAGS_MINSIZEREL_INIT " -Os") -string(APPEND CMAKE_Fortran_FLAGS_RELEASE_INIT " -O3") -- ++if(NOT DEFINED ENV{MODCMAKE_PORT_BUILD}) ++ # No -DNDEBUG for Fortran. ++ string(APPEND CMAKE_Fortran_FLAGS_MINSIZEREL_INIT " -Os") ++ string(APPEND CMAKE_Fortran_FLAGS_RELEASE_INIT " -O3") ++endif() + # No -isystem for Fortran because it will not find .mod files. unset(CMAKE_INCLUDE_SYSTEM_FLAG_Fortran) - Index: patches/patch-Modules_Compiler_GNU_cmake =================================================================== RCS file: /cvs/ports/devel/cmake/patches/patch-Modules_Compiler_GNU_cmake,v retrieving revision 1.14 diff -u -p -r1.14 patch-Modules_Compiler_GNU_cmake --- patches/patch-Modules_Compiler_GNU_cmake 11 Jan 2020 08:01:09 -0000 1.14 +++ patches/patch-Modules_Compiler_GNU_cmake 20 Nov 2020 19:58:26 -0000 @@ -2,16 +2,26 @@ $OpenBSD: patch-Modules_Compiler_GNU_cma Index: Modules/Compiler/GNU.cmake --- Modules/Compiler/GNU.cmake.orig +++ Modules/Compiler/GNU.cmake -@@ -54,9 +54,9 @@ macro(__compiler_gnu lang) +@@ -53,10 +53,18 @@ macro(__compiler_gnu lang) + # Initial configuration flags. string(APPEND CMAKE_${lang}_FLAGS_INIT " ") - string(APPEND CMAKE_${lang}_FLAGS_DEBUG_INIT " -g") +- 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") -+ 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") ++ if(DEFINED ENV{MODCMAKE_PORT_BUILD}) ++ string(APPEND CMAKE_${lang}_FLAGS_DEBUG_INIT " -g") ++ 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_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") ++ 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