summaryrefslogtreecommitdiff
path: root/math/geogram/files/patch-cmake_platforms_FreeBSD-clang.cmake
blob: a18cace985f4680e60a69f93897f7df1d7c09801 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
--- cmake/platforms/FreeBSD-clang.cmake.orig	2018-12-09 17:28:39 UTC
+++ cmake/platforms/FreeBSD-clang.cmake
@@ -0,0 +1,153 @@
+###
+### Adopted from cmake/platforms/Linux-clang.cmake
+###
+
+#-------------------------------------------------------------------
+# Flags common to all FreeBSD based platforms with Clang compiler
+#-------------------------------------------------------------------
+
+include(${GEOGRAM_SOURCE_DIR}/cmake/platforms/FreeBSD.cmake)
+
+# Warning flags
+set(NORMAL_WARNINGS -Wall -Wextra)
+
+set(FULL_WARNINGS
+    -Weverything
+    -Wno-padded # Disable generating a message each time padding is used
+    -Wno-float-equal # Sometimes we compare floats (against 0.0 or 1.0 mainly)
+    -Wno-global-constructors
+    -Wno-exit-time-destructors
+    -Wno-old-style-cast # Yes, old-style cast is sometime more legible...
+    -Wno-format-nonliteral # Todo: use Laurent Alonso's trick
+    -Wno-disabled-macro-expansion # Else it complains with stderr
+)
+
+# Compile with full warnings by default
+add_definitions(${FULL_WARNINGS})
+
+# Run the static analyzer
+if(VORPALINE_WITH_CLANGSA)
+    add_definitions(--analyze)
+endif()
+
+# I do not know where this -Wno-maybe-uninitialized comes from
+# (but clang does not understand it), silence the warning for 
+# now...
+add_flags(CMAKE_CXX_FLAGS -Wno-unknown-warning-option)
+add_flags(CMAKE_C_FLAGS -Wno-unknown-warning-option)
+
+# Add static and dynamic bounds checks (optimization required)
+#add_flags(CMAKE_CXX_FLAGS_RELEASE -D_FORTIFY_SOURCE=2)
+#add_flags(CMAKE_C_FLAGS_RELEASE -D_FORTIFY_SOURCE=2)
+
+# Enable SSE3 instruction set
+add_flags(CMAKE_CXX_FLAGS -msse3)
+add_flags(CMAKE_C_FLAGS -msse3)
+
+# C++11 standard
+add_flags(CMAKE_CXX_FLAGS -Qunused-arguments -std=c++11 -Wno-c++98-compat)
+
+# Enable glibc parallel mode
+#add_flags(CMAKE_CXX_FLAGS -D_GLIBCXX_PARALLEL)
+
+
+# Generate debug information even in release mode
+#add_flags(CMAKE_CXX_FLAGS_RELEASE -g)
+#add_flags(CMAKE_C_FLAGS_RELEASE -g)
+
+
+# Additional debug flags
+# deactivated for now: I added bound checking in VOR::vector<>.
+#add_flags(CMAKE_CXX_FLAGS_DEBUG -D_GLIBCXX_DEBUG)
+
+
+# Compile and link with OpenMP ** NOT YET SUPPORTED in clang 3 **
+#add_flags(CMAKE_CXX_FLAGS -fopenmp)
+#add_flags(CMAKE_C_FLAGS -fopenmp)
+
+
+# Profiler compilation flags
+if(VORPALINE_WITH_GPROF)
+    message(FATAL_ERROR "Profiling is not (yet) available with clang")
+    message(STATUS "Building for code profiling")
+    #add_flags(CMAKE_CXX_FLAGS -pg -DPROFILER)
+    #add_flags(CMAKE_C_FLAGS -pg -DPROFILER)
+endif()
+
+
+# Code coverage compilation flags
+if(VORPALINE_WITH_GCOV)
+    message(STATUS "Building for coverage analysis")
+    add_flags(CMAKE_CXX_FLAGS --coverage)
+    add_flags(CMAKE_C_FLAGS --coverage)
+endif()
+
+
+# Compilation flags for Google's AddressSanitizer
+# These flags can only be specified for dynamic builds
+if(VORPALINE_WITH_ASAN)
+    if(VORPALINE_BUILD_DYNAMIC)
+        message(STATUS "Building with AddressSanitizer (debug only)")
+        add_flags(CMAKE_CXX_FLAGS_DEBUG -fsanitize=address -fno-omit-frame-pointer)
+        add_flags(CMAKE_C_FLAGS_DEBUG -fsanitize=address -fno-omit-frame-pointer)
+    else()
+        message(WARNING "AddressSanitizer can be used with dynamic builds only")
+        set(VORPALINE_WITH_ASAN false)
+    endif()
+endif()
+if(NOT VORPALINE_WITH_ASAN)
+    # Use native GCC stack smash Protection and buffer overflow detection (debug only)
+    add_flags(CMAKE_CXX_FLAGS_DEBUG -fstack-protector-all)
+    add_flags(CMAKE_C_FLAGS_DEBUG -fstack-protector-all)
+endif()
+
+
+# Compilation flags for Google's ThreadSanitizer
+# Does not work for the moment: cannot figure out how to link with library libtsan
+if(VORPALINE_WITH_TSAN)
+    message(STATUS "Building with ThreadSanitizer (debug only)")
+    message(FATAL_ERROR "ThreadSanitizer is not available: cannot figure out how to link with library libtsan")
+    add_flags(CMAKE_CXX_FLAGS_DEBUG -fsanitize=thread)
+    add_flags(CMAKE_C_FLAGS_DEBUG -fsanitize=thread)
+    if(NOT VORPALINE_BUILD_DYNAMIC)
+        add_flags(CMAKE_EXE_LINKER_FLAGS -static-libtsan)
+    endif()
+endif()
+
+
+# Reset the warning level for third parties
+function(vor_reset_warning_level)
+    remove_definitions(${FULL_WARNINGS})
+    add_definitions(${NORMAL_WARNINGS})
+endfunction()
+
+macro(vor_add_executable)
+    if(NOT VORPALINE_BUILD_DYNAMIC)
+        # Create a statically linked executable
+        # Link with static libraries
+        add_flags(CMAKE_CXX_FLAGS -static)
+        add_flags(CMAKE_C_FLAGS -static)
+    endif()
+
+    add_executable(${ARGN})
+
+    if(NOT VORPALINE_BUILD_DYNAMIC AND DEFINED VORPALINE_WITH_DDT)
+        # Static builds running with Allinea's DDT must be linked with a
+        # special malloc library which replaces the malloc primitives of
+        # the Glibc (We must allow multiple definitions)
+        add_flags(CMAKE_EXE_LINKER_FLAGS -Wl,--allow-multiple-definition)
+
+        if(VORPALINE_ARCH_64)
+            link_directories(${VORPALINE_WITH_DDT}/lib/64)
+        else()
+            link_directories(${VORPALINE_WITH_DDT}/lib/32)
+        endif()
+        target_link_libraries(${ARGV0} dmallocthcxx)
+    endif()
+
+    if(UNIX)
+        target_link_libraries(${ARGV0} m pthread)
+    endif()
+
+endmacro()
+