Minetest for C++11 (CMakeLists + Travis)
authorLoic Blot <loic.blot@unix-experience.fr>
Fri, 26 May 2017 15:03:46 +0000 (17:03 +0200)
committerLoïc Blot <nerzhul@users.noreply.github.com>
Sun, 4 Jun 2017 07:57:08 +0000 (09:57 +0200)
* 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

16 files changed:
.clang-format
.travis.yml
CMakeLists.txt
src/CMakeLists.txt
src/database-dummy.h
src/database-leveldb.h
src/environment.h
src/nameidmapping.h
src/script/lua_api/l_metadata.h
src/touchscreengui.h
util/buildbot/buildwin32.sh
util/buildbot/buildwin64.sh
util/travis/before_install.sh
util/travis/common.sh
util/travis/lint.sh
util/travis/script.sh

index d2e2f2940f1a1bdce76b4eafd7c05b3f1e65b065..f1d51a04fa78146c2790e3c613d73bf53477eeeb 100644 (file)
@@ -2,7 +2,7 @@ BasedOnStyle: LLVM
 IndentWidth: 8
 UseTab: Always
 BreakBeforeBraces: Custom
-Standard: Cpp03
+Standard: Cpp11
 BraceWrapping:
   AfterClass: true
   AfterControlStatement: false
index 57d934c90fa62b6a53e7e0973b3580d75688b2e4..123705fe62bf09d63fe1f9f73a182b168f303358 100644 (file)
@@ -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
+      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:
+          packages: ['gcc-7', 'g++-7']
+          sources: &sources
+            - ubuntu-toolchain-r-test
+
+    - env: PLATFORM=Unix COMPILER=clang-3.6
       compiler: clang
       os: linux
-    - env: PLATFORM=Unix COMPILER=clang VALGRIND=1
+      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
-      dist: trusty
-    - env: COMPILER=none LINT=1
+      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
-      dist: trusty
-    - env: PLATFORM=Unix COMPILER=g++-6
-      compiler: gcc
+      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:
-    sources: &sources
-      - ubuntu-toolchain-r-test
+      addons:
+        apt:
+          packages: ['clang-format-4.0']
+          sources: &sources
+            - llvm-toolchain-trusty-4.0
+
+
+
index 763d554b9a64482e50bc8ddc3b0d216708f3fcaa..5494c91b545b1b9ed3b85ad2e0cb9ecc43a95360 100644 (file)
@@ -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)
index 7c1a4eee0959b1ba92393b3c27d3b59cdfc19be9..6963d0306d56adffee9f1d857511fcc45309dba0 100644 (file)
@@ -708,7 +708,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\"")
@@ -728,9 +728,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")
index 7d1cb2279f32fe3f701c815e9b2a15c0dac61158..c4060d5f19ad383f023ee4588bc67df95122d5b1 100644 (file)
@@ -40,6 +40,7 @@ public:
 
        void beginSave() {}
        void endSave() {}
+
 private:
        std::map<s64, std::string> m_database;
 };
index 52ccebe70a4c7ea99a35e366bc3ad13082eb0cfd..1a51f98b6147e2cb6f66268fe11c1cb722cf8371 100644 (file)
@@ -41,6 +41,7 @@ public:
 
        void beginSave() {}
        void endSave() {}
+
 private:
        leveldb::DB *m_database;
 };
index 1de13e9eddae8628f79730a694650e4f78fbdeb1..5a40ff31ab57332854a9d8be1ea4c5ae066507fd 100644 (file)
@@ -79,6 +79,7 @@ public:
        u32 m_added_objects;
 
        IGameDef *getGameDef() { return m_gamedef; }
+
 protected:
        GenericAtomic<float> m_time_of_day_speed;
 
index a2f3a30623da8e571f38e60cb9aab1970082157e..be353327db8533e1e3f7a0118a3857a28bad3b94 100644 (file)
@@ -80,6 +80,7 @@ public:
                return true;
        }
        u16 size() const { return m_id_to_name.size(); }
+
 private:
        UNORDERED_MAP<u16, std::string> m_id_to_name;
        UNORDERED_MAP<std::string, u16> m_name_to_id;
index a4d8214d323ba7889bf5541c0ae5d058c43be8ed..a479e64b021bd63957f544d23b3b5d00b527add6 100644 (file)
@@ -32,6 +32,7 @@ class MetaDataRef : public ModApiBase
 {
 public:
        virtual ~MetaDataRef() {}
+
 protected:
        static MetaDataRef *checkobject(lua_State *L, int narg);
 
index f4f1766c91042e1db53788d0b86535ebc7ff3b10..a8c59fa9aee3c357a20bf8dcba80747d857c55ba 100644 (file)
@@ -172,7 +172,7 @@ private:
        IEventReceiver *m_receiver;
        ISimpleTextureSource *m_texturesource;
        v2u32 m_screensize;
-       std::map<int, rect<s32> > m_hud_rects;
+       std::map<int, rect<s32>> m_hud_rects;
        std::map<int, irr::EKEY_CODE> m_hud_ids;
        bool m_visible; // is the gui visible
 
index d807003d287c4682750b172f9bc486dae35c52ba..26f43b235a38d0369bd2f4ac522e62e797fe7371 100755 (executable)
@@ -16,13 +16,13 @@ toolchain_file=$dir/toolchain_mingw.cmake
 irrlicht_version=1.8.4
 ogg_version=1.3.2
 vorbis_version=1.3.5
-curl_version=7.50.3
+curl_version=7.54.0
 gettext_version=0.19.8.1
-freetype_version=2.7
-sqlite3_version=3.14.2
-luajit_version=2.1.0-beta2
-leveldb_version=1.18
-zlib_version=1.2.8
+freetype_version=2.8
+sqlite3_version=3.19.2
+luajit_version=2.1.0-beta3
+leveldb_version=1.19
+zlib_version=1.2.11
 
 mkdir -p $packagedir
 mkdir -p $libdir
index 3d6965f1ea9185744c524bec40d7c5e411ebd982..31d9aad7a895bb86ebb981bebf4612f518867edd 100755 (executable)
@@ -16,13 +16,13 @@ toolchain_file=$dir/toolchain_mingw64.cmake
 irrlicht_version=1.8.4
 ogg_version=1.3.2
 vorbis_version=1.3.5
-curl_version=7.50.3
+curl_version=7.54.0
 gettext_version=0.19.8.1
-freetype_version=2.7
-sqlite3_version=3.14.2
-luajit_version=2.1.0-beta2
-leveldb_version=1.18
-zlib_version=1.2.8
+freetype_version=2.8
+sqlite3_version=3.19.2
+luajit_version=2.1.0-beta3
+leveldb_version=1.19
+zlib_version=1.2.11
 
 mkdir -p $packagedir
 mkdir -p $libdir
index a4328fa46aff74ba09096efe2b4c59f57bea31f5..afc16c332f0ba7b0b4c54dc0896e9251ff5b8f9b 100755 (executable)
@@ -1,49 +1,33 @@
 #!/bin/bash -e
+
 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
-               brew update
-               brew install freetype gettext hiredis irrlicht jpeg leveldb libogg libvorbis luajit
-               #brew upgrade postgresql
+               install_macosx_deps
        fi
 elif [[ $PLATFORM == "Win32" ]]; then
-       wget http://minetest.kitsunemimi.pw/mingw_w64_i686_ubuntu12.04_4.9.1.7z -O mingw.7z
+       sudo apt-get update
+       sudo apt-get install p7zip-full
+       wget http://minetest.kitsunemimi.pw/mingw-w64-i686_7.1.1_ubuntu14.04.7z -O mingw.7z
        sed -e "s|%PREFIX%|i686-w64-mingw32|" \
                -e "s|%ROOTPATH%|/usr/i686-w64-mingw32|" \
                < util/travis/toolchain_mingw.cmake.in > util/buildbot/toolchain_mingw.cmake
        sudo 7z x -y -o/usr mingw.7z
 elif [[ $PLATFORM == "Win64" ]]; then
-       wget http://minetest.kitsunemimi.pw/mingw_w64_x86_64_ubuntu12.04_4.9.1.7z -O mingw.7z
+       sudo apt-get update
+       sudo apt-get install p7zip-full
+       wget http://minetest.kitsunemimi.pw/mingw-w64-x86_64_7.1.1_ubuntu14.04.7z -O mingw.7z
        sed -e "s|%PREFIX%|x86_64-w64-mingw32|" \
                -e "s|%ROOTPATH%|/usr/x86_64-w64-mingw32|" \
                < util/travis/toolchain_mingw.cmake.in > util/buildbot/toolchain_mingw64.cmake
index 35ceec08d93830b268d07145f62649d9449c7cce..a5b2de7282a014982a601e63d7b358aa23fa59a1 100644 (file)
@@ -1,5 +1,40 @@
 #!/bin/bash -e
 
+set_linux_compiler_env() {
+       if [[ "${COMPILER}" == "gcc-5.1" ]]; then
+               export CC=gcc-5.1
+               export CXX=g++-5.1
+       elif [[ "${COMPILER}" == "gcc-6" ]]; then
+               export CC=gcc-6
+               export CXX=g++-6
+       elif [[ "${COMPILER}" == "gcc-7" ]]; then
+               export CC=gcc-7
+               export CXX=g++-7
+       elif [[ "${COMPILER}" == "clang-3.6" ]]; then
+               export CC=clang-3.6
+               export CXX=clang++-3.6
+       elif [[ "${COMPILER}" == "clang-4.0" ]]; then
+               export CC=clang-4.0
+               export CXX=clang++-4.0
+       fi
+}
+
+# Linux build only
+install_linux_deps() {
+       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 libleveldb-dev
+}
+
+# Mac OSX build only
+install_macosx_deps() {
+       brew update
+       brew install freetype gettext hiredis irrlicht jpeg leveldb libogg libvorbis luajit
+       #brew upgrade postgresql
+}
+
 # Relative to git-repository root:
 TRIGGER_COMPILE_PATHS="src/.*\.(c|cpp|h)|CMakeLists.txt|cmake/Modules/|util/travis/|util/buildbot/"
 
index cd5f41779a139aa50a073a1e1df0ae25560eb93e..555cf3ebe0a36a6bf74dc7e9a7b600877407aa5b 100644 (file)
@@ -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
index 14b8dfb7334489449ad48c42c502037f6e4c048b..e5be1fe3268157cab1b62a0624e2207c27e9fad1 100755 (executable)
@@ -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