summaryrefslogtreecommitdiffstats
path: root/CMakeLists.txt
blob: b3ac53a4ca00b42f6bc196151ea455f86c718d30 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# This is the top-level CMakeLists.txt file for the Cuberite project
#
# Use CMake to generate the build files for your platform

cmake_minimum_required (VERSION 3.13)
cmake_policy(VERSION 3.13...3.17.2)
project(
	Cuberite
	DESCRIPTION "A lightweight, fast and extensible game server for Minecraft"
	HOMEPAGE_URL "https://cuberite.org"
	LANGUAGES C CXX
)

option(BUILD_TOOLS "Sets up additional executables to be built along with the server" OFF)
option(BUILD_UNSTABLE_TOOLS "Sets up yet more executables to be built, these can be broken and generally are obsolete" OFF)
option(NO_NATIVE_OPTIMIZATION "Disables CPU-specific optimisations for the current machine, allows use on other CPUs of the same platform" OFF)
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)
option(WHOLE_PROGRAM_OPTIMISATION "Enables link time optimisation for Release" ON)

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:
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# 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})
endif()

# Static CRT:
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

# TODO: set_build_stamp()
set_global_flags()
build_dependencies()

add_executable(${CMAKE_PROJECT_NAME})
add_subdirectory(src)

set_exe_flags(${CMAKE_PROJECT_NAME})
link_dependencies(${CMAKE_PROJECT_NAME})

# 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")

# 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()

	set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES UNITY_BUILD ${UNITY_BUILDS})
else()
	message(WARNING "Precompiled headers for FASTER BUILDS not enabled, upgrade to CMake 3.16 or newer!")
endif()

# 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("${PROJECT_SOURCE_DIR}/src/Bindings/Bindings.cpp" PROPERTIES COMPILE_OPTIONS -Wno-everything)

	# File failed to follow NHS guidelines on handwashing and has not maintained good hygiene
	set_source_files_properties("${PROJECT_SOURCE_DIR}/src/IniFile.cpp" PROPERTIES COMPILE_OPTIONS -Wno-header-hygiene)
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
	set_source_files_properties("${PROJECT_SOURCE_DIR}/src/Bindings/Bindings.cpp" PROPERTIES COMPILE_OPTIONS -w)
endif()

if(BUILD_TOOLS)
	message(STATUS "Building tools")
	add_subdirectory(Tools/GrownBiomeGenVisualiser/)
	add_subdirectory(Tools/MCADefrag/)
	add_subdirectory(Tools/NoiseSpeedTest/)
	add_subdirectory(Tools/ProtoProxy/)
endif()

if(BUILD_UNSTABLE_TOOLS)
	message(STATUS "Building unstable tools")
	add_subdirectory(Tools/GeneratorPerformanceTest/)
endif()

# Self Test Mode enables extra checks at startup
if(SELF_TEST)
	message(STATUS "Tests enabled")
	enable_testing()
	add_subdirectory(tests)
endif()

emit_fixups()
group_sources()
enable_bindings_generation()