File compile_c_only_libs_with_c11_std.patch of Package widelands
From d0c9f68514ee2a71d8924010ec092813aad6d069 Mon Sep 17 00:00:00 2001
From: Benedikt Straub <benedikt-straub@web.de>
Date: Tue, 15 Apr 2025 13:28:28 +0200
Subject: [PATCH] Compile C-only libraries with c11 standard
---
CMakeLists.txt | 3 +++
cmake/WlFunctions.cmake | 3 +++
2 files changed, 6 insertions(+)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 241b85241ca..7e7f7907794 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -276,6 +276,7 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
endif()
elseif(MSVC)
wl_add_flag(WL_GENERIC_CXX_FLAGS "/std:c++17")
+ wl_add_flag(WL_GENERIC_C_LIBRARY_FLAGS "/std:c11")
# https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/
# Disabled warnings that are overly verbose right now or just do not make sense.
wl_add_flag(WL_COMPILE_DIAGNOSTICS "/wd4244")
@@ -288,6 +289,7 @@ else()
if(WIN32)
# This is needed for getenv().
wl_add_flag(WL_GENERIC_CXX_FLAGS "-std=gnu++17")
+ wl_add_flag(WL_GENERIC_C_LIBRARY_FLAGS "-std=c11")
if (OPTION_BUILD_WINSTATIC)
set(CMAKE_CXX_STANDARD_LIBRARIES "-static-libgcc -static-libstdc++ ${CMAKE_CXX_STANDARD_LIBRARIES}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Bstatic")
@@ -369,6 +371,7 @@ if(NOT MSVC)
endif()
wl_add_flag(WL_GENERIC_CXX_FLAGS "-std=c++17")
+ wl_add_flag(WL_GENERIC_C_LIBRARY_FLAGS "-std=c11")
endif()
# Cross-compile-unit optimization slows linking significantly.
diff --git a/cmake/WlFunctions.cmake b/cmake/WlFunctions.cmake
index 9a84ba06823..112ce93ef52 100644
--- a/cmake/WlFunctions.cmake
+++ b/cmake/WlFunctions.cmake
@@ -65,6 +65,9 @@ macro(_common_compile_tasks)
# This is needed for header only libraries. While they do not really mean
# anything for cmake, they are useful to make dependencies explicit.
set_target_properties(${NAME} PROPERTIES LINKER_LANGUAGE CXX)
+ else()
+ set(TARGET_COMPILE_FLAGS "${TARGET_COMPILE_FLAGS} ${WL_GENERIC_C_LIBRARY_FLAGS}")
+ set_target_properties(${NAME} PROPERTIES LINKER_LANGUAGE C)
endif()
set(TARGET_COMPILE_FLAGS "${TARGET_COMPILE_FLAGS} ${WL_OPTIMIZE_FLAGS} ${WL_DEBUG_FLAGS}")