mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Treat them as errors globally. Most of the time a warning is a bug, or problem in code that could be solved in a different (better) manner. Thirdparty code have this disabled. The warnings as errors option can be globally disabled through the CMake GUI, but this is not recommended.
139 lines
5.5 KiB
CMake
139 lines
5.5 KiB
CMake
# -----------------------------------------------------------------------------
|
|
# Start the source file list
|
|
# -----------------------------------------------------------------------------
|
|
macro( start_sources )
|
|
add_sources( SOURCE_GROUP ""
|
|
# Add the CMakeLists file to the project filter root
|
|
"CMakeLists.txt"
|
|
)
|
|
endmacro()
|
|
|
|
# -----------------------------------------------------------------------------
|
|
# Add source files to target within a project filter
|
|
# -----------------------------------------------------------------------------
|
|
macro( add_sources )
|
|
set( options )
|
|
set( oneValueArgs SOURCE_GROUP )
|
|
set( multiValueArgs )
|
|
|
|
cmake_parse_arguments( ADD_SOURCES
|
|
"${options}"
|
|
"${oneValueArgs}"
|
|
"${multiValueArgs}" ${ARGN}
|
|
)
|
|
|
|
if( NOT ADD_SOURCES_SOURCE_GROUP )
|
|
message( FATAL_ERROR "SOURCE_GROUP must be provided" )
|
|
endif()
|
|
|
|
source_group( "${ADD_SOURCES_SOURCE_GROUP}" FILES ${ADD_SOURCES_UNPARSED_ARGUMENTS} )
|
|
target_sources( ${PROJECT_NAME} PRIVATE ${ADD_SOURCES_UNPARSED_ARGUMENTS} )
|
|
endmacro()
|
|
|
|
# -----------------------------------------------------------------------------
|
|
# End the source file list ( optional parameter sets the runtime output dir )
|
|
# -----------------------------------------------------------------------------
|
|
macro( end_sources )
|
|
if( NOT "${ARGN}" STREQUAL "" ) # Check if an output directory is passed
|
|
set_target_output_dirs( ${PROJECT_NAME} ${ARGN} )
|
|
else()
|
|
set_target_output_dirs( ${PROJECT_NAME} "game/" )
|
|
endif()
|
|
endmacro()
|
|
|
|
# -----------------------------------------------------------------------------
|
|
# Add modules to the project
|
|
# -----------------------------------------------------------------------------
|
|
macro( add_module MODULE_TYPE MODULE_NAME REUSE_PCH FOLDER_NAME WARNINGS_AS_ERRORS )
|
|
project( ${MODULE_NAME} )
|
|
|
|
if( ${MODULE_TYPE} STREQUAL "lib" )
|
|
add_library( ${PROJECT_NAME} )
|
|
elseif( ${MODULE_TYPE} STREQUAL "shared_lib" )
|
|
add_library( ${PROJECT_NAME} SHARED )
|
|
target_link_options( ${PROJECT_NAME} PRIVATE
|
|
"$<$<CONFIG:Release>:/LTCG>"
|
|
)
|
|
elseif( ${MODULE_TYPE} STREQUAL "exe" )
|
|
add_executable( ${PROJECT_NAME} )
|
|
target_link_options( ${PROJECT_NAME} PRIVATE
|
|
"$<$<CONFIG:Release>:/LTCG>"
|
|
)
|
|
else()
|
|
message( FATAL_ERROR "Invalid module type: ${MODULE_TYPE}; expected 'lib', 'shared_lib', or 'exe'." )
|
|
endif()
|
|
|
|
if ( NOT "${REUSE_PCH}" STREQUAL "" )
|
|
target_precompile_headers( ${PROJECT_NAME} REUSE_FROM ${REUSE_PCH} )
|
|
endif()
|
|
|
|
set_target_properties( ${MODULE_NAME} PROPERTIES FOLDER ${FOLDER_NAME} )
|
|
|
|
if( ${GLOBAL_WARNINGS_AS_ERRORS} )
|
|
warnings_as_errors( ${PROJECT_NAME} ${WARNINGS_AS_ERRORS} )
|
|
endif()
|
|
endmacro()
|
|
|
|
# -----------------------------------------------------------------------------
|
|
# Initialize global compiler defines
|
|
# -----------------------------------------------------------------------------
|
|
macro( define_compiler_variables )
|
|
if( CMAKE_CXX_COMPILER_ID MATCHES "MSVC" )
|
|
add_definitions( -DCOMPILER_MSVC )
|
|
elseif( CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
|
|
add_definitions( -DCOMPILER_CLANG )
|
|
elseif( CMAKE_CXX_COMPILER_ID MATCHES "GNU" )
|
|
add_definitions( -DCOMPILER_GCC )
|
|
else()
|
|
message( FATAL_ERROR "Unsupported compiler: ${CMAKE_CXX_COMPILER_ID}" )
|
|
endif()
|
|
endmacro()
|
|
|
|
# -----------------------------------------------------------------------------
|
|
# Apply whole program optimization for this target in release ( !slow! )
|
|
# -----------------------------------------------------------------------------
|
|
macro( whole_program_optimization )
|
|
target_compile_options( ${PROJECT_NAME} PRIVATE
|
|
$<$<CONFIG:Release>:/GL>
|
|
)
|
|
endmacro()
|
|
|
|
# -----------------------------------------------------------------------------
|
|
# Toggles wether or not to treat warnings as errors
|
|
# -----------------------------------------------------------------------------
|
|
macro( warnings_as_errors TARGET FLAG )
|
|
if( ${FLAG} )
|
|
if( MSVC )
|
|
target_compile_options( ${TARGET} PRIVATE /WX )
|
|
else()
|
|
target_compile_options( ${TARGET} PRIVATE -Werror )
|
|
endif()
|
|
else()
|
|
if( MSVC )
|
|
target_compile_options( ${TARGET} PRIVATE "/wd4996" )
|
|
else()
|
|
target_compile_options( ${TARGET} PRIVATE "-Wno-error" )
|
|
endif()
|
|
endif()
|
|
endmacro()
|
|
|
|
# -----------------------------------------------------------------------------
|
|
# Disables verbose warnings caused within thirdparty code ( !only use on thirdparty projects! )
|
|
# -----------------------------------------------------------------------------
|
|
macro( thirdparty_suppress_warnings )
|
|
if( MSVC OR CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
|
|
target_compile_options( ${PROJECT_NAME} PRIVATE
|
|
/wd4100 # Unreferenced formal parameter.
|
|
/wd4152 # Function/data pointer conversion in expression.
|
|
/wd4200 # Zero-sized array in union; SDL2 uses this for compiler compatibility.
|
|
/wd4201 # Nameless struct/union.
|
|
/wd4244 # Type conversion truncation; protobuf has many, but this appears intentional.
|
|
/wd4267 # Type conversion truncation; protobuf has many, but this appears intentional.
|
|
/wd4307 # Integral constant overflow.
|
|
/wd4389 # Signed/unsigned mismatch.
|
|
/wd4505 # Unreferenced local function has been removed.
|
|
)
|
|
endif()
|
|
warnings_as_errors( ${PROJECT_NAME} FALSE )
|
|
endmacro()
|