1
0

Upgrade to C++17 [CMake] (#4717)

* Make our CMake slightly less insane
This commit is contained in:
Tiger Wang 2020-05-16 20:59:10 +01:00 committed by GitHub
parent 21ef9e3819
commit 9e8598fb1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
55 changed files with 457 additions and 762 deletions

View File

@ -5,13 +5,7 @@ cache: ccache
os: linux
dist: bionic
# CMake version out of date: update
# TODO: add ARM64, PPC, SPARC builds when we find CMake for them
addons:
snaps:
- name: cmake
confinement: classic
channel: latest
# TODO: add ARM64, PPC, IBM builds when we find CMake for them
jobs:
include:
@ -22,7 +16,7 @@ jobs:
before_install:
- HOMEBREW_NO_AUTO_UPDATE=1 brew install ccache
env: &Release
- TRAVIS_CUBERITE_BUILD_TYPE=RELEASE
- TRAVIS_CUBERITE_BUILD_TYPE=Release
- name: "AppleClang - Debug"
os: osx
@ -30,12 +24,14 @@ jobs:
before_install:
- HOMEBREW_NO_AUTO_UPDATE=1 brew install ccache
env: &Debug
- TRAVIS_CUBERITE_BUILD_TYPE=DEBUG
- TRAVIS_CUBERITE_BUILD_TYPE=Debug
- name: "Clang 7.0 - Release"
compiler: clang
before_install: &use-cmake
- export PATH=/snap/bin/:${PATH}
- wget --output-document=${HOME}/CMake http://cmake.org/files/v3.17/cmake-3.17.2-Linux-x86_64.tar.gz
- tar --extract --one-top-level=${HOME}/SeeMake --strip-components 1 --file ${HOME}/CMake
- export PATH=${HOME}/SeeMake/bin/:${PATH}
env: *Release
- name: "Clang 7.0 - Debug"
@ -43,9 +39,15 @@ jobs:
before_install: *use-cmake
env: *Debug
- name: "GCC 7.4 - Release, CMake 3.12"
- name: "GCC 7.4 - Release, CMake 3.12, No Unity"
compiler: gcc
env: *Release
before_install:
- wget --output-document=${HOME}/CMake http://cmake.org/files/v3.13/cmake-3.13.0-Linux-x86_64.tar.gz
- tar --extract --one-top-level=${HOME}/SeeMake --strip-components 1 --file ${HOME}/CMake
- export PATH=${HOME}/SeeMake/bin/:${PATH}
env:
- TRAVIS_CUBERITE_BUILD_TYPE=Release
- TRAVIS_CUBERITE_UNITY_BUILDS=No
- name: "GCC 7.4 - Debug"
compiler: gcc

14
CMake/Fixups.cmake Normal file
View File

@ -0,0 +1,14 @@
# TODO these should be in the submodules
# Under Windows, we need Lua as DLL; on *nix we need it linked statically:
if (WIN32)
target_compile_definitions(lua PUBLIC LUA_BUILD_AS_DLL)
endif()
# Let Lua use additional checks on its C API. This is only compiled into Debug builds:
target_compile_definitions(lua PRIVATE LUA_USE_APICHECK)
if(NOT MSVC AND "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "arm")
# mbed TLS uses the frame pointer's register in inline assembly for its bignum implementation:
# https://tls.mbed.org/kb/development/arm-thumb-error-r7-cannot-be-used-in-asm-here
target_compile_options(mbedcrypto PRIVATE -fomit-frame-pointer)
endif()

View File

@ -0,0 +1,112 @@
# Enumerate every Lua-exported class.
# Changes to these files will cause binding regen:
set(BINDING_DEPENDENCIES
Bindings/AllToLua.pkg
Bindings/BindingsProcessor.lua
Bindings/LuaFunctions.h
Bindings/LuaWindow.h
Bindings/Plugin.h
Bindings/PluginLua.h
Bindings/PluginManager.h
BiomeDef.h
BlockArea.h
BlockEntities/BeaconEntity.h
BlockEntities/BedEntity.h
BlockEntities/BlockEntity.h
BlockEntities/BlockEntityWithItems.h
BlockEntities/BrewingstandEntity.h
BlockEntities/ChestEntity.h
BlockEntities/CommandBlockEntity.h
BlockEntities/DispenserEntity.h
BlockEntities/DropSpenserEntity.h
BlockEntities/DropperEntity.h
BlockEntities/FurnaceEntity.h
BlockEntities/HopperEntity.h
BlockEntities/JukeboxEntity.h
BlockEntities/MobSpawnerEntity.h
BlockEntities/NoteEntity.h
BlockEntities/SignEntity.h
BlockEntities/MobHeadEntity.h
BlockEntities/FlowerPotEntity.h
BlockType.h
BlockInfo.h
BoundingBox.h
ChatColor.h
ChunkDef.h
ClientHandle.h
Color.h
CompositeChat.h
CraftingRecipes.h
Cuboid.h
Defines.h
EffectID.h
Enchantments.h
Entities/Boat.h
Entities/ArrowEntity.h
Entities/Entity.h
Entities/ExpOrb.h
Entities/EntityEffect.h
Entities/ExpBottleEntity.h
Entities/FallingBlock.h
Entities/FireChargeEntity.h
Entities/FireworkEntity.h
Entities/Floater.h
Entities/GhastFireballEntity.h
Entities/HangingEntity.h
Entities/ItemFrame.h
Entities/LeashKnot.h
Entities/Pawn.h
Entities/Player.h
Entities/Painting.h
Entities/Pickup.h
Entities/ProjectileEntity.h
Entities/SplashPotionEntity.h
Entities/ThrownEggEntity.h
Entities/ThrownEnderPearlEntity.h
Entities/ThrownSnowballEntity.h
Entities/TNTEntity.h
Entities/WitherSkullEntity.h
Generating/ChunkDesc.h
IniFile.h
Inventory.h
Item.h
ItemGrid.h
Map.h
MapManager.h
Mobs/Monster.h
Mobs/MonsterTypes.h
OSSupport/File.h
Protocol/MojangAPI.h
Root.h
Scoreboard.h
Server.h
Statistics.h
StringUtils.h
UI/Window.h
UUID.h
Vector3.h
WebAdmin.h
World.h
)
# List all the files that are generated as part of the Bindings build process:
set(BINDING_OUTPUTS
Bindings.cpp
Bindings.h
LuaState_Declaration.inc
LuaState_Implementation.cpp
LuaState_Typedefs.inc
)
# Make the file paths absolute and pointing to the bindings folder:
set(BINDINGS_FOLDER "${PROJECT_SOURCE_DIR}/src/Bindings/")
list(TRANSFORM BINDING_OUTPUTS PREPEND ${BINDINGS_FOLDER})
list(TRANSFORM BINDING_DEPENDENCIES PREPEND "${PROJECT_SOURCE_DIR}/src/")
# Generate the bindings:
add_custom_command(
OUTPUT ${BINDING_OUTPUTS}
COMMAND luaexe BindingsProcessor.lua
WORKING_DIRECTORY ${BINDINGS_FOLDER}
DEPENDS ${BINDING_DEPENDENCIES} luaexe
)

42
CMake/GroupSources.cmake Normal file
View File

@ -0,0 +1,42 @@
# Enable the support for solution folders in MSVC
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# Put projects into solution folders in MSVC:
set_target_properties(
event_core_static
event_extra_static
expat
fmt
jsoncpp_lib
lua
luaexpat
mbedcrypto
mbedtls
mbedx509
lsqlite
sqlite3
SQLiteCpp
tolualib
zlib
PROPERTIES FOLDER Libraries
)
# luaproxy not generated on anything else
if(WIN32)
set_target_properties(
luaproxy
PROPERTIES FOLDER Support
)
endif()
if(${BUILD_TOOLS})
set_target_properties(
MCADefrag
ProtoProxy
PROPERTIES FOLDER Tools
)
endif()
# Put all files into one project, separate by the folders:
get_property(TARGET_SOURCE_FILES TARGET ${CMAKE_PROJECT_NAME} PROPERTY SOURCES)
source_group(TREE "${PROJECT_SOURCE_DIR}/src" FILES ${TARGET_SOURCE_FILES})

View File

@ -13,19 +13,18 @@
cmake_minimum_required (VERSION 3.12.4)
cmake_minimum_required (VERSION 3.13)
project(
Cuberite
DESCRIPTION "A lightweight, fast and extensible game server for Minecraft"
HOMEPAGE_URL "https://cuberite.org"
LANGUAGES C CXX
)
if (POLICY CMP0054)
cmake_policy(SET CMP0054 NEW)
endif()
# Without this, the MSVC variable isn't defined for MSVC builds ( https://cmake.org/pipermail/cmake/2011-November/047130.html )
enable_language(CXX C)
# Enable the support for solution folders in MSVC
if (MSVC)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
endif()
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)
# These env variables are used for configuring Travis CI builds.
if(DEFINED ENV{TRAVIS_CUBERITE_BUILD_TYPE})
@ -93,54 +92,20 @@ else()
set(BUILD_DATETIME "approx: ${BUILD_DATETIME}")
endif()
# We need C++11 features, Visual Studio has those from VS2012, but it needs a new platform toolset for those; VS2013 supports them natively:
# Adapted from https://web.archive.org/web/https://binglongx.wordpress.com/2013/06/28/set-non-default-platform-toolset-in-cmake/
if(MSVC OR MSVC_IDE)
if( MSVC_VERSION LESS 1700 ) # VC10- / VS2010-
message(FATAL_ERROR "The project requires C++11 features. "
"You need at least Visual Studio 11 (Microsoft Visual Studio 2012), "
"with Microsoft Visual C++ Compiler Nov 2012 CTP (v120_CTP_Nov2012).")
elseif( MSVC_VERSION EQUAL 1700 ) # VC11 / VS2012
message( "VC11: using Microsoft Visual Studio 2012 "
"with Microsoft Visual C++ Compiler Nov 2012 CTP (v120_CTP_Nov2012)" )
set(CMAKE_GENERATOR_TOOLSET "v120_CTP_Nov2012" CACHE STRING "Platform Toolset" FORCE)
else() # VC12+, assuming C++11 supported.
endif()
else() # GCC or Clang, so get compiler version directly since CMAKE_CXX_COMPILER_VERSION is only available in CMake 2.8.8 and later
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE DUMPED_COMPILER_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
# Check for gcc version 4.8 or greater
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND DUMPED_COMPILER_VERSION VERSION_LESS "4.8")
message(FATAL_ERROR "You have ${CMAKE_CXX_COMPILER_ID} version ${DUMPED_COMPILER_VERSION}, but at least 4.8 is needed")
endif()
# Check for clang version 3.4 or greater
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND DUMPED_COMPILER_VERSION VERSION_LESS "3.4")
message(FATAL_ERROR "You have ${CMAKE_CXX_COMPILER_ID} version ${DUMPED_COMPILER_VERSION}, but at least 3.4 is needed")
endif()
endif()
# We need C++17 features
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(BUILD_TOOLS OFF CACHE BOOL "")
set(SELF_TEST OFF CACHE BOOL "")
# Check whether Lua can be used:
if (NOT(DISABLE_SYSTEM_LUA))
include(CheckLua.cmake)
if(HAS_LUA_INTERPRETER)
message(STATUS "Lua has been found in your system and will be used for the build.")
set(USE_SYSTEM_LUA 1)
else()
message(STATUS "Lua has NOT been found in your system, the build will use its own Lua implementation.")
unset(USE_SYSTEM_LUA)
endif()
else()
message(STATUS "System Lua is disabled via CMake command-line parameters. The build will use its own Lua implementation.")
# The need for speed (in Release)
include(CheckIPOSupported)
check_ipo_supported(RESULT IPO_SUPPORTED)
if(IPO_SUPPORTED)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON)
endif()
# Static CRT
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
# This has to be done before any flags have been set up.
if(${BUILD_TOOLS})
@ -161,31 +126,6 @@ set_flags()
set_lib_flags()
enable_profile()
# Under Windows, we need Lua as DLL; on *nix we need it linked statically:
if (WIN32)
add_definitions(-DLUA_BUILD_AS_DLL)
endif()
# The Expat library is linked in statically, make the source files aware of that:
add_definitions(-DXML_STATIC)
# Let Lua use additional checks on its C API. This is only compiled into Debug builds:
add_definitions(-DLUA_USE_APICHECK)
# Self Test Mode enables extra checks at startup
if(${SELF_TEST})
add_definitions(-DSELF_TEST)
endif()
# Build all dependent libraries as static:
SET(CMAKE_BUILD_STATIC_LIBRARIES ON)
####
project (Cuberite)
# 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)
@ -203,12 +143,14 @@ set(EVENT__DISABLE_REGRESS YES CACHE BOOL "Disable LibEvent regression tests
set(EVENT__DISABLE_SAMPLES YES CACHE BOOL "Disable LibEvent samples" FORCE)
set(EVENT__LIBRARY_TYPE "STATIC" CACHE STRING "Use static LibEvent libraries" FORCE)
# Set options for JsonCPP, disabling all of their tests
# Additionally, their library is output to a strange location; make sure the linker knows where to find it
# Set options for JsonCPP, disabling all of their tests:
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")
link_directories(lib/jsoncpp/src/lib_json)
# Set options for mbedtls:
set(ENABLE_PROGRAMS OFF CACHE BOOL "Build mbed TLS programs.")
set(ENABLE_TESTING OFF CACHE BOOL "Build mbed TLS tests.")
# Check that the libraries are present:
if (NOT EXISTS ${PROJECT_SOURCE_DIR}/lib/SQLiteCpp/CMakeLists.txt)
@ -251,84 +193,102 @@ if (NOT EXISTS ${PROJECT_SOURCE_DIR}/lib/zlib/CMakeLists.txt)
message(FATAL_ERROR "zlib is missing in folder lib/zlib. Have you initialized and updated the submodules / downloaded the extra libraries?")
endif()
# Include all the libraries:
add_subdirectory(lib/jsoncpp/ EXCLUDE_FROM_ALL)
add_subdirectory(lib/zlib/)
add_subdirectory(lib/lua/)
add_subdirectory(lib/tolua++/ EXCLUDE_FROM_ALL)
add_subdirectory(lib/SQLiteCpp/)
add_subdirectory(lib/sqlite/)
add_subdirectory(lib/expat/)
add_subdirectory(lib/luaexpat/)
add_subdirectory(lib/libevent/ EXCLUDE_FROM_ALL)
# 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 proper includes for LibEvent's event-config.h header:
include_directories(SYSTEM ${LIBEVENT_INCLUDE_DIRS})
# Prettify jsoncpp_lib name in VS solution explorer
set_property(TARGET jsoncpp_lib PROPERTY PROJECT_LABEL "jsoncpp")
# jsoncpp uses these for ccache support, clashing with our method
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "")
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "")
if (WIN32)
add_subdirectory(lib/luaproxy/)
endif()
# We use EXCLUDE_FROM_ALL so that only the explicit dependencies are used
# (mbedTLS also has test and example programs in their CMakeLists.txt, we don't want those)
include(lib/mbedtls.cmake EXCLUDE_FROM_ALL)
if(NOT MSVC AND "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "arm")
# mbed TLS uses the frame pointer's register in inline assembly for its bignum implementation:
# https://tls.mbed.org/kb/development/arm-thumb-error-r7-cannot-be-used-in-asm-here
target_compile_options(mbedcrypto PRIVATE -fomit-frame-pointer)
endif()
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)
set_exe_flags()
add_executable(${CMAKE_PROJECT_NAME})
add_subdirectory(src)
# 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()
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()
# Add required includes:
target_include_directories(
${CMAKE_PROJECT_NAME} SYSTEM PRIVATE
${CMAKE_CURRENT_BINARY_DIR}/lib/libevent/include # TODO: remove when updating libevent
lib/libevent/include
lib/mbedtls/include
lib/TCLAP/include
lib # TODO fix files including zlib/x instead of x
)
# Link dependencies as private:
target_link_libraries(
${CMAKE_PROJECT_NAME} PRIVATE
event_core
event_extra
fmt::fmt
jsoncpp_lib
lsqlite
lua
luaexpat
mbedtls
SQLiteCpp
tolualib
zlib
)
# Link process information library:
if (WIN32)
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE Psapi.lib)
endif()
# 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:
set_property(TARGET jsoncpp_lib PROPERTY PROJECT_LABEL "jsoncpp")
if (WIN32)
add_subdirectory(lib/luaproxy)
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("${CMAKE_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("${CMAKE_SOURCE_DIR}/src/IniFile.cpp" PROPERTIES COMPILE_OPTIONS -Wno-header-hygiene)
endif()
# Self Test Mode enables extra checks at startup
if(${SELF_TEST})
message("Tests enabled")
enable_testing()
add_subdirectory(tests)
endif()
# Put projects into solution folders in MSVC:
if (MSVC)
set_target_properties(
event_core_static
event_extra_static
expat
fmt
jsoncpp_lib
lua
luaexpat
mbedcrypto
mbedtls
mbedx509
lsqlite
SQLiteCpp
tolualib
zlib
PROPERTIES FOLDER Lib
)
set_target_properties(
luaproxy
PROPERTIES FOLDER Support
)
if(${BUILD_TOOLS})
set_target_properties(
MCADefrag
ProtoProxy
PROPERTIES FOLDER Tools
)
endif()
endif()
include("CMake/Fixups.cmake")
include("CMake/GenerateBindings.cmake")
include("CMake/GroupSources.cmake")
# TODO: include("CMake/SetCompilerFlags.cmake")

View File

@ -63,6 +63,14 @@ macro(set_flags)
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /LTCG")
set(CMAKE_MODULE_LINKER_FLAGS_RELEASE "${CMAKE_MODULE_LINKER_FLAGS_RELEASE} /LTCG")
# Make MSVC generate the PDB files even for the release build
# (TODO: have AppVeyor build RelWithDebInfo and remove):
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /Zi")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /DEBUG")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG")
set(CMAKE_MODULE_LINKER_FLAGS_RELEASE "${CMAKE_MODULE_LINKER_FLAGS_RELEASE} /DEBUG")
# Make build use Unicode:
add_definitions(-DUNICODE -D_UNICODE)
elseif(APPLE)

View File

@ -21,7 +21,6 @@ function(flatten_files arg1)
set(${arg1} "${res}" PARENT_SCOPE)
endfunction()
include(../../lib/mbedtls.cmake)
add_subdirectory(../../lib/zlib ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/lib/zlib)
set_exe_flags()

View File

@ -249,11 +249,6 @@ around it, "(32 KiB)") */
// Pretty much the same as ASSERT() but stays in Release builds
#define VERIFY( x) ( !!(x) || ( LOGERROR("Verification failed: %s, file %s, line %i", #x, __FILE__, __LINE__), exit(1), 0))
// Same as assert but in all Self test builds
#ifdef SELF_TEST
#define assert_test(x) ( !!(x) || (assert(!#x), exit(1), 0))
#endif
// C++11 has std::shared_ptr in <memory>, included earlier
#define SharedPtr std::shared_ptr

View File

@ -9,7 +9,10 @@ ARGS="-header-filter $REGEX -quiet -export-fixes $FIXES_FILE "$@" $REGEX"
# Generate the compilation database
mkdir -p tidy-build
cd tidy-build
cmake --target Cuberite -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..
# Disable precompiled headers since they aren't generated during linting which causes an error
# Disable unity builds since clang-tidy needs the full list of compiled files to check each one
cmake --target Cuberite -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DPRECOMPILE_HEADERS=OFF -DUNITY_BUILDS=OFF ..
# Ensure LuaState_Typedefs.inc has been generated
(cd ../src/Bindings && lua BindingsProcessor.lua)

@ -1 +1 @@
Subproject commit 829d549af3a11e24fcb0b99090837dac9a9aae4f
Subproject commit 6aec7cf646e9d0e49b0000c3d5b74de9c3222ef2

@ -1 +1 @@
Subproject commit ec3ddcfe41b0544a4551a57439b6b3682fe31479
Subproject commit 12cee38782897cfe60a1611615c200c45cd99eaf

@ -1 +1 @@
Subproject commit 75f059124b8e9d3d442d1907344187f15e34e6b6
Subproject commit e87c7903718ed7e05cbb614bbc385553987a2d33

@ -1 +1 @@
Subproject commit d2e6a971f4544c55b8e3b25cf96db266971b778f
Subproject commit b8cb8889aab726a35c49472228256f7bb1d44388

@ -1 +1 @@
Subproject commit 6d57f1c3c4face973f0405b2a3c0fb8471a79d92
Subproject commit e5942d9d88221dc02b824f5bda0db9876fa92bad

@ -1 +1 @@
Subproject commit bf6adc1f92708600707c0a8603b45a9de9a8fe14
Subproject commit 368e2927fcd227bf0af91b3e4b92e740196425cd

@ -1 +1 @@
Subproject commit 9a17fd73198c645c924996c0aee7836f51bcf7bb
Subproject commit 01cbf6d5a5ba91dd78d17604865dd3aebe1b5093

@ -1 +1 @@
Subproject commit 4a814cf1759c8a1d0917344397a84c917c74de97
Subproject commit 23cd44840dc9405f4f7df34a621a351062359b8d

@ -1 +1 @@
Subproject commit 2ea59173610490eb48e29de44bd6e04324d84995
Subproject commit a9c7b30641ed8b86590141a1b4025263bce4c881

View File

@ -1,5 +1,6 @@
target_sources(
${CMAKE_PROJECT_NAME} PRIVATE
SET (SRCS
Bindings.cpp
DeprecatedBindings.cpp
LuaChunkStay.cpp
@ -19,9 +20,7 @@ SET (SRCS
Plugin.cpp
PluginLua.cpp
PluginManager.cpp
)
SET (HDRS
Bindings.h
DeprecatedBindings.h
LuaChunkStay.h
@ -41,133 +40,3 @@ SET (HDRS
PluginManager.h
tolua++.h
)
# List all the files that are generated as part of the Bindings build process
set (BINDING_OUTPUTS
${CMAKE_CURRENT_SOURCE_DIR}/Bindings.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Bindings.h
${CMAKE_CURRENT_SOURCE_DIR}/LuaState_Declaration.inc
${CMAKE_CURRENT_SOURCE_DIR}/LuaState_Implementation.cpp
${CMAKE_CURRENT_SOURCE_DIR}/LuaState_Typedefs.inc
)
set(BINDING_DEPENDENCIES
../Bindings/AllToLua.pkg
../Bindings/BindingsProcessor.lua
../Bindings/LuaFunctions.h
../Bindings/LuaWindow.h
../Bindings/Plugin.h
../Bindings/PluginLua.h
../Bindings/PluginManager.h
../BiomeDef.h
../BlockArea.h
../BlockEntities/BeaconEntity.h
../BlockEntities/BedEntity.h
../BlockEntities/BlockEntity.h
../BlockEntities/BlockEntityWithItems.h
../BlockEntities/BrewingstandEntity.h
../BlockEntities/ChestEntity.h
../BlockEntities/CommandBlockEntity.h
../BlockEntities/DispenserEntity.h
../BlockEntities/DropSpenserEntity.h
../BlockEntities/DropperEntity.h
../BlockEntities/FurnaceEntity.h
../BlockEntities/HopperEntity.h
../BlockEntities/JukeboxEntity.h
../BlockEntities/MobSpawnerEntity.h
../BlockEntities/NoteEntity.h
../BlockEntities/SignEntity.h
../BlockEntities/MobHeadEntity.h
../BlockEntities/FlowerPotEntity.h
../BlockType.h
../BlockInfo.h
../BoundingBox.h
../ChatColor.h
../ChunkDef.h
../ClientHandle.h
../Color.h
../CompositeChat.h
../CraftingRecipes.h
../Cuboid.h
../Defines.h
../EffectID.h
../Enchantments.h
../Entities/Boat.h
../Entities/ArrowEntity.h
../Entities/Entity.h
../Entities/ExpOrb.h
../Entities/EntityEffect.h
../Entities/ExpBottleEntity.h
../Entities/FallingBlock.h
../Entities/FireChargeEntity.h
../Entities/FireworkEntity.h
../Entities/Floater.h
../Entities/GhastFireballEntity.h
../Entities/HangingEntity.h
../Entities/ItemFrame.h
../Entities/LeashKnot.h
../Entities/Pawn.h
../Entities/Player.h
../Entities/Painting.h
../Entities/Pickup.h
../Entities/ProjectileEntity.h
../Entities/SplashPotionEntity.h
../Entities/ThrownEggEntity.h
../Entities/ThrownEnderPearlEntity.h
../Entities/ThrownSnowballEntity.h
../Entities/TNTEntity.h
../Entities/WitherSkullEntity.h
../Generating/ChunkDesc.h
../IniFile.h
../Inventory.h
../Item.h
../ItemGrid.h
../Map.h
../MapManager.h
../Mobs/Monster.h
../Mobs/MonsterTypes.h
../OSSupport/File.h
../Protocol/MojangAPI.h
../Root.h
../Scoreboard.h
../Server.h
../Statistics.h
../StringUtils.h
../UI/Window.h
../UUID.h
../Vector3.h
../WebAdmin.h
../World.h
)
if (NOT MSVC)
if (USE_SYSTEM_LUA)
ADD_CUSTOM_COMMAND(
OUTPUT ${BINDING_OUTPUTS}
COMMAND lua BindingsProcessor.lua
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${BINDING_DEPENDENCIES}
)
else()
ADD_CUSTOM_COMMAND(
OUTPUT ${BINDING_OUTPUTS}
COMMAND luaexe BindingsProcessor.lua
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${BINDING_DEPENDENCIES} luaexe
)
endif()
endif ()
set_source_files_properties(${BINDING_OUTPUTS} PROPERTIES GENERATED TRUE)
set_source_files_properties(${CMAKE_SOURCE_DIR}/src/Bindings/Bindings.cpp PROPERTIES COMPILE_FLAGS -Wno-error)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set_source_files_properties(Bindings.cpp PROPERTIES COMPILE_FLAGS
"-Wno-old-style-cast -Wno-missing-prototypes -Wno-deprecated-declarations")
endif()
if(NOT MSVC)
add_library(Bindings ${SRCS} ${HDRS})
target_link_libraries(Bindings fmt::fmt lua lsqlite tolualib mbedtls HTTPServer SQLiteCpp)
endif()

View File

@ -19,8 +19,8 @@ local g_ShouldIgnorePkg =
local g_ShouldIgnoreCMake =
{
["tolua"] = true,
["../Bindings/AllToLua.pkg"] = true,
["../Bindings/BindingsProcessor.lua"] = true,
["Bindings/AllToLua.pkg"] = true,
["Bindings/BindingsProcessor.lua"] = true,
}
@ -37,7 +37,17 @@ local function getAllToLuaPkgFiles()
if (g_ShouldIgnorePkg[a_FileName]) then
return
end
a_FileName = a_FileName:gsub("../Bindings/", "") -- Normalize the path
-- Normalize the path: AllToLua is relative to src\Bindings
-- but the CMake dependencies list is relative to src\
a_FileName, cnt = a_FileName:gsub("%.%./", "")
-- If no replacements were done, this entry must point to a file
-- inside the Bindings folder; normalize it
if cnt == 0 then
a_FileName = "Bindings/" .. a_FileName
end
table.insert(res, a_FileName)
res[a_FileName] = true
end
@ -54,7 +64,7 @@ end
--- Returns a sorted list of all files listed as dependencies in CMakeLists.txt
-- The returned table has both an array part (list of files) and a dictionary part ("filename" -> true)
local function getCMakeListsFiles()
local f = assert(io.open("CMakeLists.txt", "r"))
local f = assert(io.open("../../CMake/GenerateBindings.cmake", "r"))
local contents = f:read("*all")
f:close()
local res = {}
@ -69,7 +79,6 @@ local function getCMakeListsFiles()
if (g_ShouldIgnoreCMake[a_FileName]) then
return
end
a_FileName = a_FileName:gsub("../Bindings/", "") -- Normalize the path
table.insert(res, a_FileName)
res[a_FileName] = true
end

View File

@ -1,5 +1,6 @@
target_sources(
${CMAKE_PROJECT_NAME} PRIVATE
SET (SRCS
BeaconEntity.cpp
BedEntity.cpp
BlockEntity.cpp
@ -19,9 +20,7 @@ SET (SRCS
MobSpawnerEntity.cpp
NoteEntity.cpp
SignEntity.cpp
)
SET (HDRS
BeaconEntity.h
BedEntity.h
BlockEntity.h
@ -42,8 +41,3 @@ SET (HDRS
NoteEntity.h
SignEntity.h
)
if(NOT MSVC)
add_library(BlockEntities ${SRCS} ${HDRS})
target_link_libraries(BlockEntities fmt::fmt SQLiteCpp)
endif()

View File

@ -1,16 +1,12 @@
project (Cuberite)
target_sources(
${CMAKE_PROJECT_NAME} PRIVATE
include_directories ("${PROJECT_SOURCE_DIR}/../")
SET (SRCS
BlockBed.cpp
BlockDoor.cpp
BlockHandler.cpp
BlockPiston.cpp
ChunkInterface.cpp
)
SET (HDRS
BlockAnvil.h
BlockBed.h
BlockBigFlower.h
@ -105,8 +101,3 @@ SET (HDRS
Mixins.h
WorldInterface.h
)
if(NOT MSVC)
add_library(Blocks ${SRCS} ${HDRS})
target_link_libraries(Blocks fmt::fmt SQLiteCpp)
endif()

View File

@ -1,18 +1,8 @@
project (Cuberite)
target_sources(
${CMAKE_PROJECT_NAME} PRIVATE
Resources/Cuberite.rc
include_directories (SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/../lib/")
include_directories (SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/../lib/jsoncpp/include")
include_directories (SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/../lib/mbedtls/include")
include_directories (SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/../lib/libevent/include")
set(FOLDERS
OSSupport HTTP Items Blocks Protocol Generating mbedTLS++ Bindings
WorldStorage Mobs Entities Simulator Simulator/IncrementalRedstoneSimulator
BlockEntities UI Noise
)
SET (SRCS
BiomeDef.cpp
BlockArea.cpp
BlockInfo.cpp
@ -80,9 +70,7 @@ SET (SRCS
WebAdmin.cpp
World.cpp
main.cpp
)
SET (HDRS
AllocationPool.h
BiomeDef.h
BlockArea.h
@ -169,156 +157,33 @@ SET (HDRS
XMLParser.h
)
file(WRITE "${CMAKE_BINARY_DIR}/include/Globals.h"
"/* This file allows Globals.h to be included with an absolute path */\n#include \"${PROJECT_SOURCE_DIR}/Globals.h\"\n")
set(FOLDERS
OSSupport HTTP Items Blocks Protocol Generating mbedTLS++ Bindings
WorldStorage Mobs Entities Simulator Simulator/IncrementalRedstoneSimulator
BlockEntities UI Noise
)
include_directories("${CMAKE_BINARY_DIR}/include")
include_directories (SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/../lib/TCLAP/include")
# Add all child source directories:
foreach(folder ${FOLDERS})
add_subdirectory(${folder})
endforeach(folder)
file(WRITE "${CMAKE_BINARY_DIR}/include/Globals.h"
"/* This file allows Globals.h to be included with an absolute path */\n#include \"${PROJECT_SOURCE_DIR}/src/Globals.h\"\n")
configure_file("BuildInfo.h.cmake" "${CMAKE_BINARY_DIR}/include/BuildInfo.h")
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE "${CMAKE_BINARY_DIR}/include/")
if (NOT MSVC)
# Bindings need to reference other folders, so they are done here instead
# lib dependencies are not included
include_directories ("${CMAKE_CURRENT_SOURCE_DIR}/../lib/mbedtls/include")
# Generate AllFiles.lst for CheckBasicStyle.lua
get_target_property(ALL_FILES ${CMAKE_PROJECT_NAME} SOURCES)
foreach(FILE ${ALL_FILES})
# target_sources converts to absolute but CheckBasicStyle expects relative
file(RELATIVE_PATH RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" ${FILE})
foreach(folder ${FOLDERS})
add_subdirectory(${folder})
endforeach(folder)
get_directory_property(BINDING_DEPENDENCIES DIRECTORY "Bindings" DEFINITION BINDING_DEPENDENCIES)
#clear file
file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/Bindings/BindingDependencies.txt)
foreach(dependency ${BINDING_DEPENDENCIES})
#write each dependency on a seperate line
file(APPEND ${CMAKE_CURRENT_SOURCE_DIR}/Bindings/BindingDependencies.txt "${dependency}\n")
endforeach()
set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "Bindings.cpp Bindings.h")
list(APPEND SOURCE "${SRCS}")
list(APPEND SOURCE "${HDRS}")
# If building a windows version, but not using MSVC, add the resources directly to the makefile:
if (WIN32)
list(APPEND SOURCE "Resources/Cuberite.rc")
endif()
else ()
# MSVC-specific handling: Put all files into one project, separate by the folders:
source_group(Bindings FILES "Bindings/Bindings.cpp" "Bindings/Bindings.h")
# Add all subfolders as solution-folders:
function(includefolder PATH)
FILE(GLOB FOLDER_FILES
"${PATH}/*.cpp"
"${PATH}/*.h"
"${PATH}/*.rc"
"${PATH}/*.pkg"
)
string(REPLACE "/" "\\" PROJECT_PATH ${PATH})
source_group("${PROJECT_PATH}" FILES ${FOLDER_FILES})
endfunction(includefolder)
foreach(folder ${FOLDERS})
add_subdirectory(${folder})
includefolder(${folder})
# Get all source files in this folder:
get_directory_property(FOLDER_SRCS DIRECTORY ${folder} DEFINITION SRCS)
foreach (src ${FOLDER_SRCS})
list(APPEND SOURCE "${folder}/${src}")
endforeach(src)
# Get all headers in this folder:
get_directory_property(FOLDER_HDRS DIRECTORY ${folder} DEFINITION HDRS)
foreach (hdr ${FOLDER_HDRS})
list(APPEND SOURCE "${folder}/${hdr}")
endforeach(hdr)
# Include this folder's CMakeLists.txt in the project:
list(APPEND SOURCE "${folder}/CMakeLists.txt")
source_group("${folder}" FILES "${folder}/CMakeLists.txt")
endforeach(folder)
list(APPEND SOURCE "${SRCS}")
list(APPEND SOURCE "${HDRS}")
list(APPEND SOURCE "Bindings/AllToLua.pkg")
includefolder("Resources")
source_group("" FILES ${SOURCE})
# Precompiled headers (1st part)
SET_SOURCE_FILES_PROPERTIES(
Globals.cpp PROPERTIES COMPILE_FLAGS "/Yc\"Globals.h\""
)
# CMake cannot "remove" the precompiled header flags, so we use a dummy precompiled header compatible with just this one file:
SET_SOURCE_FILES_PROPERTIES(
Bindings/Bindings.cpp PROPERTIES COMPILE_FLAGS "/Yc\"string.h\" /Fp\"$(IntDir)/Bindings.pch\""
)
list(APPEND SOURCE "Resources/Cuberite.rc")
# Make MSVC generate the PDB files even for the release build:
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /Zi")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /DEBUG")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG")
set(CMAKE_MODULE_LINKER_FLAGS_RELEASE "${CMAKE_MODULE_LINKER_FLAGS_RELEASE} /DEBUG")
endif()
# Generate a list of all source files:
set(ALLFILES "${SRCS}" "${HDRS}")
foreach(folder ${FOLDERS})
get_directory_property(FOLDER_SRCS DIRECTORY ${folder} DEFINITION SRCS)
foreach (src ${FOLDER_SRCS})
list(APPEND ALLFILES "${folder}/${src}")
endforeach(src)
get_directory_property(FOLDER_HDRS DIRECTORY ${folder} DEFINITION HDRS)
foreach (hdr ${FOLDER_HDRS})
list(APPEND ALLFILES "${folder}/${hdr}")
endforeach(hdr)
endforeach(folder)
foreach(arg ${ALLFILES})
set(ALLFILESLINES "${ALLFILESLINES}${arg}\n")
# Convert CMake list into newline-delimited string
set(ALL_FILES_AS_LINES "${ALL_FILES_AS_LINES}${RELATIVE}\n")
endforeach()
FILE(WRITE "AllFiles.lst" "${ALLFILESLINES}")
if (MSVC)
get_directory_property(BINDING_OUTPUTS DIRECTORY "Bindings" DEFINITION BINDING_OUTPUTS)
get_directory_property(BINDING_DEPENDENCIES DIRECTORY "Bindings" DEFINITION BINDING_DEPENDENCIES)
# The paths in BINDING_DEPENDENCIES are