From b35744cc2e7b54333c829516adc92f4b00774905 Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Fri, 26 May 2017 17:03:46 +0200 Subject: [PATCH] Minetest for C++11 (CMakeLists + Travis) * Move GCC to GCC 6 & GCC 7 * Move Clang to Clang 3.6 & Clang 4.0 * LINT moves from Clang 3.9 to Clang 4.0 * Move XCode 7.3 to 8.0 * Use more travis tricks to install compilers instead of adding complexity to our build script * Clang format fixes on checked files (compat Cpp11 instead of Cpp03) * Mingw GCC update from 4.8.4 to 5.3 (Ubuntu Xenial) * Drop mingw cmake generated files and add them to gitignore --- .clang-format | 2 +- .travis.yml | 88 ++++++++++++++++++++++++++------- CMakeLists.txt | 2 + src/CMakeLists.txt | 5 +- src/database-dummy.h | 1 + src/database-leveldb.h | 1 + src/environment.h | 1 + src/nameidmapping.h | 1 + src/script/lua_api/l_metadata.h | 1 + src/touchscreengui.h | 2 +- util/travis/before_install.sh | 27 ++-------- util/travis/common.sh | 1 - util/travis/lint.sh | 4 +- util/travis/script.sh | 19 +++---- 14 files changed, 94 insertions(+), 61 deletions(-) diff --git a/.clang-format b/.clang-format index d2e2f2940..f1d51a04f 100644 --- a/.clang-format +++ b/.clang-format @@ -2,7 +2,7 @@ BasedOnStyle: LLVM IndentWidth: 8 UseTab: Always BreakBeforeBraces: Custom -Standard: Cpp03 +Standard: Cpp11 BraceWrapping: AfterClass: true AfterControlStatement: false diff --git a/.travis.yml b/.travis.yml index 57d934c90..123705fe6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: cpp before_install: ./util/travis/before_install.sh script: ./util/travis/script.sh sudo: required +dist: trusty notifications: email: false matrix: @@ -10,30 +11,81 @@ matrix: - env: PLATFORM=Win32 compiler: gcc os: linux + addons: + apt: + packages: ['gcc-mingw-w64-i686', 'g++-mingw-w64-i686', 'binutils-mingw-w64-i686'] + sources: &sources + - ubuntu-toolchain-r-test + - sourceline: 'deb http://mirrors.kernel.org/ubuntu xenial main universe' + - env: PLATFORM=Win64 compiler: gcc os: linux - - env: PLATFORM=Unix COMPILER=clang + addons: + apt: + packages: ['gcc-mingw-w64-x86-64', 'g++-mingw-w64-x86-64', 'binutils-mingw-w64-x86-64'] + sources: &sources + - ubuntu-toolchain-r-test + - sourceline: 'deb http://mirrors.kernel.org/ubuntu xenial main universe' + + - env: PLATFORM=Unix compiler: clang os: osx - - env: PLATFORM=Unix COMPILER=g++ + osx_image: xcode8 + + - env: PLATFORM=Unix COMPILER=gcc-6 compiler: gcc os: linux - - env: PLATFORM=Unix COMPILER=clang - compiler: clang - os: linux - - env: PLATFORM=Unix COMPILER=clang VALGRIND=1 - compiler: clang - os: linux - dist: trusty - - env: COMPILER=none LINT=1 - compiler: clang - os: linux - dist: trusty - - env: PLATFORM=Unix COMPILER=g++-6 + addons: + apt: + packages: ['gcc-6', 'g++-6'] + sources: &sources + - ubuntu-toolchain-r-test + + - env: PLATFORM=Unix COMPILER=gcc-7 compiler: gcc os: linux -addons: - apt: - sources: &sources - - ubuntu-toolchain-r-test + addons: + apt: + packages: ['gcc-7', 'g++-7'] + sources: &sources + - ubuntu-toolchain-r-test + + - env: PLATFORM=Unix COMPILER=clang-3.6 + compiler: clang + os: linux + addons: + apt: + packages: ['clang-3.6', 'clang++-3.6'] + sources: &sources + - llvm-toolchain-trusty-3.6 + + - env: PLATFORM=Unix COMPILER=clang-4.0 + compiler: clang + os: linux + addons: + apt: + packages: ['clang-4.0', 'clang++-4.0'] + sources: &sources + - llvm-toolchain-trusty-4.0 + + - env: PLATFORM=Unix COMPILER=clang-4.0 VALGRIND=1 + compiler: clang + os: linux + addons: + apt: + packages: ['valgrind', 'clang-4.0', 'clang++-4.0'] + sources: &sources + - llvm-toolchain-trusty-4.0 + + - env: LINT=1 + compiler: clang + os: linux + addons: + apt: + packages: ['clang-format-4.0'] + sources: &sources + - llvm-toolchain-trusty-4.0 + + + diff --git a/CMakeLists.txt b/CMakeLists.txt index 29d1cba72..1d6052c8a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,8 @@ endif() project(minetest) set(PROJECT_NAME_CAPITALIZED "Minetest") +# Works only for cmake 3.1 and greater +set(CMAKE_CXX_STANDARD 11) # Also remember to set PROTOCOL_VERSION in network/networkprotocol.h when releasing set(VERSION_MAJOR 0) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a0df21f66..494f8cba7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -710,7 +710,7 @@ include(CheckCXXCompilerFlag) if(MSVC) # Visual Studio - + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++11") # EHa enables SEH exceptions (used for catching segfaults) set(CMAKE_CXX_FLAGS_RELEASE "/EHa /Ox /GL /FD /MT /GS- /Zi /arch:SSE /fp:fast /D NDEBUG /D _HAS_ITERATOR_DEBUGGING=0 /TP") #set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/LTCG /NODEFAULTLIB:\"libcmtd.lib\" /NODEFAULTLIB:\"libcmt.lib\"") @@ -730,9 +730,10 @@ if(MSVC) # /MT = Link statically with standard library stuff set(CMAKE_C_FLAGS_RELEASE "/O2 /Ob2 /MT") else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") # Probably GCC if(APPLE) - SET( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pagezero_size 10000 -image_base 100000000" ) + SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pagezero_size 10000 -image_base 100000000" ) endif() if(WARN_ALL) set(RELEASE_WARNING_FLAGS "-Wall") diff --git a/src/database-dummy.h b/src/database-dummy.h index 7d1cb2279..c4060d5f1 100644 --- a/src/database-dummy.h +++ b/src/database-dummy.h @@ -40,6 +40,7 @@ public: void beginSave() {} void endSave() {} + private: std::map m_database; }; diff --git a/src/database-leveldb.h b/src/database-leveldb.h index 52ccebe70..1a51f98b6 100644 --- a/src/database-leveldb.h +++ b/src/database-leveldb.h @@ -41,6 +41,7 @@ public: void beginSave() {} void endSave() {} + private: leveldb::DB *m_database; }; diff --git a/src/environment.h b/src/environment.h index 1de13e9ed..5a40ff31a 100644 --- a/src/environment.h +++ b/src/environment.h @@ -79,6 +79,7 @@ public: u32 m_added_objects; IGameDef *getGameDef() { return m_gamedef; } + protected: GenericAtomic m_time_of_day_speed; diff --git a/src/nameidmapping.h b/src/nameidmapping.h index a2f3a3062..be353327d 100644 --- a/src/nameidmapping.h +++ b/src/nameidmapping.h @@ -80,6 +80,7 @@ public: return true; } u16 size() const { return m_id_to_name.size(); } + private: UNORDERED_MAP m_id_to_name; UNORDERED_MAP m_name_to_id; diff --git a/src/script/lua_api/l_metadata.h b/src/script/lua_api/l_metadata.h index a4d8214d3..a479e64b0 100644 --- a/src/script/lua_api/l_metadata.h +++ b/src/script/lua_api/l_metadata.h @@ -32,6 +32,7 @@ class MetaDataRef : public ModApiBase { public: virtual ~MetaDataRef() {} + protected: static MetaDataRef *checkobject(lua_State *L, int narg); diff --git a/src/touchscreengui.h b/src/touchscreengui.h index 1f680ccb2..dc7cf48f6 100644 --- a/src/touchscreengui.h +++ b/src/touchscreengui.h @@ -180,7 +180,7 @@ private: IEventReceiver *m_receiver; ISimpleTextureSource *m_texturesource; v2u32 m_screensize; - std::map > m_hud_rects; + std::map> m_hud_rects; std::map m_hud_ids; bool m_visible; // is the gui visible diff --git a/util/travis/before_install.sh b/util/travis/before_install.sh index b87668cce..afc16c332 100755 --- a/util/travis/before_install.sh +++ b/util/travis/before_install.sh @@ -2,36 +2,17 @@ echo "Preparing for $TRAVIS_COMMIT_RANGE" -if [[ "$LINT" == "1" ]]; then - curl http://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - - sudo add-apt-repository "deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-3.9 main" - sudo apt-get -yq update - sudo apt-get install clang-format-3.9 +. util/travis/common.sh + +if [[ "${LINT}" == "1" ]]; then exit 0 fi -. util/travis/common.sh needs_compile || exit 0 -if [[ $TRAVIS_OS_NAME == "linux" ]]; then - sudo apt-get update - sudo apt-get install p7zip-full $COMPILER -fi - if [[ $PLATFORM == "Unix" ]]; then if [[ $TRAVIS_OS_NAME == "linux" ]]; then - sudo apt-get update - sudo apt-get install libirrlicht-dev cmake libbz2-dev libpng12-dev \ - libjpeg-dev libxxf86vm-dev libgl1-mesa-dev libsqlite3-dev \ - libhiredis-dev libogg-dev libgmp-dev libvorbis-dev libopenal-dev \ - gettext libpq-dev postgresql-server-dev-all - # Linking to LevelDB is broken, use a custom build - wget http://minetest.kitsunemimi.pw/libleveldb-1.18-ubuntu12.04.7z - sudo 7z x -o/usr libleveldb-1.18-ubuntu12.04.7z - if [[ "$VALGRIND" == "1" ]]; then - sudo apt-get install valgrind - fi - + install_linux_deps else install_macosx_deps fi diff --git a/util/travis/common.sh b/util/travis/common.sh index 949540967..eabce7759 100644 --- a/util/travis/common.sh +++ b/util/travis/common.sh @@ -51,4 +51,3 @@ needs_compile() { fi git diff --name-only $RANGE -- | egrep -q "^($TRIGGER_COMPILE_PATHS)" } - diff --git a/util/travis/lint.sh b/util/travis/lint.sh index cd5f41779..555cf3ebe 100644 --- a/util/travis/lint.sh +++ b/util/travis/lint.sh @@ -1,8 +1,8 @@ #! /bin/bash function perform_lint() { echo "Performing LINT..." - if hash clang-format-3.9 2>/dev/null; then - CLANG_FORMAT=clang-format-3.9 + if hash clang-format-4.0 2>/dev/null; then + CLANG_FORMAT=clang-format-4.0 else CLANG_FORMAT=clang-format fi diff --git a/util/travis/script.sh b/util/travis/script.sh index 14b8dfb73..e5be1fe32 100755 --- a/util/travis/script.sh +++ b/util/travis/script.sh @@ -10,22 +10,15 @@ if [[ "$LINT" == "1" ]]; then exit 0 fi -if [[ $PLATFORM == "Unix" ]]; then +set_linux_compiler_env + +if [[ ${PLATFORM} == "Unix" ]]; then mkdir -p travisbuild cd travisbuild || exit 1 CMAKE_FLAGS='' - if [[ $COMPILER == "g++-6" ]]; then - export CC=gcc-6 - export CXX=g++-6 - fi - # Clang builds with FreeType fail on Travis - if [[ $CC == "clang" ]]; then - CMAKE_FLAGS+=' -DENABLE_FREETYPE=FALSE' - fi - - if [[ $TRAVIS_OS_NAME == "osx" ]]; then + if [[ ${TRAVIS_OS_NAME} == "osx" ]]; then CMAKE_FLAGS+=' -DCUSTOM_GETTEXT_PATH=/usr/local/opt/gettext' fi @@ -33,12 +26,12 @@ if [[ $PLATFORM == "Unix" ]]; then -DRUN_IN_PLACE=TRUE \ -DENABLE_GETTEXT=TRUE \ -DBUILD_SERVER=TRUE \ - $CMAKE_FLAGS .. + ${CMAKE_FLAGS} .. make -j2 echo "Running unit tests." CMD="../bin/minetest --run-unittests" - if [[ "$VALGRIND" == "1" ]]; then + if [[ "${VALGRIND}" == "1" ]]; then valgrind --leak-check=full --leak-check-heuristics=all --undef-value-errors=no --error-exitcode=9 ${CMD} && exit 0 else ${CMD} && exit 0