changeset 1264:3cd8dd706aaa

Add possibility to build with CLANG and document it. This only works for now with the c parts of the code.
author Andre Heinecke <andre.heinecke@intevation.de>
date Fri, 26 Sep 2014 17:59:49 +0200
parents 827abc0923a8
children b18f08034c24
files CMakeLists.txt INSTALL common/binverify.c common/certhelp.h common/listutil.c
diffstat 5 files changed, 36 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- 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()
 
--- 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
--- 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)
--- 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"
--- 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)
 

http://wald.intevation.org/projects/trustbridge/