2017-09-19 04:34:08 -04:00
# This is the top-level CMakeLists.txt file for the Cuberite project
2016-07-21 05:46:31 -04:00
#
# Use CMake to generate the build files for your platform
#
# This script supports some configuration through CMake arguments (-Dparam=val syntax):
2016-07-30 09:22:18 -04: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
2016-07-21 05:46:31 -04:00
2020-05-16 15:59:10 -04:00
cmake_minimum_required ( VERSION 3.13 )
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 )
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 04:40:01 -04:00
2014-03-10 16:52:13 -04:00
# These env variables are used for configuring Travis CI builds.
2015-08-26 04:58:51 -04:00
if ( DEFINED ENV{TRAVIS_CUBERITE_BUILD_TYPE} )
message ( "Setting build type to $ENV{TRAVIS_CUBERITE_BUILD_TYPE}" )
set ( CMAKE_BUILD_TYPE $ENV{ TRAVIS_CUBERITE_BUILD_TYPE } )
2014-03-07 15:16:16 -05:00
endif ( )
2016-01-01 15:05:09 -05:00
if ( DEFINED ENV{TRAVIS_CUBERITE_FORCE32} )
set ( FORCE32 $ENV{ TRAVIS_CUBERITE_FORCE32 } )
2014-03-07 15:16:16 -05:00
endif ( )
2014-05-10 08:03:36 -04:00
if ( DEFINED ENV{TRAVIS_BUILD_WITH_COVERAGE} )
set ( BUILD_WITH_COVERAGE $ENV{ TRAVIS_BUILD_WITH_COVERAGE } )
endif ( )
2015-08-26 04:58:51 -04:00
if ( DEFINED ENV{CUBERITE_BUILD_ID} )
2015-06-05 04:19:58 -04:00
# The build info is defined by the build system (Travis / Jenkins)
2015-08-26 04:58:51 -04:00
set ( BUILD_ID $ENV{ CUBERITE_BUILD_ID } )
set ( BUILD_SERIES_NAME $ENV{ CUBERITE_BUILD_SERIES_NAME } )
set ( BUILD_DATETIME $ENV{ CUBERITE_BUILD_DATETIME } )
if ( DEFINED ENV{CUBERITE_BUILD_COMMIT_ID} )
set ( BUILD_COMMIT_ID $ENV{ CUBERITE_BUILD_COMMIT_ID } )
2014-09-10 11:07:00 -04:00
else ( )
message ( "Commit id not set, attempting to determine id from git" )
execute_process (
C O M M A N D g i t r e v - p a r s e H E A D
2015-10-09 05:15:40 -04:00
W O R K I N G _ D I R E C T O R Y $ { C M A K E _ C U R R E N T _ L I S T _ D I R }
2014-09-10 11:07:00 -04:00
R E S U L T _ V A R I A B L E G I T _ E X E C U T E D
2015-06-05 04:19:58 -04:00
O U T P U T _ V A R I A B L E B U I L D _ C O M M I T _ I D
)
string ( STRIP ${ BUILD_COMMIT_ID } BUILD_COMMIT_ID )
2014-09-10 11:07:00 -04:00
if ( NOT ( GIT_EXECUTED EQUAL 0 ) )
message ( FATAL_ERROR "Could not identifiy git commit id" )
endif ( )
endif ( )
2015-06-05 04:19:58 -04:00
else ( )
# This is a local build, stuff in some basic info:
set ( BUILD_ID "Unknown" )
set ( BUILD_SERIES_NAME "local build" )
execute_process (
C O M M A N D g i t r e v - p a r s e H E A D
2015-10-09 05:15:40 -04:00
W O R K I N G _ D I R E C T O R Y $ { C M A K E _ C U R R E N T _ L I S T _ D I R }
2015-06-05 04:19:58 -04:00
R E S U L T _ V A R I A B L E G I T _ E X E C U T E D
O U T P U T _ V A R I A B L E B U I L D _ C O M M I T _ I D
)
2015-06-05 07:37:36 -04:00
if ( NOT(GIT_EXECUTED EQUAL 0 ) )
set ( BUILD_COMMIT_ID "Unknown" )
endif ( )
2015-06-05 04:19:58 -04:00
string ( STRIP ${ BUILD_COMMIT_ID } BUILD_COMMIT_ID )
execute_process (
C O M M A N D g i t l o g - 1 - - d a t e = i s o - - p r e t t y = f o r m a t : % a i
2015-10-09 05:15:40 -04:00
W O R K I N G _ D I R E C T O R Y $ { C M A K E _ C U R R E N T _ L I S T _ D I R }
2015-06-05 07:37:36 -04:00
R E S U L T _ V A R I A B L E G I T _ E X E C U T E D
2015-06-05 04:19:58 -04:00
O U T P U T _ V A R I A B L E B U I L D _ D A T E T I M E
)
2015-06-05 07:37:36 -04:00
if ( NOT(GIT_EXECUTED EQUAL 0 ) )
set ( BUILD_DATETIME "Unknown" )
endif ( )
2015-06-05 04:19:58 -04:00
string ( STRIP ${ BUILD_DATETIME } BUILD_DATETIME )
# The BUILD_COMMIT_ID and BUILD_DATETIME aren't updated on each repo pull
# They are only updated when cmake re-configures the project
# Therefore mark them as "approx: "
set ( BUILD_COMMIT_ID "approx: ${BUILD_COMMIT_ID}" )
set ( BUILD_DATETIME "approx: ${BUILD_DATETIME}" )
2014-09-10 11:07:00 -04:00
endif ( )
2020-05-16 15:59:10 -04:00
# We need C++17 features
2020-05-09 11:51:54 -04:00
set ( CMAKE_CXX_STANDARD 17 )
set ( CMAKE_CXX_STANDARD_REQUIRED ON )
set ( CMAKE_CXX_EXTENSIONS OFF )
2020-05-31 15:26:50 -04: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 10:23:29 -04:00
endif ( )
2020-05-16 15:59:10 -04:00
# Static CRT
set ( CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>" )
2016-07-17 10:23:29 -04:00
2014-02-16 08:55:37 -05:00
# This has to be done before any flags have been set up.
2014-02-16 06:37:31 -05:00
if ( ${ BUILD_TOOLS } )
2015-05-03 04:01:19 -04:00
message ( "Building tools" )
2016-03-12 04:49:41 -05:00
add_subdirectory ( Tools/GrownBiomeGenVisualiser/ )
2014-02-16 06:37:31 -05:00
add_subdirectory ( Tools/MCADefrag/ )
2016-11-15 01:38:00 -05:00
add_subdirectory ( Tools/NoiseSpeedTest/ )
2014-02-16 07:30:45 -05:00
add_subdirectory ( Tools/ProtoProxy/ )
2014-02-16 06:37:31 -05:00
endif ( )
if ( ${ BUILD_UNSTABLE_TOOLS } )
2015-05-03 04:01:19 -04:00
message ( "Building unstable tools" )
2014-02-16 06:37:31 -05:00
add_subdirectory ( Tools/GeneratorPerformanceTest/ )
endif ( )
2014-02-15 18:17:58 -05:00
include ( SetFlags.cmake )
set_flags ( )
set_lib_flags ( )
enable_profile ( )
2014-01-14 05:05:57 -05:00
2014-07-28 13:59:53 -04:00
# Set options for SQLiteCpp, disable all their tests and lints:
set ( SQLITECPP_RUN_CPPLINT OFF CACHE BOOL "Run cpplint.py tool for Google C++ StyleGuide." FORCE )
set ( SQLITECPP_RUN_CPPCHECK OFF CACHE BOOL "Run cppcheck C++ static analysis tool." FORCE )
set ( SQLITECPP_RUN_DOXYGEN OFF CACHE BOOL "Run Doxygen C++ documentation tool." FORCE )
set ( SQLITECPP_BUILD_EXAMPLES OFF CACHE BOOL "Build examples." FORCE )
set ( SQLITECPP_BUILD_TESTS OFF CACHE BOOL "Build and run tests." FORCE )
2020-05-09 10:51:15 -04:00
set ( SQLITECPP_INTERNAL_SQLITE ON CACHE BOOL "Add the internal SQLite3 source to the project." FORCE )
2015-06-06 08:22:56 -04:00
set ( SQLITE_ENABLE_COLUMN_METADATA OFF CACHE BOOL "" FORCE )
2014-07-28 13:59:53 -04:00
2015-01-05 16:14:48 -05:00
# Set options for LibEvent, disable all their tests and benchmarks:
2019-09-04 17:34:54 -04:00
set ( EVENT__DISABLE_OPENSSL YES CACHE BOOL "Disable OpenSSL in LibEvent" FORCE )
set ( EVENT__DISABLE_BENCHMARK YES CACHE BOOL "Disable LibEvent benchmarks" FORCE )
set ( EVENT__DISABLE_TESTS YES CACHE BOOL "Disable LibEvent tests" FORCE )
set ( EVENT__DISABLE_REGRESS YES CACHE BOOL "Disable LibEvent regression tests" FORCE )
set ( EVENT__DISABLE_SAMPLES YES CACHE BOOL "Disable LibEvent samples" FORCE )
set ( EVENT__LIBRARY_TYPE "STATIC" CACHE STRING "Use static LibEvent libraries" FORCE )
2015-01-05 16:14:48 -05:00
2020-05-16 15:59:10 -04:00
# Set options for JsonCPP, disabling all of their tests:
2015-05-08 20:22:33 -04:00
set ( JSONCPP_WITH_TESTS OFF CACHE BOOL "Compile and (for jsoncpp_check) run JsonCpp test executables" )
set ( JSONCPP_WITH_POST_BUILD_UNITTEST OFF CACHE BOOL "Automatically run unit-tests as a post build step" )
set ( JSONCPP_WITH_PKGCONFIG_SUPPORT OFF CACHE BOOL "Generate and install .pc files" )
2020-05-16 15:59:10 -04:00
# Set options for mbedtls:
set ( ENABLE_PROGRAMS OFF CACHE BOOL "Build mbed TLS programs." )
set ( ENABLE_TESTING OFF CACHE BOOL "Build mbed TLS tests." )
2015-05-08 20:22:33 -04:00
2015-01-09 14:38:25 -05:00
# Check that the libraries are present:
2016-11-07 17:15:07 -05:00
if ( NOT EXISTS ${ PROJECT_SOURCE_DIR } /lib/SQLiteCpp/CMakeLists.txt )
2015-01-09 14:38:25 -05:00
message ( FATAL_ERROR "SQLiteCpp is missing in folder lib/SQLiteCpp. Have you initialized the submodules / downloaded the extra libraries?" )
endif ( )
2017-08-30 10:00:06 -04:00
if ( NOT EXISTS ${ PROJECT_SOURCE_DIR } /lib/mbedtls/CMakeLists.txt )
message ( FATAL_ERROR "mbedTLS is missing in folder lib/mbedtls. Have you initialized the submodules / downloaded the extra libraries?" )
2015-01-09 14:38:25 -05:00
endif ( )
2016-11-07 17:15:07 -05:00
if ( NOT EXISTS ${ PROJECT_SOURCE_DIR } /lib/libevent/CMakeLists.txt )
2015-01-05 16:14:48 -05:00
message ( FATAL_ERROR "LibEvent is missing in folder lib/libevent. Have you initialized and updated the submodules / downloaded the extra libraries?" )
endif ( )
2016-11-07 17:15:07 -05:00
if ( NOT EXISTS ${ PROJECT_SOURCE_DIR } /lib/jsoncpp/CMakeLists.txt )
2015-08-10 03:55:35 -04:00
message ( FATAL_ERROR "JsonCPP is missing in folder lib/jsoncpp. Have you initialized and updated the submodules / downloaded the extra libraries?" )
endif ( )
2016-11-07 17:15:07 -05:00
if ( NOT EXISTS ${ PROJECT_SOURCE_DIR } /lib/cmake-coverage/CodeCoverage.cmake )
2015-11-04 16:32:11 -05:00
message ( FATAL_ERROR "cmake-coverage is missing in folder lib/cmake-coverage. Have you initialized and updated the submodules / downloaded the extra libraries?" )
endif ( )
2016-11-07 17:15:07 -05:00
if ( NOT EXISTS ${ PROJECT_SOURCE_DIR } /lib/expat/CMakeLists.txt )
2015-11-04 16:32:11 -05:00
message ( FATAL_ERROR "expat is missing in folder lib/expat. Have you initialized and updated the submodules / downloaded the extra libraries?" )
endif ( )
2018-01-03 12:41:16 -05:00
if ( NOT EXISTS ${ PROJECT_SOURCE_DIR } /lib/fmt/CMakeLists.txt )
message ( FATAL_ERROR "fmt is missing in folder lib/fmt. Have you initialized and updated the submodules / downloaded the extra libraries?" )
endif ( )
2016-11-07 17:15:07 -05:00
if ( NOT EXISTS ${ PROJECT_SOURCE_DIR } /lib/lua/CMakeLists.txt )
2015-11-04 16:32:11 -05:00
message ( FATAL_ERROR "lua is missing in folder lib/lua. Have you initialized and updated the submodules / downloaded the extra libraries?" )
endif ( )
2016-11-07 17:15:07 -05:00
if ( NOT EXISTS ${ PROJECT_SOURCE_DIR } /lib/luaexpat/CMakeLists.txt )
2015-11-04 16:32:11 -05:00
message ( FATAL_ERROR "luaexpat is missing in folder lib/luaexpat. Have you initialized and updated the submodules / downloaded the extra libraries?" )
endif ( )
2016-11-07 17:15:07 -05:00
if ( NOT EXISTS ${ PROJECT_SOURCE_DIR } /lib/luaproxy/CMakeLists.txt )
2015-11-04 16:32:11 -05:00
message ( FATAL_ERROR "luaproxy is missing in folder lib/luaproxy. Have you initialized and updated the submodules / downloaded the extra libraries?" )
endif ( )
2016-11-07 17:15:07 -05:00
if ( NOT EXISTS ${ PROJECT_SOURCE_DIR } /lib/sqlite/CMakeLists.txt )
2015-11-04 16:32:11 -05:00
message ( FATAL_ERROR "sqlite is missing in folder lib/sqlite. Have you initialized and updated the submodules / downloaded the extra libraries?" )
endif ( )
2016-11-07 17:15:07 -05:00
if ( NOT EXISTS ${ PROJECT_SOURCE_DIR } /lib/tolua++/CMakeLists.txt )
2015-11-04 16:32:11 -05:00
message ( FATAL_ERROR "tolua++ is missing in folder lib/tolua++. Have you initialized and updated the submodules / downloaded the extra libraries?" )
endif ( )
2016-11-07 17:15:07 -05:00
if ( NOT EXISTS ${ PROJECT_SOURCE_DIR } /lib/zlib/CMakeLists.txt )
2015-11-04 16:32:11 -05:00
message ( FATAL_ERROR "zlib is missing in folder lib/zlib. Have you initialized and updated the submodules / downloaded the extra libraries?" )
endif ( )
2020-05-16 15:59:10 -04:00
# Include all the libraries
# We use EXCLUDE_FROM_ALL so that only the explicit dependencies are compiled
# (mbedTLS also has test and example programs in their CMakeLists.txt, we don't want those):
add_subdirectory ( lib/expat )
add_subdirectory ( lib/fmt )
add_subdirectory ( lib/jsoncpp EXCLUDE_FROM_ALL )
add_subdirectory ( lib/libevent EXCLUDE_FROM_ALL )
add_subdirectory ( lib/lua )
add_subdirectory ( lib/luaexpat )
add_subdirectory ( lib/mbedtls )
add_subdirectory ( lib/SQLiteCpp ) # SQLiteCpp needs to be included before sqlite so the lsqlite target is available
add_subdirectory ( lib/sqlite )
add_subdirectory ( lib/tolua++ EXCLUDE_FROM_ALL )
add_subdirectory ( lib/zlib )
2015-11-04 16:32:11 -05:00
2020-05-16 15:59:10 -04:00
set_exe_flags ( )
add_executable ( ${ CMAKE_PROJECT_NAME } )
add_subdirectory ( src )
2015-11-04 16:32:11 -05:00
2020-05-16 15:59:10 -04: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-09 14:38:25 -05:00
2020-05-16 15:59:10 -04: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-03 12:41:16 -05:00
2020-05-16 15:59:10 -04:00
if ( UNITY_BUILDS )
set_target_properties ( ${ CMAKE_PROJECT_NAME } PROPERTIES UNITY_BUILD ON )
endif ( )
else ( )
message ( WARNING "Precompiled headers for FASTER BUILDS not enabled, upgrade to CMake 1.16 or newer!" )
endif ( )
2013-12-10 16:39:20 -05:00
2020-05-16 15:59:10 -04:00
# Add required includes:
target_include_directories (
$ { C M A K E _ P R O J E C T _ N A M E } S Y S T E M P R I V A T E
l i b / m b e d t l s / i n c l u d e
l i b / T C L A P / i n c l u d e
l i b # TODO fix files including zlib/x instead of x
)
# Link dependencies as private:
target_link_libraries (
$ { C M A K E _ P R O J E C T _ N A M E } P R I V A T E
e v e n t _ c o r e
e v e n t _ e x t r a
f m t : : f m t
j s o n c p p _ l i b
l s q l i t e
l u a
l u a e x p a t
m b e d t l s
S Q L i t e C p p
t o l u a l i b
z l i b
)
# Link process information library:
if ( WIN32 )
target_link_libraries ( ${ CMAKE_PROJECT_NAME } PRIVATE Psapi.lib )
endif ( )
2015-01-13 08:44:03 -05:00
2020-05-16 15:59:10 -04:00
# Special case handling for libevent pthreads:
if ( NOT WIN32 )
target_link_libraries ( ${ CMAKE_PROJECT_NAME } PRIVATE event_pthreads_static )
endif ( )
# Prettify jsoncpp_lib name in VS solution explorer:
2020-05-09 10:51:15 -04:00
set_property ( TARGET jsoncpp_lib PROPERTY PROJECT_LABEL "jsoncpp" )
2015-07-09 18:43:23 -04:00
2014-06-24 08:48:18 -04:00
if ( WIN32 )
2020-05-16 15:59:10 -04:00
add_subdirectory ( lib/luaproxy )
2014-06-24 08:48:18 -04:00
endif ( )
2020-05-16 15:59:10 -04: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-22 16:19:33 -05:00
2020-05-16 15:59:10 -04: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 )
2017-08-22 15:56:32 -04:00
endif ( )
2020-05-16 15:59:10 -04:00
# Self Test Mode enables extra checks at startup
2014-04-27 15:25:03 -04:00
if ( ${ SELF_TEST } )
2015-01-11 04:43:02 -05:00
message ( "Tests enabled" )
2014-04-27 15:25:03 -04:00
enable_testing ( )
2016-11-07 17:15:07 -05:00
add_subdirectory ( tests )
2014-04-27 15:25:03 -04:00
endif ( )
2020-05-16 15:59:10 -04:00
include ( "CMake/Fixups.cmake" )
include ( "CMake/GenerateBindings.cmake" )
include ( "CMake/GroupSources.cmake" )
# TODO: include("CMake/SetCompilerFlags.cmake")