Skip to content
James Robertson edited this page Feb 13, 2021 · 15 revisions

Commands you might find useful:

simple client and server compilation with Ninja

  • cmake . -B build -G Ninja -DFREECIV_ENABLE_TOOLS=NO -DFREECIV_ENABLE_SERVER=YES -DCMAKE_BUILD_TYPE=Release -DFREECIV_ENABLE_NLS=NO
  • cmake --build build

complex way of adding compiler path

  • /usr/bin/cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=/usr/lib/llvm/10/bin/clang -DCMAKE_CXX_COMPILER:FILEPATH=/usr/lib/llvm/10/bin/clang++ -B build -G Ninja

build with ccache

  • cmake .. -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache -DFREECIV_ENABLE_TOOLS=NO -DFREECIV_ENABLE_SERVER=YES -DCMAKE_BUILD_TYPE=Debug -DFREECIV_ENABLE_NLS=NO

clazy checks with make instead ninja, full list of checks is here: https://github.com/KDE/clazy

  • export CLAZY_CHECKS="level0,detaching-temporary" # Enables all from level0 and also detaching-temporary
  • cmake .. -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clazy -DCMAKE_CXX_FLAGS="-std=c++11 -O0 -ggdb -pipe

enable clazy fixits

  • export CLAZY_EXPORT_FIXES
  • cmake .. -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clazy -DCMAKE_CXX_FLAGS="-Xclang -plugin-arg-clazy -Xclang export-fixes"
  • clang-apply-replacements

if you want to build with LTO:

  • -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS="-mtune=native -O2 -pipe" -DCMAKE_CXX_FLAGS="-mtune=native -O2 -pipe -fgraphite -flto=8 -fuse-linker-plugin -fno-fat-lto-objects -fgraphite-identity -floop-interchange -floop-strip-mine -floop-block -fno-delete-null-pointer-checks" -DCMAKE_EXE_LINKER_FLAGS="-Wl,-O1 -Wl,--as-needed -Wl,-z,now -Wl,-z,relro"

build with custom Qt version

  • export CMAKE_PREFIX_PATH=/home/you/git/qt/6.0.0/gcc_64

use address sanitizer

  • -DCMAKE_CXX_FLAGS="-O0 -ggdb -fsanitize=address -fno-omit-frame-pointer" -DCMAKE_EXE_LINKER_FLAGS="-fsanitize=address"

other sanitizers you might find useful, you can use few at once

  • -DCMAKE_CXX_FLAGS="-fstack-protector-all" -DCMAKE_EXE_LINKER_FLAGS="-fstack-protector-all"
  • -DCMAKE_CXX_FLAGS="-fsanitize=undefined" -DCMAKE_EXE_LINKER_FLAGS="-fsanitize=undefined"
  • -DCMAKE_CXX_FLAGS="-fsanitize=alignment" -DCMAKE_EXE_LINKER_FLAGS="-fsanitize=alignment"
  • -DCMAKE_CXX_FLAGS="-fsanitize=thread" -DCMAKE_EXE_LINKER_FLAGS="-fsanitize=thread"

it's nice if you rebase your commits before sending, eg like that:

  • git fetch origin; git rebase origin/master

dont print stack traces

  • export QT_LOGGING_RULES="freeciv.stacktrace*=false"

show map scroll fps (and graphics logs)

  • QT_LOGGING_RULES="freeciv.graphics = true" build/freeciv-qt

add mingw triplet to build under windows

  • -DCMAKE_PREFIX_PATH=***\vcpkg\installed\x86-mingw-static

Format convention

Here's a command that will run clang-format on all changed files:

find \( -name *.cpp -or -name *.h \) -not -exec git diff --exit-code --quiet '{}' \; -print -exec clang-format -i '{}' \;

If you dont modify source code you can add to a commit message

  • [skip travis]