On Mon Jan 26, 2026 at 03:05:32PM +0100, Claudio Jeker wrote:
> ports-gcc is modern enough to support -flto but our binutils and ld in
> base are not. So compiles break whenever lto is enabled on archs like
> sparc64.
>
> This diff disables -flto and -fno-fat-lto-objects for OpenBSD which is
> maybe a big hammer but the simplest fix I came up with.
We could hide it with MODCMAKE_PORT_BUILD like. MODCMAKE_PORT_BUILD
only defined during ports build. This changes the behaviour only for
ports, but not for end users, who receive it as expected by cmake
behaviour.
if(NOT DEFINED ENV{MODCMAKE_PORT_BUILD})
...
...
all GCC lto stuf..
...
...
endif()
for example:
--- Modules/Compiler/GNU.cmake.orig Mon Jan 26 15:14:23 2026
+++ Modules/Compiler/GNU.cmake Mon Jan 26 15:22:20 2026
@@ -95,24 +95,26 @@ macro(__compiler_gnu lang)
# *
https://gcc.gnu.org/onlinedocs/gcc-10.1.0/gcc/Optimize-Options.html#Optimize-Options
(yes)
# Since GCC 12.1, the abundance of a parameter produces a warning if
compiling multiple targets.
# FIXME: What version of GCC for Windows added support for -flto=auto?
10.3 does not have it.
- if(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 11.0)
- list(APPEND __lto_flags -flto=auto)
- elseif(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 10.1)
- if (CMAKE_HOST_WIN32)
- list(APPEND __lto_flags -flto=1)
- else()
+ if(NOT DEFINED ENV{MODCMAKE_PORT_BUILD})
+ if(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 11.0)
list(APPEND __lto_flags -flto=auto)
+ elseif(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 10.1)
+ if (CMAKE_HOST_WIN32)
+ list(APPEND __lto_flags -flto=1)
+ else()
+ list(APPEND __lto_flags -flto=auto)
+ endif()
+ else()
+ list(APPEND __lto_flags -flto)
endif()
- else()
- list(APPEND __lto_flags -flto)
- endif()
- if(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 4.7 AND NOT APPLE)
- # '-ffat-lto-objects' introduced since GCC 4.7:
- # * https://gcc.gnu.org/onlinedocs/gcc-4.6.4/gcc/Option-Summary.html (no)
- # * https://gcc.gnu.org/onlinedocs/gcc-4.7.4/gcc/Option-Summary.html
(yes)
- list(APPEND __lto_flags -fno-fat-lto-objects)
- endif()
+ if(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 4.7 AND NOT APPLE)
+ # '-ffat-lto-objects' introduced since GCC 4.7:
+ # * https://gcc.gnu.org/onlinedocs/gcc-4.6.4/gcc/Option-Summary.html
(no)
+ # * https://gcc.gnu.org/onlinedocs/gcc-4.7.4/gcc/Option-Summary.html
(yes)
+ list(APPEND __lto_flags -fno-fat-lto-objects)
+ endif()
+ endif() # NOT MODCMAKE_PORT_BUILD
>
> --
> :wq Claudio
>
> Index: core/Makefile
> ===================================================================
> RCS file: /cvs/ports/devel/cmake/core/Makefile,v
> diff -u -p -r1.3 Makefile
> --- core/Makefile 12 Sep 2025 23:02:44 -0000 1.3
> +++ core/Makefile 26 Jan 2026 12:54:04 -0000
> @@ -3,7 +3,7 @@ DPB_PROPERTIES = parallel
> PKGNAME = cmake-core-${VER}
> PKGNAME-main = cmake-core-${VER}
> PKGNAME-help = cmake-help-${VER}
> -REVISION-main = 0
> +REVISION-main = 1
>
> COMMENT-main = portable build system
> COMMENT-help = files for CMake --help
> Index: patches/patch-Modules_Compiler_GNU_cmake
> ===================================================================
> RCS file: /cvs/ports/devel/cmake/patches/patch-Modules_Compiler_GNU_cmake,v
> diff -u -p -r1.22 patch-Modules_Compiler_GNU_cmake
> --- patches/patch-Modules_Compiler_GNU_cmake 1 Dec 2024 14:53:52 -0000
> 1.22
> +++ patches/patch-Modules_Compiler_GNU_cmake 26 Jan 2026 12:53:12 -0000
> @@ -26,3 +26,24 @@ Index: Modules/Compiler/GNU.cmake
> if(NOT "x${lang}" STREQUAL "xFortran")
> string(APPEND CMAKE_${lang}_FLAGS_MINSIZEREL_INIT " -DNDEBUG")
> string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT " -DNDEBUG")
> +@@ -85,7 +93,9 @@ macro(__compiler_gnu lang)
> + # *
> https://gcc.gnu.org/onlinedocs/gcc-10.1.0/gcc/Optimize-Options.html#Optimize-Options
> (yes)
> + # Since GCC 12.1, the abundance of a parameter produces a warning if
> compiling multiple targets.
> + # FIXME: What version of GCC for Windows added support for -flto=auto?
> 10.3 does not have it.
> +- if(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 11.0)
> ++ if(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
> ++ # nothing
> ++ elseif(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 11.0)
> + list(APPEND __lto_flags -flto=auto)
> + elseif(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 10.1)
> + if (CMAKE_HOST_WIN32)
> +@@ -97,7 +107,8 @@ macro(__compiler_gnu lang)
> + list(APPEND __lto_flags -flto)
> + endif()
> +
> +- if(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 4.7 AND NOT APPLE)
> ++ if(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 4.7 AND NOT APPLE AND
> ++ NOT CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
> + # '-ffat-lto-objects' introduced since GCC 4.7:
> + # * https://gcc.gnu.org/onlinedocs/gcc-4.6.4/gcc/Option-Summary.html
> (no)
> + # * https://gcc.gnu.org/onlinedocs/gcc-4.7.4/gcc/Option-Summary.html
> (yes)
> Index: patches/patch-Source_cmFileCommand_cxx
> ===================================================================
> RCS file: /cvs/ports/devel/cmake/patches/patch-Source_cmFileCommand_cxx,v
> diff -u -p -r1.19 patch-Source_cmFileCommand_cxx
> --- patches/patch-Source_cmFileCommand_cxx 1 Dec 2024 14:53:52 -0000
> 1.19
> +++ patches/patch-Source_cmFileCommand_cxx 26 Jan 2026 12:53:04 -0000
> @@ -1,7 +1,7 @@
> Index: Source/cmFileCommand.cxx
> --- Source/cmFileCommand.cxx.orig
> +++ Source/cmFileCommand.cxx
> -@@ -1931,6 +1931,13 @@ bool HandleDownloadCommand(std::vector<std::string> co
> +@@ -1929,6 +1929,13 @@ bool HandleDownloadCommand(std::vector<std::string> co
> ++i;
> std::string file;
>
> @@ -15,7 +15,7 @@ Index: Source/cmFileCommand.cxx
> long timeout = 0;
> long inactivity_timeout = 0;
> std::string logVar;
> -@@ -2412,6 +2419,12 @@ bool HandleUploadCommand(std::vector<std::string> cons
> +@@ -2409,6 +2416,12 @@ bool HandleUploadCommand(std::vector<std::string> cons
> cmExecutionStatus& status)
> {
> #if !defined(CMAKE_BOOTSTRAP)
> Index: patches/patch-Source_cmGlobalGenerator_cxx
> ===================================================================
> RCS file: /cvs/ports/devel/cmake/patches/patch-Source_cmGlobalGenerator_cxx,v
> diff -u -p -r1.31 patch-Source_cmGlobalGenerator_cxx
> --- patches/patch-Source_cmGlobalGenerator_cxx 25 Feb 2025 11:56:11
> -0000 1.31
> +++ patches/patch-Source_cmGlobalGenerator_cxx 26 Jan 2026 12:53:04
> -0000
> @@ -1,7 +1,7 @@
> Index: Source/cmGlobalGenerator.cxx
> --- Source/cmGlobalGenerator.cxx.orig
> +++ Source/cmGlobalGenerator.cxx
> -@@ -2988,6 +2988,9 @@ void cmGlobalGenerator::AddGlobalTarget_Test(
> +@@ -3000,6 +3000,9 @@ void cmGlobalGenerator::AddGlobalTarget_Test(
> cmCustomCommandLine singleLine;
> singleLine.push_back(cmSystemTools::GetCTestCommand());
> singleLine.push_back("--force-new-ctest-process");