2017-09-19 16:34:08 +08:00
# This is the top-level CMakeLists.txt file for the Cuberite project
2016-07-21 17:46:31 +08:00
#
# Use CMake to generate the build files for your platform
#
# This script supports some configuration through CMake arguments (-Dparam=val syntax):
2020-08-07 00:13:47 +08:00
# BUILD_TOOLS=1 sets up additional executables to be built along with the server (ProtoProxy, GrownBiomeGenVisualiser, MCADefrag)
# BUILD_UNSTABLE_TOOLS=1 sets up yet more executables to be built, these can be broken and generally are obsolete (GeneratorPerformanceTest)
# NO_NATIVE_OPTIMIZATION=1 disables CPU-specific optimisations for the current machine, allows use on other CPUs of the same platform
# DISABLE_SYSTEM_LUA=1 disables the use of system Lua interpreter; the tolua executable will be built and used instead. Incompatible with cross-compiling
# SELF_TEST=1 enables testing code to be built
# UNITY_BUILDS=OFF disables unity builds
# PRECOMPILE_HEADERS=OFF disables precompiled headers
# WHOLE_PROGRAM_OPTIMISATION=OFF disables link time optimisation
2016-07-21 17:46:31 +08:00
2020-05-17 03:59:10 +08:00
cmake_minimum_required ( VERSION 3.13 )
2020-05-22 06:52:19 +08:00
cmake_policy ( VERSION 3.13...3.17.2 )
2020-05-17 03:59:10 +08:00
project (
C u b e r i t e
D E S C R I P T I O N " A l i g h t w e i g h t , f a s t a n d e x t e n s i b l e g a m e s e r v e r f o r M i n e c r a f t "
H O M E P A G E _ U R L " h t t p s : / / c u b e r i t e . o r g "
L A N G U A G E S C C X X
)
option ( BUILD_TOOLS "Sets up additional executables to be built along with the server" OFF )
2020-05-22 06:52:19 +08:00
option ( WHOLE_PROGRAM_OPTIMISATION "Enables link time optimisation for Release" ON )
2020-05-17 03:59:10 +08:00
option ( PRECOMPILE_HEADERS "Enable precompiled headers for faster builds" ON )
option ( SELF_TEST "Enables testing code to be built" OFF )
option ( UNITY_BUILDS "Enables source aggregation for faster builds" ON )
2015-06-03 16:40:01 +08:00
2020-05-28 06:48:49 +08:00
include ( "CMake/AddDependencies.cmake" )
include ( "CMake/Fixups.cmake" )
include ( "CMake/GenerateBindings.cmake" )
include ( "CMake/GroupSources.cmake" )
include ( "SetFlags.cmake" )
# Add build timestamp and details:
include ( "CMake/StampBuild.cmake" )
# We need C++17 features:
2020-05-09 23:51:54 +08:00
set ( CMAKE_CXX_STANDARD 17 )
set ( CMAKE_CXX_STANDARD_REQUIRED ON )
set ( CMAKE_CXX_EXTENSIONS OFF )
2020-08-30 23:32:03 +08:00
# TODO: use standard NDEBUG in place of _DEBUG
if ( "${CMAKE_BUILD_TYPE}" MATCHES "DEBUG" )
add_definitions ( -D_DEBUG )
endif ( )
2020-06-01 03:26:50 +08:00
# The need for speed (in Release):
if ( WHOLE_PROGRAM_OPTIMISATION )
include ( CheckIPOSupported )
check_ipo_supported ( RESULT IPO_SUPPORTED )
set ( CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ IPO_SUPPORTED } )
2016-07-17 22:23:29 +08:00
endif ( )
2020-05-28 06:48:49 +08:00
# Static CRT:
2020-05-17 03:59:10 +08:00
set ( CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>" )
2016-07-17 22:23:29 +08:00
2020-07-07 07:04:32 +08:00
# TODO: set_build_stamp()
set_global_flags ( )
build_dependencies ( )
2020-05-17 03:59:10 +08:00
add_executable ( ${ CMAKE_PROJECT_NAME } )
add_subdirectory ( src )
2015-11-05 05:32:11 +08:00
2020-07-07 07:04:32 +08:00
set_exe_flags ( ${ CMAKE_PROJECT_NAME } )
link_dependencies ( ${ CMAKE_PROJECT_NAME } )
2020-05-28 06:48:49 +08:00
2020-05-17 03:59:10 +08:00
# Set the startup project to Cuberite, and the debugger dir:
set_property ( DIRECTORY PROPERTY VS_STARTUP_PROJECT ${ CMAKE_PROJECT_NAME } )
set_target_properties ( ${ CMAKE_PROJECT_NAME } PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/Server" )
2015-01-10 03:38:25 +08:00
2020-05-17 03:59:10 +08:00
# Enable PCH and jumbo builds on supporting CMake:
if ( CMAKE_VERSION VERSION_GREATER_EQUAL "3.16" )
if ( PRECOMPILE_HEADERS )
target_precompile_headers ( ${ CMAKE_PROJECT_NAME } PRIVATE src/Globals.h )
endif ( )
2018-01-04 01:41:16 +08:00
2020-05-22 06:52:19 +08:00
set_target_properties ( ${ CMAKE_PROJECT_NAME } PROPERTIES UNITY_BUILD ${ UNITY_BUILDS } )
2020-05-17 03:59:10 +08:00
else ( )
message ( WARNING "Precompiled headers for FASTER BUILDS not enabled, upgrade to CMake 1.16 or newer!" )
endif ( )
2013-12-11 05:39:20 +08:00
2020-05-17 03:59:10 +08:00
# Selectively disable warnings in the level where the target is created:
if ( CMAKE_CXX_COMPILER_ID STREQUAL "Clang" )
# Generated file has old-style casts, missing prototypes, and deprecated declarations
set_source_files_properties ( "${CMAKE_SOURCE_DIR}/src/Bindings/Bindings.cpp" PROPERTIES COMPILE_OPTIONS -Wno-everything )
2014-01-23 05:19:33 +08:00
2020-05-17 03:59:10 +08:00
# File failed to follow NHS guidelines on handwashing and has not maintained good hygiene
set_source_files_properties ( "${CMAKE_SOURCE_DIR}/src/IniFile.cpp" PROPERTIES COMPILE_OPTIONS -Wno-header-hygiene )
2020-09-17 21:51:42 +08:00
# Enforce BlockHandler handling all blocks in switch statements
set_source_files_properties ( "${CMAKE_SOURCE_DIR}/src/Blocks/BlockHandler.cpp" PROPERTIES COMPILE_OPTIONS -Werror=switch )
2017-08-23 03:56:32 +08:00
endif ( )
2020-05-22 06:52:19 +08:00
if ( ${ BUILD_TOOLS } )
message ( "Building tools" )
add_subdirectory ( Tools/GrownBiomeGenVisualiser/ )
add_subdirectory ( Tools/MCADefrag/ )
add_subdirectory ( Tools/NoiseSpeedTest/ )
add_subdirectory ( Tools/ProtoProxy/ )
endif ( )
if ( ${ BUILD_UNSTABLE_TOOLS } )
message ( "Building unstable tools" )
add_subdirectory ( Tools/GeneratorPerformanceTest/ )
endif ( )
2020-05-17 03:59:10 +08:00
# Self Test Mode enables extra checks at startup
2014-04-28 03:25:03 +08:00
if ( ${ SELF_TEST } )
2015-01-11 17:43:02 +08:00
message ( "Tests enabled" )
2014-04-28 03:25:03 +08:00
enable_testing ( )
2016-11-08 06:15:07 +08:00
add_subdirectory ( tests )
2014-04-28 03:25:03 +08:00
endif ( )
2020-05-28 06:48:49 +08:00
emit_fixups ( )
group_sources ( )
enable_bindings_generation ( )