diff options
author | Tiger Wang <ziwei.tiger@outlook.com> | 2020-05-28 00:48:49 +0200 |
---|---|---|
committer | Tiger Wang <ziwei.tiger@outlook.com> | 2020-07-12 23:00:07 +0200 |
commit | 2c0fc395ba95bcaa3b877b88ebd2d1ee0affff9a (patch) | |
tree | 8e3922013a79e1bb83797a55ec83eac19bf0d2ce /CMake | |
parent | More CMake cleanup (diff) | |
download | cuberite-2c0fc395ba95bcaa3b877b88ebd2d1ee0affff9a.tar cuberite-2c0fc395ba95bcaa3b877b88ebd2d1ee0affff9a.tar.gz cuberite-2c0fc395ba95bcaa3b877b88ebd2d1ee0affff9a.tar.bz2 cuberite-2c0fc395ba95bcaa3b877b88ebd2d1ee0affff9a.tar.lz cuberite-2c0fc395ba95bcaa3b877b88ebd2d1ee0affff9a.tar.xz cuberite-2c0fc395ba95bcaa3b877b88ebd2d1ee0affff9a.tar.zst cuberite-2c0fc395ba95bcaa3b877b88ebd2d1ee0affff9a.zip |
Diffstat (limited to '')
-rw-r--r-- | CMake/AddDependencies.cmake | 142 | ||||
-rw-r--r-- | CMake/Fixups.cmake | 26 | ||||
-rw-r--r-- | CMake/GenerateBindings.cmake | 220 | ||||
-rw-r--r-- | CMake/GroupSources.cmake | 76 | ||||
-rw-r--r-- | CMakeLists.txt | 30 |
5 files changed, 256 insertions, 238 deletions
diff --git a/CMake/AddDependencies.cmake b/CMake/AddDependencies.cmake index 72eead340..ecf18dd27 100644 --- a/CMake/AddDependencies.cmake +++ b/CMake/AddDependencies.cmake @@ -1,81 +1,83 @@ -# 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.") -set(SQLITECPP_RUN_CPPCHECK OFF CACHE BOOL "Run cppcheck C++ static analysis tool.") -set(SQLITECPP_RUN_DOXYGEN OFF CACHE BOOL "Run Doxygen C++ documentation tool.") -set(SQLITECPP_BUILD_EXAMPLES OFF CACHE BOOL "Build examples.") -set(SQLITECPP_BUILD_TESTS OFF CACHE BOOL "Build and run tests.") -set(SQLITECPP_INTERNAL_SQLITE ON CACHE BOOL "Add the internal SQLite3 source to the project.") -set(SQLITE_ENABLE_COLUMN_METADATA OFF CACHE BOOL "Enable Column::getColumnOriginName(). Require support from sqlite3 library.") +function(build_dependencies TARGET) + # 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.") + set(SQLITECPP_RUN_CPPCHECK OFF CACHE BOOL "Run cppcheck C++ static analysis tool.") + set(SQLITECPP_RUN_DOXYGEN OFF CACHE BOOL "Run Doxygen C++ documentation tool.") + set(SQLITECPP_BUILD_EXAMPLES OFF CACHE BOOL "Build examples.") + set(SQLITECPP_BUILD_TESTS OFF CACHE BOOL "Build and run tests.") + set(SQLITECPP_INTERNAL_SQLITE ON CACHE BOOL "Add the internal SQLite3 source to the project.") + set(SQLITE_ENABLE_COLUMN_METADATA OFF CACHE BOOL "Enable Column::getColumnOriginName(). Require support from sqlite3 library.") -# Set options for LibEvent, disable all their tests and benchmarks: -set(EVENT__DISABLE_OPENSSL YES CACHE BOOL "Disable OpenSSL in LibEvent") -set(EVENT__DISABLE_BENCHMARK YES CACHE BOOL "Disable LibEvent benchmarks") -set(EVENT__DISABLE_TESTS YES CACHE BOOL "Disable LibEvent tests") -set(EVENT__DISABLE_REGRESS YES CACHE BOOL "Disable LibEvent regression tests") -set(EVENT__DISABLE_SAMPLES YES CACHE BOOL "Disable LibEvent samples") -set(EVENT__LIBRARY_TYPE "STATIC" CACHE STRING "Use static LibEvent libraries") + # Set options for LibEvent, disable all their tests and benchmarks: + set(EVENT__DISABLE_OPENSSL YES CACHE BOOL "Disable OpenSSL in LibEvent") + set(EVENT__DISABLE_BENCHMARK YES CACHE BOOL "Disable LibEvent benchmarks") + set(EVENT__DISABLE_TESTS YES CACHE BOOL "Disable LibEvent tests") + set(EVENT__DISABLE_REGRESS YES CACHE BOOL "Disable LibEvent regression tests") + set(EVENT__DISABLE_SAMPLES YES CACHE BOOL "Disable LibEvent samples") + set(EVENT__LIBRARY_TYPE "STATIC" CACHE STRING "Use static LibEvent libraries") -# 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") + # 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") -# Set options for mbedtls: -set(ENABLE_PROGRAMS OFF CACHE BOOL "Build mbed TLS programs.") -set(ENABLE_TESTING OFF CACHE BOOL "Build mbed TLS tests.") + # Set options for mbedtls: + set(ENABLE_PROGRAMS OFF CACHE BOOL "Build mbed TLS programs.") + set(ENABLE_TESTING OFF CACHE BOOL "Build mbed TLS tests.") -# Enumerate all submodule libraries -# SQLiteCpp needs to be included before sqlite so the lsqlite target is available: -set(DEPENDENCIES expat fmt jsoncpp libevent lua luaexpat mbedtls SQLiteCpp sqlite tolua++ zlib) -foreach(DEPENDENCY ${DEPENDENCIES}) - # Check that the libraries are present: - if (NOT EXISTS "${PROJECT_SOURCE_DIR}/lib/${DEPENDENCY}/CMakeLists.txt") - message(FATAL_ERROR "${DEPENDENCY} is missing in folder lib/${DEPENDENCY}. Have you initialized and updated the submodules / downloaded the extra libraries?") - endif() + # Enumerate all submodule libraries + # SQLiteCpp needs to be included before sqlite so the lsqlite target is available: + set(DEPENDENCIES expat fmt jsoncpp libevent lua luaexpat mbedtls SQLiteCpp sqlite tolua++ zlib) + foreach(DEPENDENCY ${DEPENDENCIES}) + # Check that the libraries are present: + if (NOT EXISTS "${PROJECT_SOURCE_DIR}/lib/${DEPENDENCY}/CMakeLists.txt") + message(FATAL_ERROR "${DEPENDENCY} is missing in folder lib/${DEPENDENCY}. 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/${DEPENDENCY}" EXCLUDE_FROM_ALL) -endforeach() + # 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/${DEPENDENCY}" EXCLUDE_FROM_ALL) + endforeach() -# Add required includes: -target_include_directories( - ${CMAKE_PROJECT_NAME} SYSTEM PRIVATE - lib/mbedtls/include - lib/TCLAP/include - lib # TODO fix files including zlib/x instead of x -) + # Add required includes: + target_include_directories( + ${TARGET} SYSTEM PRIVATE + 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 dependencies as private: + target_link_libraries( + ${TARGET} 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() + # Link process information library: + if (WIN32) + target_link_libraries(${TARGET} PRIVATE Psapi.lib) + endif() -# Special case handling for libevent pthreads: -if(NOT WIN32) - target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE event_pthreads) -endif() + # Special case handling for libevent pthreads: + if(NOT WIN32) + target_link_libraries(${TARGET} PRIVATE event_pthreads) + endif() -# Prettify jsoncpp_lib name in VS solution explorer: -set_property(TARGET jsoncpp_lib PROPERTY PROJECT_LABEL "jsoncpp") + # Prettify jsoncpp_lib name in VS solution explorer: + set_property(TARGET jsoncpp_lib PROPERTY PROJECT_LABEL "jsoncpp") -if (WIN32) - add_subdirectory(lib/luaproxy) -endif() + if (WIN32) + add_subdirectory(lib/luaproxy) + endif() +endfunction() diff --git a/CMake/Fixups.cmake b/CMake/Fixups.cmake index 5abff5abd..374196d09 100644 --- a/CMake/Fixups.cmake +++ b/CMake/Fixups.cmake @@ -1,14 +1,16 @@ -# 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() +function(emit_fixups) + # 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) + # 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() + 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() +endfunction() diff --git a/CMake/GenerateBindings.cmake b/CMake/GenerateBindings.cmake index 153f1a58a..584ad1b66 100644 --- a/CMake/GenerateBindings.cmake +++ b/CMake/GenerateBindings.cmake @@ -1,112 +1,114 @@ -# 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 -) +function(enable_bindings_generation) + # 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 -) + # 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/") + # 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 -) + # Generate the bindings: + add_custom_command( + OUTPUT ${BINDING_OUTPUTS} + COMMAND luaexe BindingsProcessor.lua + WORKING_DIRECTORY ${BINDINGS_FOLDER} + DEPENDS ${BINDING_DEPENDENCIES} luaexe + ) +endfunction() diff --git a/CMake/GroupSources.cmake b/CMake/GroupSources.cmake index 0f1762110..a8706794d 100644 --- a/CMake/GroupSources.cmake +++ b/CMake/GroupSources.cmake @@ -1,42 +1,44 @@ -# Enable the support for solution folders in MSVC -set_property(GLOBAL PROPERTY USE_FOLDERS ON) +function(group_sources) + # 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) + # Put projects into solution folders in MSVC: set_target_properties( - luaproxy - PROPERTIES FOLDER Support + event_core_static + event_extra_static + expat + fmt + jsoncpp_lib + lua + luaexpat + mbedcrypto + mbedtls + mbedx509 + lsqlite + sqlite3 + SQLiteCpp + tolualib + zlib + PROPERTIES FOLDER Libraries ) -endif() -if(${BUILD_TOOLS}) - set_target_properties( - MCADefrag - ProtoProxy - PROPERTIES FOLDER Tools - ) -endif() + # 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}) + # 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}) +endfunction() diff --git a/CMakeLists.txt b/CMakeLists.txt index f31f33f13..9931176fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,7 +28,19 @@ 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) -# We need C++17 features +include("CMake/AddDependencies.cmake") +include("CMake/Fixups.cmake") +include("CMake/GenerateBindings.cmake") +include("CMake/GroupSources.cmake") +include("SetFlags.cmake") + +# Add build timestamp and details: +include("CMake/StampBuild.cmake") + +# TODO: set_build_stamp() +set_global_flags() + +# We need C++17 features: set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) @@ -40,15 +52,15 @@ if(WHOLE_PROGRAM_OPTIMISATION) set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ${IPO_SUPPORTED}) endif() -# Static CRT +# Static CRT: set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>") -# Add build timestamp and details: -include("CMake/StampBuild.cmake") - add_executable(${CMAKE_PROJECT_NAME}) add_subdirectory(src) +enable_warnings(${CMAKE_PROJECT_NAME}) +build_dependencies(${CMAKE_PROJECT_NAME}) + # Set the startup project to Cuberite, and the debugger dir: set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT ${CMAKE_PROJECT_NAME}) set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/Server") @@ -93,8 +105,6 @@ if(${SELF_TEST}) add_subdirectory(tests) endif() -include("CMake/AddDependencies.cmake") -include("CMake/Fixups.cmake") -include("CMake/GenerateBindings.cmake") -include("CMake/GroupSources.cmake") -include("SetFlags.cmake") +emit_fixups() +group_sources() +enable_bindings_generation() |