CMake: support sanitizers on gcc builds, too.
This also fixes Travis Linux builds.pull/200/merge
parent
49ff36fd51
commit
c5a3b43665
|
@ -4,8 +4,10 @@ if echo $TRAVIS_TAG | grep ^v; then BUILD_TYPE=RelWithDebInfo; else BUILD_TYPE=D
|
||||||
|
|
||||||
mkdir build
|
mkdir build
|
||||||
cd build
|
cd build
|
||||||
# We build without the GUI until Travis updates to an Ubuntu version with GTK 3.22.
|
# We build without the GUI until Travis updates to an Ubuntu version with GTK 3.16+.
|
||||||
cmake .. -DCMAKE_C_COMPILER=clang-3.9 -DCMAKE_CXX_COMPILER=clang++-3.9 \
|
cmake .. \
|
||||||
|
-DCMAKE_C_COMPILER=gcc-5 \
|
||||||
|
-DCMAKE_CXX_COMPILER=g++-5 \
|
||||||
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
|
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
|
||||||
-DENABLE_GUI=OFF \
|
-DENABLE_GUI=OFF \
|
||||||
-DENABLE_SANITIZERS=ON
|
-DENABLE_SANITIZERS=ON
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
#!/bin/sh -xe
|
#!/bin/sh -xe
|
||||||
|
|
||||||
wget -O - http://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
|
|
||||||
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
|
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
|
||||||
sudo add-apt-repository -y 'deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-3.9 main'
|
|
||||||
sudo apt-get update -qq
|
sudo apt-get update -qq
|
||||||
sudo apt-get install -q -y \
|
sudo apt-get install -q -y \
|
||||||
cmake cmake-data libc6-dev libpng12-dev zlib1g-dev libjson0-dev libfontconfig1-dev \
|
cmake cmake-data libc6-dev libpng12-dev zlib1g-dev libjson0-dev libfontconfig1-dev \
|
||||||
libgtkmm-3.0-dev libpangomm-1.4-dev libcairo2-dev libgl1-mesa-dev libglu-dev \
|
libgtkmm-3.0-dev libpangomm-1.4-dev libcairo2-dev libgl1-mesa-dev libglu-dev \
|
||||||
libfreetype6-dev dpkg-dev libstdc++-5-dev clang-3.9 clang++-3.9 lcov
|
libfreetype6-dev dpkg-dev gcc-5 g++-5 lcov
|
||||||
|
|
|
@ -80,15 +80,20 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(ENABLE_SANITIZERS)
|
if(ENABLE_SANITIZERS)
|
||||||
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
list(APPEND SANITIZERS address alignment bounds)
|
||||||
message(FATAL_ERROR "Sanitizers are only available when using Clang/Clang++")
|
list(APPEND SANITIZERS shift signed-integer-overflow integer-divide-by-zero)
|
||||||
|
list(APPEND SANITIZERS null bool enum)
|
||||||
|
list(APPEND SANITIZERS return)
|
||||||
|
string(REPLACE ";" "," SANITIZERS "${SANITIZERS}")
|
||||||
|
set(SANITIZE_FLAGS "-O1 -fsanitize=${SANITIZERS} -fno-sanitize-recover=address,undefined")
|
||||||
|
|
||||||
|
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||||
|
set(SANITIZE_FLAGS "${SANITIZE_FLAGS} -fno-omit-frame-pointer -fno-optimize-sibling-calls")
|
||||||
|
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||||
|
set(SANITIZE_FLAGS "${SANITIZE_FLAGS} -fuse-ld=gold")
|
||||||
|
else()
|
||||||
|
message(FATAL_ERROR "Sanitizers are only available when using GCC or Clang")
|
||||||
endif()
|
endif()
|
||||||
set(SANITIZE_FLAGS "-O1 -fno-omit-frame-pointer -fno-optimize-sibling-calls")
|
|
||||||
set(SANITIZE_FLAGS "${SANITIZE_FLAGS} -fsanitize=address,integer")
|
|
||||||
set(SANITIZE_FLAGS "${SANITIZE_FLAGS} -fno-sanitize-recover=integer")
|
|
||||||
# We assume IEEE floats, which means DIV/0 is defined; but ubsan doesn't do so by default.
|
|
||||||
set(SANITIZE_FLAGS "${SANITIZE_FLAGS} -fno-sanitize=float-divide-by-zero")
|
|
||||||
set(SANITIZE_FLAGS "${SANITIZE_FLAGS} -fno-sanitize=unsigned-integer-overflow")
|
|
||||||
|
|
||||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SANITIZE_FLAGS}")
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SANITIZE_FLAGS}")
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SANITIZE_FLAGS}")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SANITIZE_FLAGS}")
|
||||||
|
|
Loading…
Reference in New Issue