2023-05-09 23:55:46 +02:00
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# Setup each build configuration
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
macro( apply_project_settings )
|
|
|
|
# Set common settings for all configurations
|
|
|
|
add_compile_options(
|
|
|
|
$<$<CXX_COMPILER_ID:MSVC>:/permissive->
|
|
|
|
$<$<CXX_COMPILER_ID:MSVC>:/MP>
|
2023-05-18 14:07:52 +02:00
|
|
|
$<$<CXX_COMPILER_ID:MSVC>:/Zf>
|
2023-05-25 22:25:33 +02:00
|
|
|
$<$<CXX_COMPILER_ID:MSVC>:/Zi>
|
2023-05-09 23:55:46 +02:00
|
|
|
$<$<CXX_COMPILER_ID:MSVC>:/W4>
|
|
|
|
$<$<CXX_COMPILER_ID:MSVC>:/GR>
|
|
|
|
)
|
|
|
|
|
2023-05-15 09:44:26 +02:00
|
|
|
# Suppress certain compiler warnings
|
|
|
|
# ( !don't suppress warnings here that are specific to a project! )
|
|
|
|
add_compile_options(
|
|
|
|
$<$<CXX_COMPILER_ID:MSVC>:/wd4996> # 'The POSIX name for this item is deprecated'
|
|
|
|
$<$<CXX_COMPILER_ID:MSVC>:/wd4127> # 'Consider using 'if constexpr' statement instead'
|
|
|
|
)
|
|
|
|
|
|
|
|
# Some thirdparty code have Warnings as Errors disabled; this option won't override those.
|
2023-08-21 20:40:05 +02:00
|
|
|
option( OPTION_WARNINGS_AS_ERRORS "Treat compiler warnings as errors" ON )
|
2024-01-21 20:12:50 +01:00
|
|
|
|
|
|
|
set( OPTION_LTCG_MODE "OFF" CACHE STRING "Enables link-time code generation (significantly increases compile times)" )
|
|
|
|
set_property( CACHE OPTION_LTCG_MODE PROPERTY STRINGS
|
|
|
|
"OFF"
|
2024-02-04 12:50:02 +01:00
|
|
|
"ON" # Only on projects that specified LTCG
|
|
|
|
"ALL" # All projects, whether or not LTCG was specified
|
2024-01-21 20:12:50 +01:00
|
|
|
)
|
2023-05-15 09:44:26 +02:00
|
|
|
|
2023-08-21 20:40:05 +02:00
|
|
|
option( OPTION_CERTAIN "This build is certain; debug statements (such as DevMsg(...)) will NOT be compiled" OFF )
|
|
|
|
option( OPTION_RETAIL "This build is retail; enable this among with 'OPTION_CERTAIN' to form a release build" OFF )
|
|
|
|
|
2023-05-09 23:55:46 +02:00
|
|
|
# Set common defines
|
|
|
|
add_compile_definitions(
|
|
|
|
"_CRT_SECURE_NO_WARNINGS"
|
|
|
|
"SPDLOG_COMPILED_LIB"
|
|
|
|
"SPDLOG_NO_EXCEPTIONS"
|
|
|
|
"CURL_STATICLIB"
|
2023-09-07 11:18:00 +02:00
|
|
|
|
|
|
|
# Must be explicitly defined to toggle SIMD optimizations for RapidJSON.
|
|
|
|
# Don't set this to anything higher than SSE2, as the game supports from
|
|
|
|
# SSE3 and higher, and the next level of optimizations in RapidJSON is SSE4.2.
|
|
|
|
"RAPIDJSON_SSE2"
|
|
|
|
|
2024-02-04 12:50:02 +01:00
|
|
|
# Use iterative parsing to protect against stack overflows in rare cases; see:
|
|
|
|
# https://rapidjson.org/md_doc_features.html
|
|
|
|
# https://github.com/Tencent/rapidjson/issues/1227
|
|
|
|
# https://github.com/Tencent/rapidjson/issues/2260
|
2024-03-31 15:32:04 +02:00
|
|
|
"RAPIDJSON_PARSE_DEFAULT_FLAGS=kParseIterativeFlag|kParseValidateEncodingFlag"
|
2024-02-04 12:50:02 +01:00
|
|
|
|
2023-09-07 11:18:00 +02:00
|
|
|
# Target is 64bits only.
|
|
|
|
"PLATFORM_64BITS"
|
2023-05-09 23:55:46 +02:00
|
|
|
)
|
|
|
|
|
2023-08-21 20:40:05 +02:00
|
|
|
if( ${OPTION_CERTAIN} )
|
|
|
|
add_compile_definitions(
|
|
|
|
"_CERT"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if( ${OPTION_RETAIL} )
|
|
|
|
add_compile_definitions(
|
|
|
|
"_RETAIL"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2023-05-09 23:55:46 +02:00
|
|
|
# Set settings for Debug configuration
|
|
|
|
add_compile_options(
|
|
|
|
$<$<AND:$<CXX_COMPILER_ID:MSVC>,$<CONFIG:Debug>>:/MTd>
|
|
|
|
)
|
|
|
|
|
|
|
|
# Set settings for Profile configuration
|
|
|
|
add_compile_options(
|
|
|
|
$<$<AND:$<CXX_COMPILER_ID:MSVC>,$<CONFIG:Profile>>:/Ox>
|
|
|
|
$<$<AND:$<CXX_COMPILER_ID:MSVC>,$<CONFIG:Profile>>:/GF>
|
|
|
|
$<$<AND:$<CXX_COMPILER_ID:MSVC>,$<CONFIG:Profile>>:/MT>
|
|
|
|
)
|
|
|
|
set( CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_PROFILE} /PROFILE" )
|
|
|
|
|
|
|
|
# Set settings for Release configuration
|
|
|
|
add_compile_options(
|
|
|
|
$<$<AND:$<CXX_COMPILER_ID:MSVC>,$<CONFIG:Release>>:/GF>
|
|
|
|
$<$<AND:$<CXX_COMPILER_ID:MSVC>,$<CONFIG:Release>>:/MT>
|
2023-05-18 14:07:52 +02:00
|
|
|
$<$<AND:$<CXX_COMPILER_ID:MSVC>,$<CONFIG:Release>>:/EHsc>
|
2023-05-09 23:55:46 +02:00
|
|
|
)
|
|
|
|
|
2024-01-21 20:12:50 +01:00
|
|
|
if( ${OPTION_LTCG_MODE} STREQUAL "ALL" )
|
|
|
|
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON)
|
|
|
|
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_PROFILE ON)
|
2023-07-03 15:40:45 +02:00
|
|
|
endif()
|
|
|
|
|
2023-05-09 23:55:46 +02:00
|
|
|
set( CMAKE_EXE_LINKER_FLAGS_RELEASE
|
|
|
|
"${CMAKE_EXE_LINKER_FLAGS_RELEASE}
|
|
|
|
/OPT:REF
|
|
|
|
/OPT:ICF
|
|
|
|
/RELEASE
|
|
|
|
/SAFESEH:NO
|
|
|
|
/DEBUG"
|
|
|
|
)
|
|
|
|
|
2023-06-17 00:45:27 +02:00
|
|
|
# Commonly used directories across libraries
|
2023-05-09 23:55:46 +02:00
|
|
|
include_directories(
|
|
|
|
"${ENGINE_SOURCE_DIR}/"
|
|
|
|
"${ENGINE_SOURCE_DIR}/public/"
|
2023-10-07 16:26:56 +02:00
|
|
|
"${THIRDPARTY_SOURCE_DIR}/"
|
|
|
|
"${THIRDPARTY_SOURCE_DIR}/imgui/"
|
|
|
|
"${THIRDPARTY_SOURCE_DIR}/recast/"
|
2023-05-09 23:55:46 +02:00
|
|
|
)
|
|
|
|
endmacro()
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# Setup build output directories for target
|
|
|
|
# -----------------------------------------------------------------------------
|
2023-05-14 01:26:17 +02:00
|
|
|
macro( set_target_output_dirs TARGET RUNTIME_DIR )
|
2023-05-09 23:55:46 +02:00
|
|
|
# Set output directories
|
|
|
|
set_target_properties( ${TARGET} PROPERTIES
|
2023-05-14 01:26:17 +02:00
|
|
|
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/${RUNTIME_DIR}"
|
|
|
|
RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_SOURCE_DIR}/${RUNTIME_DIR}"
|
|
|
|
RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_SOURCE_DIR}/${RUNTIME_DIR}"
|
|
|
|
RUNTIME_OUTPUT_DIRECTORY_PROFILE "${CMAKE_SOURCE_DIR}/${RUNTIME_DIR}"
|
2023-05-09 23:55:46 +02:00
|
|
|
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/lib/${TARGET}"
|
|
|
|
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/lib/${TARGET}"
|
|
|
|
)
|
|
|
|
|
|
|
|
# Set output directories for each configuration
|
|
|
|
foreach( CONFIG_TYPE ${CMAKE_CONFIGURATION_TYPES} )
|
|
|
|
set_target_properties( ${TARGET} PROPERTIES
|
2023-05-14 01:26:17 +02:00
|
|
|
"RUNTIME_OUTPUT_DIRECTORY_${CONFIG_TYPE}" "${CMAKE_SOURCE_DIR}/${RUNTIME_DIR}"
|
2023-05-09 23:55:46 +02:00
|
|
|
"ARCHIVE_OUTPUT_DIRECTORY_${CONFIG_TYPE}" "${CMAKE_SOURCE_DIR}/lib/${TARGET}/${CONFIG_TYPE}"
|
|
|
|
"LIBRARY_OUTPUT_DIRECTORY_${CONFIG_TYPE}" "${CMAKE_SOURCE_DIR}/lib/${TARGET}/${CONFIG_TYPE}"
|
|
|
|
"LINK_FLAGS_${CONFIG_TYPE}" "/PDB:${PDB_FULL_PATH}"
|
|
|
|
)
|
|
|
|
endforeach()
|
2023-05-11 21:04:21 +02:00
|
|
|
|
|
|
|
# Set PDB properties for release builds ( should be created )
|
|
|
|
set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi" )
|
|
|
|
set( PDB_OUTPUT_DIRECTORY "RUNTIME_OUTPUT_DIRECTORY_${CONFIG_TYPE}" )
|
2023-05-14 02:28:53 +02:00
|
|
|
|
|
|
|
# Set linker properties
|
|
|
|
set( CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF" )
|
|
|
|
set( CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_PROFILE} /DEBUG /PROFILE" )
|
2023-05-09 23:55:46 +02:00
|
|
|
endmacro()
|