mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Add CMake macro's
Macro's performing project wide, and common operations. Crafted for r5sdk, but it is still partially incomplete.
This commit is contained in:
parent
f310497464
commit
807d660883
7
r5dev/cmake/Configure.cmake
Normal file
7
r5dev/cmake/Configure.cmake
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
# Set global configuration types
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
macro( setup_build_configurations )
|
||||||
|
set( CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" CACHE STRING "" FORCE )
|
||||||
|
endmacro()
|
54
r5dev/cmake/Macros.cmake
Normal file
54
r5dev/cmake/Macros.cmake
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
# 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
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
macro( end_sources )
|
||||||
|
get_property( SRCS_LIST GLOBAL PROPERTY SRCS_LIST )
|
||||||
|
set_target_output_dirs( ${PROJECT_NAME} )
|
||||||
|
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()
|
94
r5dev/cmake/Options.cmake
Normal file
94
r5dev/cmake/Options.cmake
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
# 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>
|
||||||
|
$<$<CXX_COMPILER_ID:MSVC>:/W4>
|
||||||
|
$<$<CXX_COMPILER_ID:MSVC>:/GR>
|
||||||
|
$<$<CXX_COMPILER_ID:MSVC>:/D_UNICODE>
|
||||||
|
$<$<CXX_COMPILER_ID:MSVC>:/DUNICODE>
|
||||||
|
)
|
||||||
|
|
||||||
|
# Set common defines
|
||||||
|
add_compile_definitions(
|
||||||
|
"_CRT_SECURE_NO_WARNINGS"
|
||||||
|
"SPDLOG_COMPILED_LIB"
|
||||||
|
"SPDLOG_NO_EXCEPTIONS"
|
||||||
|
"CURL_STATICLIB"
|
||||||
|
)
|
||||||
|
|
||||||
|
# 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>>:/Ob2>
|
||||||
|
$<$<AND:$<CXX_COMPILER_ID:MSVC>,$<CONFIG:Release>>:/Oi>
|
||||||
|
$<$<AND:$<CXX_COMPILER_ID:MSVC>,$<CONFIG:Release>>:/Ot>
|
||||||
|
$<$<AND:$<CXX_COMPILER_ID:MSVC>,$<CONFIG:Release>>:/GF>
|
||||||
|
$<$<AND:$<CXX_COMPILER_ID:MSVC>,$<CONFIG:Release>>:/MT>
|
||||||
|
$<$<AND:$<CXX_COMPILER_ID:MSVC>,$<CONFIG:Release>>:/GS->
|
||||||
|
$<$<AND:$<CXX_COMPILER_ID:MSVC>,$<CONFIG:Release>>:/Gy>
|
||||||
|
$<$<AND:$<CXX_COMPILER_ID:MSVC>,$<CONFIG:Release>>:/fp:fast>
|
||||||
|
)
|
||||||
|
|
||||||
|
set( CMAKE_EXE_LINKER_FLAGS_RELEASE
|
||||||
|
"${CMAKE_EXE_LINKER_FLAGS_RELEASE}
|
||||||
|
/OPT:REF
|
||||||
|
/OPT:ICF
|
||||||
|
/RELEASE
|
||||||
|
/SAFESEH:NO
|
||||||
|
/DEBUG"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Commonly used directories accross libraries.
|
||||||
|
include_directories(
|
||||||
|
"${ENGINE_SOURCE_DIR}/"
|
||||||
|
"${ENGINE_SOURCE_DIR}/public/"
|
||||||
|
"${ENGINE_SOURCE_DIR}/thirdparty/"
|
||||||
|
"${ENGINE_SOURCE_DIR}/thirdparty/imgui/"
|
||||||
|
"${ENGINE_SOURCE_DIR}/thirdparty/recast/"
|
||||||
|
)
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
# Setup build output directories for target
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
macro( set_target_output_dirs TARGET )
|
||||||
|
# Set abs PDB path
|
||||||
|
get_filename_component( OUTPUT_DIR_ABSOLUTE "${CMAKE_SOURCE_DIR}/game/" ABSOLUTE )
|
||||||
|
set( PDB_FULL_PATH "${OUTPUT_DIR_ABSOLUTE}/${PROJECT_NAME}.pdb" )
|
||||||
|
|
||||||
|
# Set output directories
|
||||||
|
set_target_properties( ${TARGET} PROPERTIES
|
||||||
|
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/game/"
|
||||||
|
RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_SOURCE_DIR}/game/"
|
||||||
|
RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_SOURCE_DIR}/game/"
|
||||||
|
RUNTIME_OUTPUT_DIRECTORY_PROFILE "${CMAKE_SOURCE_DIR}/game/"
|
||||||
|
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
|
||||||
|
"RUNTIME_OUTPUT_DIRECTORY_${CONFIG_TYPE}" "${CMAKE_SOURCE_DIR}/game/"
|
||||||
|
"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()
|
||||||
|
endmacro()
|
Loading…
x
Reference in New Issue
Block a user