1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-09-19 21:07:26 +02:00

CMake: Scope C99/C++98 flags to VVVVVV only

Due to a confluence of weird factors, it turns out that PhysFS is
compiling with implicit function definitions due to function definitions
that get hidden with -std=c99, but not with -std=gnu99 (or the default
GCC value of -std=gnu17).

Also, due to a recent GCC update (GCC 14), implicit function
declarations are actually prohibited with -std=c99 as the C99 standard
proscribes.

This meant that people started getting build errors in PhysFS code on
default settings, which wasn't ideal.

To fix this, we will make our -std= flags apply only to VVVVVV source
files. In CMake 2.8.12, this can be done with
set_source_files_properties. Additionally the flags to disable
exceptions and RTTI are scoped down too.

Thanks to leo60228 for helping debug and solve this issue.

Fixes #1167.
This commit is contained in:
Misa 2024-07-11 23:25:34 -07:00 committed by Misa Elizabeth Kai
parent 7d01c6bdb0
commit ff611a56ff

View file

@ -65,7 +65,7 @@ if(NOT WIN32)
endif() endif()
# Source Lists # Source Lists
set(VVV_SRC set(VVV_CXX_SRC
src/BinaryBlob.cpp src/BinaryBlob.cpp
src/BlockV.cpp src/BlockV.cpp
src/ButtonGlyphs.cpp src/ButtonGlyphs.cpp
@ -108,6 +108,8 @@ set(VVV_SRC
src/WarpClass.cpp src/WarpClass.cpp
src/XMLUtils.cpp src/XMLUtils.cpp
src/main.cpp src/main.cpp
)
set(VVV_C_SRC
src/DeferCallbacks.c src/DeferCallbacks.c
src/GlitchrunnerMode.c src/GlitchrunnerMode.c
src/Network.c src/Network.c
@ -120,12 +122,14 @@ set(VVV_SRC
../third_party/physfs/extras/physfsrwops.c ../third_party/physfs/extras/physfsrwops.c
) )
if(STEAM) if(STEAM)
list(APPEND VVV_SRC src/SteamNetwork.c) list(APPEND VVV_C_SRC src/SteamNetwork.c)
endif() endif()
if(GOG) if(GOG)
list(APPEND VVV_SRC src/GOGNetwork.c) list(APPEND VVV_C_SRC src/GOGNetwork.c)
endif() endif()
set(VVV_SRC ${VVV_CXX_SRC} ${VVV_C_SRC})
# Executable information # Executable information
if(WIN32) if(WIN32)
add_executable(VVVVVV WIN32 ${VVV_SRC} icon.rc) add_executable(VVVVVV WIN32 ${VVV_SRC} icon.rc)
@ -290,11 +294,11 @@ if(MSVC)
# MSVC does not officially support disabling exceptions, # MSVC does not officially support disabling exceptions,
# so this is as far as we are willing to go to disable them. # so this is as far as we are willing to go to disable them.
string(REGEX REPLACE "/EH[a-z]+" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") string(REGEX REPLACE "/EH[a-z]+" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc") set_source_files_properties(${VVV_CXX_SRC} PROPERTIES COMPILE_FLAGS /EHsc)
# Disable RTTI # Disable RTTI
string(REPLACE "/GR" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") string(REPLACE "/GR" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-") set_source_files_properties(${VVV_CXX_SRC} PROPERTIES COMPILE_FLAGS /GR-)
if(MSVC_VERSION GREATER 1900) if(MSVC_VERSION GREATER 1900)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8")
@ -302,18 +306,18 @@ if(MSVC)
endif() endif()
else() else()
string(REGEX REPLACE "-std=[a-z0-9]+" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") string(REGEX REPLACE "-std=[a-z0-9]+" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99") set_source_files_properties(${VVV_C_SRC} PROPERTIES COMPILE_FLAGS -std=c99)
string(REGEX REPLACE "-std=[a-z0-9+]+" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") string(REGEX REPLACE "-std=[a-z0-9+]+" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++98") set_source_files_properties(${VVV_CXX_SRC} PROPERTIES COMPILE_FLAGS -std=c++98)
# Disable exceptions # Disable exceptions
string(REPLACE "-fexceptions" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") string(REPLACE "-fexceptions" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions") set_source_files_properties(${VVV_CXX_SRC} PROPERTIES COMPILE_FLAGS -fno-exceptions)
# Disable RTTI # Disable RTTI
string(REPLACE "-frtti" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") string(REPLACE "-frtti" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti") set_source_files_properties(${VVV_CXX_SRC} PROPERTIES COMPILE_FLAGS -fno-rtti)
endif() endif()
# Unfortunately, it doesn't seem like distros package LodePNG # Unfortunately, it doesn't seem like distros package LodePNG