From 9e8598fb1ca359143600d6bb2e8b317126a86bcc Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 16 May 2020 20:59:10 +0100 Subject: Upgrade to C++17 [CMake] (#4717) * Make our CMake slightly less insane --- .travis.yml | 26 ++- CMake/Fixups.cmake | 14 ++ CMake/GenerateBindings.cmake | 112 ++++++++++ CMake/GroupSources.cmake | 42 ++++ CMakeLists.txt | 248 +++++++++------------ SetFlags.cmake | 8 + Tools/ProtoProxy/CMakeLists.txt | 1 - Tools/QtBiomeVisualiser/Globals.h | 5 - clang-tidy.sh | 5 +- lib/SQLiteCpp | 2 +- lib/TCLAP | 2 +- lib/expat | 2 +- lib/jsoncpp | 2 +- lib/lua | 2 +- lib/luaexpat | 2 +- lib/sqlite | 2 +- lib/tolua++ | 2 +- lib/zlib | 2 +- src/Bindings/CMakeLists.txt | 135 +---------- src/Bindings/CheckBindingsDependencies.lua | 19 +- src/BlockEntities/CMakeLists.txt | 10 +- src/Blocks/CMakeLists.txt | 13 +- src/CMakeLists.txt | 220 ++---------------- src/Entities/CMakeLists.txt | 14 +- src/Generating/CMakeLists.txt | 10 +- src/Generating/FinishGen.h | 2 + src/Globals.h | 6 + src/HTTP/CMakeLists.txt | 10 +- src/Items/CMakeLists.txt | 10 +- src/LinearUpscale.h | 7 + src/Mobs/CMakeLists.txt | 14 +- src/Noise/CMakeLists.txt | 10 +- src/OSSupport/CMakeLists.txt | 13 +- src/Protocol/CMakeLists.txt | 11 +- src/Simulator/CMakeLists.txt | 10 +- .../IncrementalRedstoneSimulator/CMakeLists.txt | 11 +- src/UI/CMakeLists.txt | 14 +- src/WorldStorage/CMakeLists.txt | 10 +- src/mbedTLS++/CMakeLists.txt | 10 +- tests/BlockTypeRegistry/CMakeLists.txt | 12 +- tests/BoundingBox/CMakeLists.txt | 6 - tests/ByteBuffer/CMakeLists.txt | 6 - tests/CMakeLists.txt | 4 +- tests/ChunkData/CMakeLists.txt | 7 +- tests/CompositeChat/CMakeLists.txt | 6 - tests/FastRandom/CMakeLists.txt | 6 - tests/Generating/CMakeLists.txt | 9 +- tests/HTTP/CMakeLists.txt | 7 +- tests/LoadablePieces/CMakeLists.txt | 8 +- tests/LuaThreadStress/CMakeLists.txt | 8 +- tests/Network/CMakeLists.txt | 7 +- tests/OSSupport/CMakeLists.txt | 45 ++-- tests/SchematicFileSerializer/CMakeLists.txt | 7 +- tests/UUID/CMakeLists.txt | 3 - travisbuild.sh | 22 +- 55 files changed, 448 insertions(+), 753 deletions(-) create mode 100644 CMake/Fixups.cmake create mode 100644 CMake/GenerateBindings.cmake create mode 100644 CMake/GroupSources.cmake diff --git a/.travis.yml b/.travis.yml index 8b517c5f8..a2a518751 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/CMake/Fixups.cmake b/CMake/Fixups.cmake new file mode 100644 index 000000000..5abff5abd --- /dev/null +++ b/CMake/Fixups.cmake @@ -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() diff --git a/CMake/GenerateBindings.cmake b/CMake/GenerateBindings.cmake new file mode 100644 index 000000000..153f1a58a --- /dev/null +++ b/CMake/GenerateBindings.cmake @@ -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 +) diff --git a/CMake/GroupSources.cmake b/CMake/GroupSources.cmake new file mode 100644 index 000000000..0f1762110 --- /dev/null +++ b/CMake/GroupSources.cmake @@ -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}) diff --git a/CMakeLists.txt b/CMakeLists.txt index f10e961e0..5c16c0e40 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,19 +13,18 @@ -cmake_minimum_required (VERSION 3.12.4) - -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() +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 +) + +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$<$: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 +# 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) +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") -# 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) -add_subdirectory(lib/fmt) +# 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 proper includes for LibEvent's event-config.h header: -include_directories(SYSTEM ${LIBEVENT_INCLUDE_DIRS}) +# 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() -# Prettify jsoncpp_lib name in VS solution explorer +# 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") -# 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/) + 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) +# 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) -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) + # 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() -set_exe_flags() - -add_subdirectory(src) - +# 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") diff --git a/SetFlags.cmake b/SetFlags.cmake index b8dd26bfd..1a154dd24 100644 --- a/SetFlags.cmake +++ b/SetFlags.cmake @@ -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) diff --git a/Tools/ProtoProxy/CMakeLists.txt b/Tools/ProtoProxy/CMakeLists.txt index b5b1365a2..e5c261bc8 100644 --- a/Tools/ProtoProxy/CMakeLists.txt +++ b/Tools/ProtoProxy/CMakeLists.txt @@ -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() diff --git a/Tools/QtBiomeVisualiser/Globals.h b/Tools/QtBiomeVisualiser/Globals.h index d908c0b2c..0b119fcb1 100644 --- a/Tools/QtBiomeVisualiser/Globals.h +++ b/Tools/QtBiomeVisualiser/Globals.h @@ -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 , included earlier #define SharedPtr std::shared_ptr diff --git a/clang-tidy.sh b/clang-tidy.sh index 86a71521b..fb99bc189 100755 --- a/clang-tidy.sh +++ b/clang-tidy.sh @@ -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) diff --git a/lib/SQLiteCpp b/lib/SQLiteCpp index 829d549af..6aec7cf64 160000 --- a/lib/SQLiteCpp +++ b/lib/SQLiteCpp @@ -1 +1 @@ -Subproject commit 829d549af3a11e24fcb0b99090837dac9a9aae4f +Subproject commit 6aec7cf646e9d0e49b0000c3d5b74de9c3222ef2 diff --git a/lib/TCLAP b/lib/TCLAP index ec3ddcfe4..12cee3878 160000 --- a/lib/TCLAP +++ b/lib/TCLAP @@ -1 +1 @@ -Subproject commit ec3ddcfe41b0544a4551a57439b6b3682fe31479 +Subproject commit 12cee38782897cfe60a1611615c200c45cd99eaf diff --git a/lib/expat b/lib/expat index 75f059124..e87c79037 160000 --- a/lib/expat +++ b/lib/expat @@ -1 +1 @@ -Subproject commit 75f059124b8e9d3d442d1907344187f15e34e6b6 +Subproject commit e87c7903718ed7e05cbb614bbc385553987a2d33 diff --git a/lib/jsoncpp b/lib/jsoncpp index d2e6a971f..b8cb8889a 160000 --- a/lib/jsoncpp +++ b/lib/jsoncpp @@ -1 +1 @@ -Subproject commit d2e6a971f4544c55b8e3b25cf96db266971b778f +Subproject commit b8cb8889aab726a35c49472228256f7bb1d44388 diff --git a/lib/lua b/lib/lua index 6d57f1c3c..e5942d9d8 160000 --- a/lib/lua +++ b/lib/lua @@ -1 +1 @@ -Subproject commit 6d57f1c3c4face973f0405b2a3c0fb8471a79d92 +Subproject commit e5942d9d88221dc02b824f5bda0db9876fa92bad diff --git a/lib/luaexpat b/lib/luaexpat index bf6adc1f9..368e2927f 160000 --- a/lib/luaexpat +++ b/lib/luaexpat @@ -1 +1 @@ -Subproject commit bf6adc1f92708600707c0a8603b45a9de9a8fe14 +Subproject commit 368e2927fcd227bf0af91b3e4b92e740196425cd diff --git a/lib/sqlite b/lib/sqlite index 9a17fd731..01cbf6d5a 160000 --- a/lib/sqlite +++ b/lib/sqlite @@ -1 +1 @@ -Subproject commit 9a17fd73198c645c924996c0aee7836f51bcf7bb +Subproject commit 01cbf6d5a5ba91dd78d17604865dd3aebe1b5093 diff --git a/lib/tolua++ b/lib/tolua++ index 4a814cf17..23cd44840 160000 --- a/lib/tolua++ +++ b/lib/tolua++ @@ -1 +1 @@ -Subproject commit 4a814cf1759c8a1d0917344397a84c917c74de97 +Subproject commit 23cd44840dc9405f4f7df34a621a351062359b8d diff --git a/lib/zlib b/lib/zlib index 2ea591736..a9c7b3064 160000 --- a/lib/zlib +++ b/lib/zlib @@ -1 +1 @@ -Subproject commit 2ea59173610490eb48e29de44bd6e04324d84995 +Subproject commit a9c7b30641ed8b86590141a1b4025263bce4c881 diff --git a/src/Bindings/CMakeLists.txt b/src/Bindings/CMakeLists.txt index f5896f02d..3e7101cbf 100644 --- a/src/Bindings/CMakeLists.txt +++ b/src/Bindings/CMakeLists.txt @@ -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() diff --git a/src/Bindings/CheckBindingsDependencies.lua b/src/Bindings/CheckBindingsDependencies.lua index c0565ead8..50e915311 100644 --- a/src/Bindings/CheckBindingsDependencies.lua +++ b/src/Bindings/CheckBindingsDependencies.lua @@ -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 diff --git a/src/BlockEntities/CMakeLists.txt b/src/BlockEntities/CMakeLists.txt index 6e88ef128..b0e456da3 100644 --- a/src/BlockEntities/CMakeLists.txt +++ b/src/BlockEntities/CMakeLists.txt @@ -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() diff --git a/src/Blocks/CMakeLists.txt b/src/Blocks/CMakeLists.txt index 9d9f07b52..1026848df 100644 --- a/src/Blocks/CMakeLists.txt +++ b/src/Blocks/CMakeLists.txt @@ -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() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e10e8e8ca..c452ca7e2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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") - -include_directories("${CMAKE_BINARY_DIR}/include") -include_directories (SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/../lib/TCLAP/include") - -configure_file("BuildInfo.h.cmake" "${CMAKE_BINARY_DIR}/include/BuildInfo.h") - -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") - - 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() - +set(FOLDERS + OSSupport HTTP Items Blocks Protocol Generating mbedTLS++ Bindings + WorldStorage Mobs Entities Simulator Simulator/IncrementalRedstoneSimulator + BlockEntities UI Noise +) -# Generate a list of all source files: -set(ALLFILES "${SRCS}" "${HDRS}") +# Add all child source directories: 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) + add_subdirectory(${folder}) endforeach(folder) -foreach(arg ${ALLFILES}) - set(ALLFILESLINES "${ALLFILESLINES}${arg}\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 relative to the Bindings folder, convert them relative to this folder: - foreach (dep ${BINDING_DEPENDENCIES}) - list (APPEND BINDINGS_DEPENDENCIES "Bindings/${dep}") - endforeach(dep) - - if (USE_SYSTEM_LUA) - ADD_CUSTOM_COMMAND( - OUTPUT ${BINDING_OUTPUTS} - COMMAND lua BindingsProcessor.lua - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Bindings/ - DEPENDS ${BINDINGS_DEPENDENCIES} - ) - else() - ADD_CUSTOM_COMMAND( - OUTPUT ${BINDING_OUTPUTS} - - # Regenerate bindings: - COMMAND luaexe BindingsProcessor.lua - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Bindings/ - DEPENDS ${BINDINGS_DEPENDENCIES} luaexe - ) - endif() -endif() - +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/") +# 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}) -add_executable(${CMAKE_PROJECT_NAME} ${SOURCE}) + # Convert CMake list into newline-delimited string + set(ALL_FILES_AS_LINES "${ALL_FILES_AS_LINES}${RELATIVE}\n") +endforeach() +file(WRITE AllFiles.lst "${ALL_FILES_AS_LINES}") # Output the executable into the $/Server folder, so that it has access to external resources: SET_TARGET_PROPERTIES(${CMAKE_PROJECT_NAME} PROPERTIES @@ -402,45 +267,6 @@ make_symlink("${CMAKE_CURRENT_SOURCE_DIR}/../CONTRIBUTORS" make_symlink("${CMAKE_CURRENT_SOURCE_DIR}/../LICENSE" "${CMAKE_BINARY_DIR}/Server/LICENSE") make_symlink("${CMAKE_CURRENT_SOURCE_DIR}/../Server/Install/ThirdPartyLicenses" "${CMAKE_BINARY_DIR}/Server/ThirdPartyLicenses") - - - -# Precompiled headers (2nd part) -if (MSVC) - SET_TARGET_PROPERTIES( - ${CMAKE_PROJECT_NAME} PROPERTIES COMPILE_FLAGS "/Yu\"Globals.h\"" - OBJECT_DEPENDS "$(IntDir)/$(TargetName.pch)" - ) -endif () - - -if (NOT MSVC) - target_link_libraries(${CMAKE_PROJECT_NAME} - OSSupport HTTPServer Bindings Items Blocks Noise - Protocol Generating WorldStorage - Mobs Entities Simulator IncrementalRedstoneSimulator - BlockEntities UI mbedTLS++ - ) -endif () - -if (WIN32) - target_link_libraries(${CMAKE_PROJECT_NAME} expat tolualib ws2_32.lib Psapi.lib) -endif() - -if (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD") - add_flags_lnk(-L/usr/local/lib) - add_flags_lnk(-L/usr/ports/devel) -endif() - -target_link_libraries(${CMAKE_PROJECT_NAME} luaexpat jsoncpp_lib mbedtls zlib lsqlite lua SQLiteCpp event_core event_extra fmt::fmt) - # Create a folder for Bindings' documentation: FILE(MAKE_DIRECTORY "Bindings/docs") make_symlink("${CMAKE_CURRENT_SOURCE_DIR}/Bindings/docs" "${CMAKE_BINARY_DIR}/Server/BindingsDocs") - - -# For MSVC, set the startup project to Cuberite, and the debugger dir: -if (MSVC) - set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${CMAKE_PROJECT_NAME}) - set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/Server") -endif() diff --git a/src/Entities/CMakeLists.txt b/src/Entities/CMakeLists.txt index 1a6e78af5..87c9ff790 100644 --- a/src/Entities/CMakeLists.txt +++ b/src/Entities/CMakeLists.txt @@ -1,5 +1,6 @@ +target_sources( + ${CMAKE_PROJECT_NAME} PRIVATE -SET (SRCS ArrowEntity.cpp Boat.cpp EnderCrystal.cpp @@ -26,9 +27,8 @@ SET (SRCS ThrownEggEntity.cpp ThrownEnderPearlEntity.cpp ThrownSnowballEntity.cpp - WitherSkullEntity.cpp) + WitherSkullEntity.cpp -SET (HDRS ArrowEntity.h Boat.h EnderCrystal.h @@ -55,9 +55,5 @@ SET (HDRS ThrownEggEntity.h ThrownEnderPearlEntity.h ThrownSnowballEntity.h - WitherSkullEntity.h) - -if(NOT MSVC) - add_library(Entities ${SRCS} ${HDRS}) - target_link_libraries(Entities fmt::fmt WorldStorage SQLiteCpp) -endif() + WitherSkullEntity.h +) diff --git a/src/Generating/CMakeLists.txt b/src/Generating/CMakeLists.txt index 713e5b8c9..d6f0ce2fb 100644 --- a/src/Generating/CMakeLists.txt +++ b/src/Generating/CMakeLists.txt @@ -1,5 +1,6 @@ +target_sources( + ${CMAKE_PROJECT_NAME} PRIVATE -SET (SRCS BioGen.cpp Caves.cpp ChunkDesc.cpp @@ -29,9 +30,7 @@ SET (SRCS VerticalLimit.cpp VerticalStrategy.cpp VillageGen.cpp -) -SET (HDRS BioGen.h Caves.h ChunkDesc.h @@ -66,8 +65,3 @@ SET (HDRS VerticalStrategy.h VillageGen.h ) - -if(NOT MSVC) - add_library(Generating ${SRCS} ${HDRS}) - target_link_libraries(Generating fmt::fmt OSSupport Blocks Bindings) -endif() diff --git a/src/Generating/FinishGen.h b/src/Generating/FinishGen.h index 22292d924..c12bc2392 100644 --- a/src/Generating/FinishGen.h +++ b/src/Generating/FinishGen.h @@ -15,6 +15,8 @@ +#pragma once + #include "ComposableGenerator.h" #include "../Noise/Noise.h" #include "../ProbabDistrib.h" diff --git a/src/Globals.h b/src/Globals.h index 778bfe2b9..c0686c5b5 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -8,6 +8,12 @@ +#pragma once + + + + + // Compiler-dependent stuff: #if defined(_MSC_VER) // Disable some warnings that we don't care about: diff --git a/src/HTTP/CMakeLists.txt b/src/HTTP/CMakeLists.txt index 1bd311dc4..46165af3f 100644 --- a/src/HTTP/CMakeLists.txt +++ b/src/HTTP/CMakeLists.txt @@ -1,5 +1,6 @@ +target_sources( + ${CMAKE_PROJECT_NAME} PRIVATE -SET (SRCS EnvelopeParser.cpp HTTPFormParser.cpp HTTPMessage.cpp @@ -12,9 +13,7 @@ SET (SRCS TransferEncodingParser.cpp UrlClient.cpp UrlParser.cpp -) -SET (HDRS EnvelopeParser.h HTTPFormParser.h HTTPMessage.h @@ -28,8 +27,3 @@ SET (HDRS UrlClient.h UrlParser.h ) - -if(NOT MSVC) - add_library(HTTPServer ${SRCS} ${HDRS}) - target_link_libraries(HTTPServer fmt::fmt) -endif() diff --git a/src/Items/CMakeLists.txt b/src/Items/CMakeLists.txt index 9deec08c7..e5f65fb3b 100644 --- a/src/Items/CMakeLists.txt +++ b/src/Items/CMakeLists.txt @@ -1,9 +1,8 @@ +target_sources( + ${CMAKE_PROJECT_NAME} PRIVATE -SET (SRCS ItemHandler.cpp -) -SET (HDRS ItemArmor.h ItemAxe.h ItemBed.h @@ -62,8 +61,3 @@ SET (HDRS ItemSword.h ItemThrowable.h ) - -if(NOT MSVC) - add_library(Items ${SRCS} ${HDRS}) - target_link_libraries(Items fmt::fmt SQLiteCpp) -endif() diff --git a/src/LinearUpscale.h b/src/LinearUpscale.h index d0c2bb41a..349a3a55d 100644 --- a/src/LinearUpscale.h +++ b/src/LinearUpscale.h @@ -26,6 +26,13 @@ Regular upscaling takes two arrays and "moves" the input from src to dst; src is + +#pragma once + + + + + /** Linearly interpolates values in the array between the equidistant anchor points (upscales). Works in-place (input is already present at the correct output coords) diff --git a/src/Mobs/CMakeLists.txt b/src/Mobs/CMakeLists.txt index aada8f3a8..6508e1814 100644 --- a/src/Mobs/CMakeLists.txt +++ b/src/Mobs/CMakeLists.txt @@ -1,5 +1,6 @@ +target_sources( + ${CMAKE_PROJECT_NAME} PRIVATE -SET (SRCS AggressiveMonster.cpp Bat.cpp Blaze.cpp @@ -37,9 +38,8 @@ SET (SRCS Wolf.cpp Zombie.cpp ZombiePigman.cpp - ZombieVillager.cpp) + ZombieVillager.cpp -SET (HDRS AggressiveMonster.h Bat.h Blaze.h @@ -80,9 +80,5 @@ SET (HDRS Wolf.h Zombie.h ZombiePigman.h - ZombieVillager.h) - -if(NOT MSVC) - add_library(Mobs ${SRCS} ${HDRS}) - target_link_libraries(Mobs fmt::fmt SQLiteCpp) -endif() + ZombieVillager.h +) diff --git a/src/Noise/CMakeLists.txt b/src/Noise/CMakeLists.txt index b099c1766..85b3e2b8e 100644 --- a/src/Noise/CMakeLists.txt +++ b/src/Noise/CMakeLists.txt @@ -1,16 +1,10 @@ +target_sources( + ${CMAKE_PROJECT_NAME} PRIVATE -SET (SRCS Noise.cpp -) -SET (HDRS InterpolNoise.h Noise.h OctavedNoise.h RidgedNoise.h ) - -if(NOT MSVC) - add_library(Noise ${SRCS} ${HDRS}) - target_link_libraries(Noise fmt::fmt OSSupport) -endif() diff --git a/src/OSSupport/CMakeLists.txt b/src/OSSupport/CMakeLists.txt index 62ad9c475..1b853c202 100644 --- a/src/OSSupport/CMakeLists.txt +++ b/src/OSSupport/CMakeLists.txt @@ -1,5 +1,6 @@ +target_sources( + ${CMAKE_PROJECT_NAME} PRIVATE -SET (SRCS CriticalSection.cpp Errors.cpp Event.cpp @@ -16,9 +17,7 @@ SET (SRCS TCPLinkImpl.cpp UDPEndpointImpl.cpp WinStackWalker.cpp -) -SET (HDRS AtomicUniquePtr.h CriticalSection.h Errors.h @@ -40,11 +39,3 @@ SET (HDRS WinStackWalker.h ) -if(NOT MSVC) - add_library(OSSupport ${SRCS} ${HDRS}) - target_link_libraries(OSSupport fmt::fmt) - - if(NOT WIN32) - target_link_libraries(OSSupport event_pthreads_static) - endif() -endif() diff --git a/src/Protocol/CMakeLists.txt b/src/Protocol/CMakeLists.txt index 0f22e531f..e197853cb 100644 --- a/src/Protocol/CMakeLists.txt +++ b/src/Protocol/CMakeLists.txt @@ -1,6 +1,6 @@ -include_directories (SYSTEM "../../lib/jsoncpp/include") +target_sources( + ${CMAKE_PROJECT_NAME} PRIVATE -SET (SRCS Authenticator.cpp ChunkDataSerializer.cpp ForgeHandshake.cpp @@ -14,9 +14,7 @@ SET (SRCS Protocol_1_13.cpp ProtocolPalettes.cpp ProtocolRecognizer.cpp -) -SET (HDRS Authenticator.h ChunkDataSerializer.h ForgeHandshake.h @@ -32,8 +30,3 @@ SET (HDRS ProtocolPalettes.h ProtocolRecognizer.h ) - -if (NOT MSVC) - add_library(Protocol ${SRCS} ${HDRS}) - target_link_libraries(Protocol fmt::fmt SQLiteCpp) -endif() diff --git a/src/Simulator/CMakeLists.txt b/src/Simulator/CMakeLists.txt index a8efc988c..2acaa2031 100644 --- a/src/Simulator/CMakeLists.txt +++ b/src/Simulator/CMakeLists.txt @@ -1,5 +1,6 @@ +target_sources( + ${CMAKE_PROJECT_NAME} PRIVATE -SET (SRCS DelayedFluidSimulator.cpp FireSimulator.cpp FloodyFluidSimulator.cpp @@ -9,9 +10,7 @@ SET (SRCS SimulatorManager.cpp VanillaFluidSimulator.cpp VaporizeFluidSimulator.cpp -) -SET (HDRS DelayedFluidSimulator.h FireSimulator.h FloodyFluidSimulator.h @@ -25,8 +24,3 @@ SET (HDRS VanillaFluidSimulator.h VaporizeFluidSimulator.h ) - -if(NOT MSVC) - add_library(Simulator ${SRCS} ${HDRS}) - target_link_libraries(Simulator fmt::fmt SQLiteCpp) -endif() diff --git a/src/Simulator/IncrementalRedstoneSimulator/CMakeLists.txt b/src/Simulator/IncrementalRedstoneSimulator/CMakeLists.txt index 0c2346322..1857a115a 100644 --- a/src/Simulator/IncrementalRedstoneSimulator/CMakeLists.txt +++ b/src/Simulator/IncrementalRedstoneSimulator/CMakeLists.txt @@ -1,9 +1,8 @@ +target_sources( + ${CMAKE_PROJECT_NAME} PRIVATE -set (SRCS IncrementalRedstoneSimulator.cpp -) -set (HDRS CommandBlockHandler.h DoorHandler.h DropSpenserHandler.h @@ -29,9 +28,3 @@ set (HDRS PoweredRailHandler.h PressurePlateHandler.h ) - -if(NOT MSVC) - add_library(IncrementalRedstoneSimulator ${SRCS} ${HDRS}) - target_link_libraries(IncrementalRedstoneSimulator fmt::fmt) -endif() - diff --git a/src/UI/CMakeLists.txt b/src/UI/CMakeLists.txt index 16c70f6fe..b87a7fe47 100644 --- a/src/UI/CMakeLists.txt +++ b/src/UI/CMakeLists.txt @@ -1,5 +1,6 @@ +target_sources( + ${CMAKE_PROJECT_NAME} PRIVATE -SET (SRCS SlotArea.cpp Window.cpp AnvilWindow.cpp @@ -13,9 +14,8 @@ SET (SRCS FurnaceWindow.cpp HopperWindow.cpp HorseWindow.cpp - InventoryWindow.cpp) + InventoryWindow.cpp -SET (HDRS SlotArea.h Window.h AnvilWindow.h @@ -31,9 +31,5 @@ SET (HDRS HorseWindow.h InventoryWindow.h MinecartWithChestWindow.h - WindowOwner.h) - -if(NOT MSVC) - add_library(UI ${SRCS} ${HDRS}) - target_link_libraries(UI fmt::fmt SQLiteCpp) -endif() + WindowOwner.h +) diff --git a/src/WorldStorage/CMakeLists.txt b/src/WorldStorage/CMakeLists.txt index 341d88e68..68fdd31bc 100644 --- a/src/WorldStorage/CMakeLists.txt +++ b/src/WorldStorage/CMakeLists.txt @@ -1,5 +1,6 @@ +target_sources( + ${CMAKE_PROJECT_NAME} PRIVATE -SET (SRCS EnchantmentSerializer.cpp FastNBT.cpp FireworksSerializer.cpp @@ -10,9 +11,7 @@ SET (SRCS StatSerializer.cpp WSSAnvil.cpp WorldStorage.cpp -) -SET (HDRS EnchantmentSerializer.h FastNBT.h FireworksSerializer.h @@ -24,8 +23,3 @@ SET (HDRS WSSAnvil.h WorldStorage.h ) - -if(NOT MSVC) - add_library(WorldStorage ${SRCS} ${HDRS}) - target_link_libraries(WorldStorage fmt::fmt OSSupport SQLiteCpp) -endif() diff --git a/src/mbedTLS++/CMakeLists.txt b/src/mbedTLS++/CMakeLists.txt index 29c323cc6..42e0fc8b2 100644 --- a/src/mbedTLS++/CMakeLists.txt +++ b/src/mbedTLS++/CMakeLists.txt @@ -1,5 +1,6 @@ +target_sources( + ${CMAKE_PROJECT_NAME} PRIVATE -set(SRCS AesCfb128Decryptor.cpp AesCfb128Encryptor.cpp BlockingSslClientSocket.cpp @@ -13,9 +14,7 @@ set(SRCS SslConfig.cpp SslContext.cpp X509Cert.cpp -) -set(HDRS AesCfb128Decryptor.h AesCfb128Encryptor.h BlockingSslClientSocket.h @@ -31,8 +30,3 @@ set(HDRS Sha1Checksum.h X509Cert.h ) - -if(NOT MSVC) - add_library(mbedTLS++ ${SRCS} ${HDRS}) - target_link_libraries(mbedTLS++ fmt::fmt mbedtls) -endif() diff --git a/tests/BlockTypeRegistry/CMakeLists.txt b/tests/BlockTypeRegistry/CMakeLists.txt index 1b2749722..ef4803747 100644 --- a/tests/BlockTypeRegistry/CMakeLists.txt +++ b/tests/BlockTypeRegistry/CMakeLists.txt @@ -1,14 +1,6 @@ -cmake_minimum_required(VERSION 3.0.2) -enable_testing() - +find_package(Threads REQUIRED) include_directories(${CMAKE_SOURCE_DIR}/src/) -add_definitions(-DTEST_GLOBALS=1) - - - - - # Define individual test executables: # BlockStateTest: Verify that the BlockState class works as intended: @@ -41,7 +33,7 @@ add_executable(BlockTypeRegistryTest ${CMAKE_SOURCE_DIR}/src/StringUtils.cpp ${CMAKE_SOURCE_DIR}/src/OSSupport/CriticalSection.cpp ) -target_link_libraries(BlockTypeRegistryTest fmt::fmt) +target_link_libraries(BlockTypeRegistryTest fmt::fmt Threads::Threads) # PalettedBlockAreaTest: Verify that the PalettedBlockArea class works as intended: add_executable(PalettedBlockAreaTest diff --git a/tests/BoundingBox/CMakeLists.txt b/tests/BoundingBox/CMakeLists.txt index da960ba19..e102017f9 100644 --- a/tests/BoundingBox/CMakeLists.txt +++ b/tests/BoundingBox/CMakeLists.txt @@ -1,11 +1,5 @@ -cmake_minimum_required(VERSION 3.0.2) -enable_testing() -add_definitions(-DTEST_GLOBALS=1) - include_directories(${CMAKE_SOURCE_DIR}/src/) -add_definitions(-DTEST_GLOBALS=1) - set (SHARED_SRCS ${CMAKE_SOURCE_DIR}/src/BoundingBox.cpp ${CMAKE_SOURCE_DIR}/src/OSSupport/StackTrace.cpp diff --git a/tests/ByteBuffer/CMakeLists.txt b/tests/ByteBuffer/CMakeLists.txt index 989fabc23..654e68ec6 100644 --- a/tests/ByteBuffer/CMakeLists.txt +++ b/tests/ByteBuffer/CMakeLists.txt @@ -1,11 +1,5 @@ -cmake_minimum_required(VERSION 3.0.2) -enable_testing() -add_definitions(-DTEST_GLOBALS=1) - include_directories(${CMAKE_SOURCE_DIR}/src/) -add_definitions(-DTEST_GLOBALS=1) - set (SHARED_SRCS ${CMAKE_SOURCE_DIR}/src/ByteBuffer.cpp ${CMAKE_SOURCE_DIR}/src/StringUtils.cpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 74e4323ec..9b605470e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,10 +1,8 @@ -enable_testing() - if (CMAKE_BUILD_TYPE STREQUAL "COVERAGE") setup_target_for_coverage("${PROJECT_NAME}_coverage" "ctest" coverage) endif() -add_definitions(-DTEST_GLOBALS=1) +add_compile_definitions(TEST_GLOBALS) add_subdirectory(BlockTypeRegistry) add_subdirectory(BoundingBox) diff --git a/tests/ChunkData/CMakeLists.txt b/tests/ChunkData/CMakeLists.txt index 5bd617f6c..ff7dca0da 100644 --- a/tests/ChunkData/CMakeLists.txt +++ b/tests/ChunkData/CMakeLists.txt @@ -1,10 +1,5 @@ -cmake_minimum_required(VERSION 3.0.2) -enable_testing() - include_directories(${CMAKE_SOURCE_DIR}/src/) - -add_definitions(-DTEST_GLOBALS=1) add_library(ChunkBuffer ${CMAKE_SOURCE_DIR}/src/ChunkData.cpp ${CMAKE_SOURCE_DIR}/src/StringUtils.cpp) target_link_libraries(ChunkBuffer PUBLIC fmt::fmt) @@ -43,5 +38,5 @@ set_target_properties( ) set_target_properties( ChunkBuffer - PROPERTIES FOLDER Lib + PROPERTIES FOLDER Tests/Libraries ) diff --git a/tests/CompositeChat/CMakeLists.txt b/tests/CompositeChat/CMakeLists.txt index 626a146f8..78847c443 100644 --- a/tests/CompositeChat/CMakeLists.txt +++ b/tests/CompositeChat/CMakeLists.txt @@ -1,13 +1,7 @@ -cmake_minimum_required(VERSION 3.0.2) -enable_testing() -add_definitions(-DTEST_GLOBALS=1) - include_directories(${CMAKE_CURRENT_SOURCE_DIR}) include_directories(${CMAKE_SOURCE_DIR}/src/) include_directories(${CMAKE_SOURCE_DIR}/lib/jsoncpp/include) -add_definitions(-DTEST_GLOBALS=1) - set (SHARED_SRCS ${CMAKE_SOURCE_DIR}/src/CompositeChat.cpp ${CMAKE_SOURCE_DIR}/src/JsonUtils.cpp diff --git a/tests/FastRandom/CMakeLists.txt b/tests/FastRandom/CMakeLists.txt index 3030b78e7..e780a2180 100644 --- a/tests/FastRandom/CMakeLists.txt +++ b/tests/FastRandom/CMakeLists.txt @@ -1,11 +1,5 @@ -cmake_minimum_required(VERSION 3.0.2) -enable_testing() -add_definitions(-DTEST_GLOBALS=1) - include_directories(${CMAKE_SOURCE_DIR}/src/) -add_definitions(-DTEST_GLOBALS=1) - set (SHARED_SRCS ${CMAKE_SOURCE_DIR}/src/FastRandom.cpp ${CMAKE_SOURCE_DIR}/src/StringUtils.cpp diff --git a/tests/Generating/CMakeLists.txt b/tests/Generating/CMakeLists.txt index b7ce70e13..241e2efb9 100644 --- a/tests/Generating/CMakeLists.txt +++ b/tests/Generating/CMakeLists.txt @@ -1,13 +1,8 @@ -cmake_minimum_required(VERSION 3.0.2) -enable_testing() - include_directories(${CMAKE_SOURCE_DIR}/src/) include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/lib/) include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/lib/mbedtls/include) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) -add_definitions(-DTEST_GLOBALS=1) - set (SHARED_SRCS ${CMAKE_SOURCE_DIR}/src/BiomeDef.cpp ${CMAKE_SOURCE_DIR}/src/BlockArea.cpp @@ -148,8 +143,8 @@ set (STUBS if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - add_flags_cxx("-Wno-error=global-constructors") - add_flags_cxx("-Wno-error=switch-enum") + add_compile_options("-Wno-error=global-constructors") + add_compile_options("-Wno-error=switch-enum") endif() diff --git a/tests/HTTP/CMakeLists.txt b/tests/HTTP/CMakeLists.txt index 4ca163864..a32355d95 100644 --- a/tests/HTTP/CMakeLists.txt +++ b/tests/HTTP/CMakeLists.txt @@ -1,12 +1,7 @@ -cmake_minimum_required(VERSION 3.0.2) -enable_testing() - include_directories(${CMAKE_SOURCE_DIR}/src/) include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/lib/libevent/include) include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/lib/mbedtls/include) -add_definitions(-DTEST_GLOBALS=1) - # Create a single HTTP library that contains all the HTTP code: set (HTTP_SRCS ${CMAKE_SOURCE_DIR}/src/HTTP/EnvelopeParser.cpp @@ -104,5 +99,5 @@ set_target_properties( ) set_target_properties( HTTP - PROPERTIES FOLDER Lib + PROPERTIES FOLDER Tests/Libraries ) diff --git a/tests/LoadablePieces/CMakeLists.txt b/tests/LoadablePieces/CMakeLists.txt index 4c8f698bf..e3aa369c2 100644 --- a/tests/LoadablePieces/CMakeLists.txt +++ b/tests/LoadablePieces/CMakeLists.txt @@ -1,11 +1,7 @@ -enable_testing() - include_directories(${CMAKE_SOURCE_DIR}/src/) include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/lib/) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) -add_definitions(-DTEST_GLOBALS=1) - set (SHARED_SRCS ${CMAKE_SOURCE_DIR}/src/BiomeDef.cpp ${CMAKE_SOURCE_DIR}/src/BlockArea.cpp @@ -75,8 +71,8 @@ set (SRCS if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - add_flags_cxx("-Wno-error=global-constructors") - add_flags_cxx("-Wno-error=switch-enum") + add_compile_options("-Wno-error=global-constructors") + add_compile_options("-Wno-error=switch-enum") endif() diff --git a/tests/LuaThreadStress/CMakeLists.txt b/tests/LuaThreadStress/CMakeLists.txt index 2f005a342..34e6836ec 100644 --- a/tests/LuaThreadStress/CMakeLists.txt +++ b/tests/LuaThreadStress/CMakeLists.txt @@ -1,12 +1,8 @@ -cmake_minimum_required(VERSION 3.0.2) -enable_testing() - +find_package(Threads REQUIRED) include_directories(${CMAKE_SOURCE_DIR}/src/) include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/lib/) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) -add_definitions(-DTEST_GLOBALS=1) - set (SHARED_SRCS ${CMAKE_SOURCE_DIR}/src/BiomeDef.cpp ${CMAKE_SOURCE_DIR}/src/BlockArea.cpp @@ -82,7 +78,7 @@ source_group("Shared" FILES ${SHARED_SRCS} ${SHARED_HDRS}) source_group("Sources" FILES ${SRCS}) source_group("Lua files" FILES Test.lua) add_executable(LuaThreadStress ${SRCS} ${SHARED_SRCS} ${SHARED_HDRS} Test.lua) -target_link_libraries(LuaThreadStress tolualib zlib fmt::fmt) +target_link_libraries(LuaThreadStress tolualib zlib fmt::fmt Threads::Threads) add_test(NAME LuaThreadStress-test WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMAND LuaThreadStress) diff --git a/tests/Network/CMakeLists.txt b/tests/Network/CMakeLists.txt index 0cc75f735..0fe639ba4 100644 --- a/tests/Network/CMakeLists.txt +++ b/tests/Network/CMakeLists.txt @@ -1,12 +1,7 @@ -cmake_minimum_required(VERSION 3.0.2) -enable_testing() - include_directories(${CMAKE_SOURCE_DIR}/src/) include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/lib/libevent/include) include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/lib/mbedtls/include) -add_definitions(-DTEST_GLOBALS=1) - # Create a single Network library that contains all the networking code: set (Network_SRCS ${CMAKE_SOURCE_DIR}/src/OSSupport/CriticalSection.cpp @@ -103,7 +98,7 @@ set_target_properties( ) set_target_properties( Network - PROPERTIES FOLDER Lib + PROPERTIES FOLDER Tests/Libraries ) diff --git a/tests/OSSupport/CMakeLists.txt b/tests/OSSupport/CMakeLists.txt index 60c68c472..9d481ce09 100644 --- a/tests/OSSupport/CMakeLists.txt +++ b/tests/OSSupport/CMakeLists.txt @@ -1,36 +1,29 @@ -cmake_minimum_required(VERSION 3.0.2) -enable_testing() - +find_package(Threads REQUIRED) include_directories(${CMAKE_SOURCE_DIR}/src/) -add_definitions(-DTEST_GLOBALS=1) - # Create a single OSSupport library that contains all the OSSupport code used in the tests: -# Only needed for Windows; Linux already defines the OSSupport lib -if (WIN32) - set (OSSupport_SRCS - ${CMAKE_SOURCE_DIR}/src/OSSupport/CriticalSection.cpp - ${CMAKE_SOURCE_DIR}/src/OSSupport/Event.cpp - ${CMAKE_SOURCE_DIR}/src/StringUtils.cpp - ) - set (OSSupport_HDRS - ${CMAKE_SOURCE_DIR}/src/OSSupport/CriticalSection.h - ${CMAKE_SOURCE_DIR}/src/OSSupport/Event.h - ${CMAKE_SOURCE_DIR}/src/StringUtils.h - ${CMAKE_SOURCE_DIR}/src/Globals.h - ) - add_library(OSSupport - ${OSSupport_SRCS} - ${OSSupport_HDRS} - ) - target_link_libraries(OSSupport PUBLIC fmt::fmt) -endif() +set (OSSupport_SRCS + ${CMAKE_SOURCE_DIR}/src/OSSupport/CriticalSection.cpp + ${CMAKE_SOURCE_DIR}/src/OSSupport/Event.cpp + ${CMAKE_SOURCE_DIR}/src/StringUtils.cpp +) +set (OSSupport_HDRS + ${CMAKE_SOURCE_DIR}/src/OSSupport/CriticalSection.h + ${CMAKE_SOURCE_DIR}/src/OSSupport/Event.h + ${CMAKE_SOURCE_DIR}/src/StringUtils.h + ${CMAKE_SOURCE_DIR}/src/Globals.h +) +add_library(OSSupport + ${OSSupport_SRCS} + ${OSSupport_HDRS} +) +target_link_libraries(OSSupport PUBLIC fmt::fmt) # Define individual tests: # StressEvent: Stress-test the cEvent implementation: add_executable(StressEvent-exe StressEvent.cpp) -target_link_libraries(StressEvent-exe OSSupport fmt::fmt) +target_link_libraries(StressEvent-exe OSSupport fmt::fmt Threads::Threads) add_test(NAME StressEvent-test COMMAND StressEvent-exe) @@ -42,7 +35,7 @@ set_target_properties( ) set_target_properties( OSSupport - PROPERTIES FOLDER Lib + PROPERTIES FOLDER Tests/Libraries ) diff --git a/tests/SchematicFileSerializer/CMakeLists.txt b/tests/SchematicFileSerializer/CMakeLists.txt index a431bee8e..3bee9ee0c 100644 --- a/tests/SchematicFileSerializer/CMakeLists.txt +++ b/tests/SchematicFileSerializer/CMakeLists.txt @@ -1,12 +1,7 @@ -cmake_minimum_required(VERSION 3.0.2) -enable_testing() - include_directories(${CMAKE_SOURCE_DIR}/src/) include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/lib/) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) -add_definitions(-DTEST_GLOBALS=1) - set (SHARED_SRCS ${CMAKE_SOURCE_DIR}/src/BiomeDef.cpp ${CMAKE_SOURCE_DIR}/src/BlockArea.cpp @@ -66,7 +61,7 @@ set (SRCS if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - add_flags_cxx("-Wno-error=global-constructors") + add_compile_options("-Wno-error=global-constructors") endif() diff --git a/tests/UUID/CMakeLists.txt b/tests/UUID/CMakeLists.txt index 384ebe1e5..f1d61e4a1 100644 --- a/tests/UUID/CMakeLists.txt +++ b/tests/UUID/CMakeLists.txt @@ -1,6 +1,3 @@ -cmake_minimum_required(VERSION 3.0.2) -enable_testing() - set (SHARED_SRCS ${CMAKE_SOURCE_DIR}/src/UUID.cpp ${CMAKE_SOURCE_DIR}/src/StringUtils.cpp diff --git a/travisbuild.sh b/travisbuild.sh index adcf5d12c..5c4a559bb 100755 --- a/travisbuild.sh +++ b/travisbuild.sh @@ -8,26 +8,36 @@ export CUBERITE_BUILD_DATETIME=`date` # Use ccache if available if [ `which ccache` ]; then + # Re-run compile on pre-processed sources on cache miss + # "It's slower actually, but clang builds fail without it." export CCACHE_CPP2=true + + # Tell CMake of ccache's existence CACHE_ARGS="-DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache" + echo "Using ccache installed at $(which ccache)" ccache --max-size=3G ccache -z # Zero statistics fi -cmake . -DBUILD_TOOLS=1 -DSELF_TEST=1 ${CACHE_ARGS}; +# Work around a Clang + ccache issue with failing +# builds by disabling precompiled headers +cmake . -DBUILD_TOOLS=YES \ + -DPRECOMPILE_HEADERS=NO \ + -DUNITY_BUILDS=${TRAVIS_CUBERITE_UNITY_BUILDS-YES} \ + -DSELF_TEST=YES \ + ${CACHE_ARGS}; echo "Building..." -cmake --build . -j 2 +cmake --build . --parallel 2; if [ `which ccache` ]; then - echo "Built with ccache, outputting cache stats..." - ccache -s + echo "Built with ccache, outputting cache stats..." + ccache -s fi echo "Testing..." - -ctest -j 2 -V; +ctest --output-on-failure --parallel 2; cd Server/; touch apiCheckFailed.flag -- cgit v1.2.3