2023-05-09 23:55:46 +02:00
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# 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()
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
2023-05-14 01:26:17 +02:00
|
|
|
# End the source file list ( optional parameter sets the runtime output dir )
|
2023-05-09 23:55:46 +02:00
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
macro( end_sources )
|
2023-05-14 01:26:17 +02:00
|
|
|
if( NOT "${ARGN}" STREQUAL "" ) # Check if an output directory is passed
|
|
|
|
set_target_output_dirs( ${PROJECT_NAME} ${ARGN} )
|
|
|
|
else()
|
2023-06-24 15:46:56 +02:00
|
|
|
set_target_output_dirs( ${PROJECT_NAME} "${BUILD_OUTPUT_DIR}/" )
|
2023-05-14 01:26:17 +02:00
|
|
|
endif()
|
2023-05-09 23:55:46 +02:00
|
|
|
endmacro()
|
|
|
|
|
2023-05-11 23:50:57 +02:00
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# Add modules to the project
|
|
|
|
# -----------------------------------------------------------------------------
|
2023-06-17 00:45:27 +02:00
|
|
|
macro( add_module MODULE_TYPE MODULE_NAME REUSE_PCH FOLDER_NAME WARNINGS_AS_ERRORS APPLY_COMPILE_OPTIONS )
|
2023-05-11 23:50:57 +02:00
|
|
|
project( ${MODULE_NAME} )
|
|
|
|
|
|
|
|
if( ${MODULE_TYPE} STREQUAL "lib" )
|
|
|
|
add_library( ${PROJECT_NAME} )
|
|
|
|
elseif( ${MODULE_TYPE} STREQUAL "shared_lib" )
|
|
|
|
add_library( ${PROJECT_NAME} SHARED )
|
2023-05-15 09:44:26 +02:00
|
|
|
elseif( ${MODULE_TYPE} STREQUAL "exe" )
|
2023-05-11 23:50:57 +02:00
|
|
|
add_executable( ${PROJECT_NAME} )
|
|
|
|
else()
|
|
|
|
message( FATAL_ERROR "Invalid module type: ${MODULE_TYPE}; expected 'lib', 'shared_lib', or 'exe'." )
|
|
|
|
endif()
|
|
|
|
|
2023-05-13 00:14:53 +02:00
|
|
|
if ( NOT "${REUSE_PCH}" STREQUAL "" )
|
|
|
|
target_precompile_headers( ${PROJECT_NAME} REUSE_FROM ${REUSE_PCH} )
|
|
|
|
endif()
|
|
|
|
|
2023-05-11 23:50:57 +02:00
|
|
|
set_target_properties( ${MODULE_NAME} PROPERTIES FOLDER ${FOLDER_NAME} )
|
2023-05-15 09:44:26 +02:00
|
|
|
|
2023-08-21 20:40:05 +02:00
|
|
|
if( ${OPTION_WARNINGS_AS_ERRORS} )
|
2023-05-15 09:44:26 +02:00
|
|
|
warnings_as_errors( ${PROJECT_NAME} ${WARNINGS_AS_ERRORS} )
|
|
|
|
endif()
|
2023-06-17 00:45:27 +02:00
|
|
|
|
|
|
|
if ( NOT "${APPLY_COMPILE_OPTIONS}" STREQUAL "FALSE" )
|
|
|
|
target_compile_options( ${PROJECT_NAME} PRIVATE
|
|
|
|
$<$<AND:$<CXX_COMPILER_ID:MSVC>,$<CONFIG:Release>>:/Ob2>
|
|
|
|
$<$<AND:$<CXX_COMPILER_ID:MSVC>,$<CONFIG:Release>>:/Oi>
|
|
|
|
$<$<AND:$<CXX_COMPILER_ID:MSVC>,$<CONFIG:Release>>:/Ot>
|
|
|
|
$<$<AND:$<CXX_COMPILER_ID:MSVC>,$<CONFIG:Release>>:/GS->
|
|
|
|
$<$<AND:$<CXX_COMPILER_ID:MSVC>,$<CONFIG:Release>>:/Gy>
|
2024-01-21 20:12:50 +01:00
|
|
|
$<$<AND:$<CXX_COMPILER_ID:MSVC>,$<CONFIG:Release>>:/GT>
|
2023-06-17 00:45:27 +02:00
|
|
|
$<$<AND:$<CXX_COMPILER_ID:MSVC>,$<CONFIG:Release>>:/fp:fast>
|
|
|
|
)
|
|
|
|
endif()
|
2023-05-13 00:14:53 +02:00
|
|
|
endmacro()
|
2023-05-11 23:50:57 +02:00
|
|
|
|
2023-05-09 23:55:46 +02:00
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# 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()
|
2023-05-13 11:57:57 +02:00
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
2024-01-21 20:12:50 +01:00
|
|
|
# Apply whole program optimization for this target in release and profile ( !slow! )
|
2023-05-13 11:57:57 +02:00
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
macro( whole_program_optimization )
|
2024-01-21 20:12:50 +01:00
|
|
|
if( ${OPTION_LTCG_MODE} STREQUAL "ON" )
|
|
|
|
set_property( TARGET ${PROJECT_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE)
|
|
|
|
set_property( TARGET ${PROJECT_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION_PROFILE TRUE)
|
|
|
|
endif()
|
2023-05-13 11:57:57 +02:00
|
|
|
endmacro()
|
2023-05-15 09:44:26 +02:00
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# 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
|
2023-10-07 16:26:56 +02:00
|
|
|
/wd4057 # 'function': 'int *' differs in indirection to slightly different base types from 'unsigned int [4]'
|
2023-05-15 09:44:26 +02:00
|
|
|
/wd4100 # Unreferenced formal parameter.
|
2024-02-19 15:48:45 +01:00
|
|
|
/wd4131 # Using old-style declarations.
|
2023-05-15 09:44:26 +02:00
|
|
|
/wd4152 # Function/data pointer conversion in expression.
|
|
|
|
/wd4200 # Zero-sized array in union; SDL2 uses this for compiler compatibility.
|
|
|
|
/wd4201 # Nameless struct/union.
|
2023-11-25 11:24:06 +01:00
|
|
|
/wd4204 # nonstandard extension used: non-constant aggregate initializer.
|
|
|
|
/wd4221 # nonstandard extension used: 'value': cannot be initialized using address of automatic variable 'symbol'
|
2023-05-15 09:44:26 +02:00
|
|
|
/wd4244 # Type conversion truncation; protobuf has many, but this appears intentional.
|
2023-10-07 16:26:56 +02:00
|
|
|
/wd4245 # 'return': conversion signed/unsigned mismatch
|
2023-05-15 09:44:26 +02:00
|
|
|
/wd4267 # Type conversion truncation; protobuf has many, but this appears intentional.
|
|
|
|
/wd4307 # Integral constant overflow.
|
|
|
|
/wd4389 # Signed/unsigned mismatch.
|
2023-07-28 16:44:52 +02:00
|
|
|
/wd4456 # Declaration hides previous local declaration.
|
|
|
|
/wd4457 # Declaration hides function parameter.
|
2023-05-15 09:44:26 +02:00
|
|
|
/wd4505 # Unreferenced local function has been removed.
|
2023-10-07 16:26:56 +02:00
|
|
|
/wd4701 # potentially uninitialized local variable.
|
|
|
|
/wd4702 # Unreachable code.
|
2023-05-15 09:44:26 +02:00
|
|
|
)
|
|
|
|
endif()
|
|
|
|
warnings_as_errors( ${PROJECT_NAME} FALSE )
|
|
|
|
endmacro()
|