[PATCH] Add possibility to build with CLANG and document it
Wald Commits
scm-commit at wald.intevation.org
Fri Sep 26 17:59:53 CEST 2014
# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# Date 1411747189 -7200
# Node ID 3cd8dd706aaa3a70123f76fb1e4fde74f5b99d13
# Parent 827abc0923a80d35467de4dccb7e2aa64b87e8a3
Add possibility to build with CLANG and document it.
This only works for now with the c parts of the code.
diff -r 827abc0923a8 -r 3cd8dd706aaa CMakeLists.txt
--- a/CMakeLists.txt Fri Sep 26 16:06:44 2014 +0200
+++ b/CMakeLists.txt Fri Sep 26 17:59:49 2014 +0200
@@ -11,6 +11,7 @@
option(DO_RELEASE_BUILD "Build for a public release." OFF)
option(ENABLE_PROFILING "Set to enable profiling." OFF)
option(USE_CURL "Use libcurl to download updates and certificate lists." ON)
+option(USE_CLANG "Use clang to compile trustbridge." OFF)
set(DOWNLOAD_SERVER "https://tb-devel.intevation.de:443" CACHE STRING "Used as download server" )
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
@@ -21,6 +22,10 @@
cmake_policy(SET CMP0020 OLD)
endif()
+if (USE_CLANG)
+ message (STATUS "Using clang options to build trustbridge.")
+endif()
+
include(CTest)
include(GenerateCppcheck)
include(HGVersion)
@@ -82,14 +87,16 @@
add_definitions (-DUSE_REAL_RESOURCES)
endif()
+if (NOT USE_CLANG)
# Warn level to be used for privileged parts
-set(WARN_HARDENING_FLAGS " -Wextra -Wconversion -Wformat-security")
+ set(WARN_HARDENING_FLAGS " -Wextra -Wconversion -Wformat-security")
# Hardening flags
-set(HARDENING_FLAGS " -Wall -fstack-protector-all -fno-exceptions")
-set(HARDENING_FLAGS " ${HARDENING_FLAGS} -Wstack-protector")
-set(HARDENING_FLAGS " ${HARDENING_FLAGS} --param ssp-buffer-size=4")
-set(HARDENING_FLAGS " ${HARDENING_FLAGS} -D_FORTIFY_SOURCE=2 -O0")
+ set(HARDENING_FLAGS " -Wall -fstack-protector-all -fno-exceptions")
+ set(HARDENING_FLAGS " ${HARDENING_FLAGS} -Wstack-protector")
+ set(HARDENING_FLAGS " ${HARDENING_FLAGS} --param ssp-buffer-size=4")
+ set(HARDENING_FLAGS " ${HARDENING_FLAGS} -D_FORTIFY_SOURCE=2 -O0")
+endif()
if(ENABLE_PROFILING)
set(PROFILING_FLAGS "-fprofile-arcs -ftest-coverage")
@@ -102,10 +109,10 @@
add_definitions(-DMINGW_HAS_SECURE_API) # for _s functions
endif(WIN32)
-if(UNIX)
+if(UNIX AND NOT USE_CLANG)
set(HARDENING_FLAGS " ${HARDENING_FLAGS} -pie -fPIE -ftrapv")
set(HARDENING_FLAGS " ${HARDENING_FLAGS} -Wl,-z,relro,-z,now")
-elseif(WIN32)
+elseif(WIN32 AND NOT USE_CLANG)
set(HARDENING_FLAGS " ${HARDENING_FLAGS} -Wl,--dynamicbase -Wl,--nxcompat")
endif()
diff -r 827abc0923a8 -r 3cd8dd706aaa INSTALL
--- a/INSTALL Fri Sep 26 16:06:44 2014 +0200
+++ b/INSTALL Fri Sep 26 17:59:49 2014 +0200
@@ -107,6 +107,14 @@
cd build-linux
cmake .. -DCMAKE_PREFIX_PATH=$YOURPREFIX
+To build with clang (if it is installed):
+
+ mkdir build-clang
+ cd build-clang
+ CC=/usr/bin/clang \
+ CXX=/usr/bin/clang++ \
+ cmake .. -DCMAKE_PREFIX_PATH=$YOURPREFIX \
+ -DUSE_CLANG=TRUE
I386
====
@@ -167,7 +175,8 @@
--without-zlib
make && make install
-Now for Trustbridge itself
+Now for Trustbridge itself:
+
cd ../../trustbridge
mkdir build-i386
cd build-i386
diff -r 827abc0923a8 -r 3cd8dd706aaa common/binverify.c
--- a/common/binverify.c Fri Sep 26 16:06:44 2014 +0200
+++ b/common/binverify.c Fri Sep 26 17:59:49 2014 +0200
@@ -256,14 +256,18 @@
}
#else /* WIN32 */
+#ifndef __clang__
#pragma GCC diagnostic ignored "-Wconversion"
+#endif
/* Polarssl mh.h contains a conversion which gcc warns about */
#include <polarssl/pk.h>
#include <polarssl/base64.h>
#include <polarssl/sha256.h>
#include <polarssl/error.h>
#include <polarssl/x509_crt.h>
+#ifndef __clang__
#pragma GCC diagnostic pop
+#endif
bin_verify_result
verify_binary_linux(const char *filename, size_t name_len)
diff -r 827abc0923a8 -r 3cd8dd706aaa common/certhelp.h
--- a/common/certhelp.h Fri Sep 26 16:06:44 2014 +0200
+++ b/common/certhelp.h Fri Sep 26 17:59:49 2014 +0200
@@ -9,12 +9,16 @@
#define CERTHELP_H
/* Polarssl mh.h contains a conversion which gcc warns about */
+#ifndef __clang__
#pragma GCC diagnostic ignored "-Wsign-conversion"
#pragma GCC diagnostic ignored "-Wconversion"
+#endif
#include <polarssl/oid.h>
#include <polarssl/x509_crt.h>
+#ifndef __clang__
#pragma GCC diagnostic pop
#pragma GCC diagnostic pop
+#endif
#define CERT_OID_CN (unsigned char *)OID_AT_CN "\0"
#define CERT_OID_O (unsigned char *)OID_AT_ORGANIZATION "\0"
diff -r 827abc0923a8 -r 3cd8dd706aaa common/listutil.c
--- a/common/listutil.c Fri Sep 26 16:06:44 2014 +0200
+++ b/common/listutil.c Fri Sep 26 17:59:49 2014 +0200
@@ -30,12 +30,16 @@
#include "pubkey-test.h"
#endif
+#ifndef __clang__
#pragma GCC diagnostic ignored "-Wconversion"
+#endif
/* Polarssl mh.h contains a conversion which gcc warns about */
#include <polarssl/pk.h>
#include <polarssl/base64.h>
#include <polarssl/sha256.h>
+#ifndef __clang__
#pragma GCC diagnostic pop
+#endif
#define MAX_FILESIZE (MAX_LINE_LENGTH * MAX_LINES)
More information about the Trustbridge-commits
mailing list