|
| 1 | + |
| 2 | +SET(GEOGRAM_WITH_GRAPHICS OFF) |
| 3 | + |
| 4 | +#------------------------------------------------------------------- |
| 5 | +# Flags common to all Linux based platforms with GNU compiler |
| 6 | +#------------------------------------------------------------------- |
| 7 | + |
| 8 | +include(${GEOGRAM_SOURCE_DIR}/cmake/platforms/Linux.cmake) |
| 9 | + |
| 10 | +# Warning flags |
| 11 | +set(NORMAL_WARNINGS -Wall -Wextra) |
| 12 | +set(FULL_WARNINGS |
| 13 | + ${NORMAL_WARNINGS} |
| 14 | + -pedantic |
| 15 | + -Wno-long-long |
| 16 | + -Wconversion |
| 17 | +) |
| 18 | + |
| 19 | +# Determine gcc version and activate additional warnings available in latest versions |
| 20 | +execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION) |
| 21 | + |
| 22 | +if (GCC_VERSION VERSION_GREATER 4.3 OR GCC_VERSION VERSION_EQUAL 4.3) |
| 23 | + set(FULL_WARNINGS ${FULL_WARNINGS} -Wsign-conversion) |
| 24 | +endif() |
| 25 | + |
| 26 | +if (GCC_VERSION VERSION_GREATER 4.6 OR GCC_VERSION VERSION_EQUAL 4.6) |
| 27 | + set(FULL_WARNINGS ${FULL_WARNINGS} -Wdouble-promotion) |
| 28 | +endif() |
| 29 | + |
| 30 | + |
| 31 | +# Compile with full warnings by default |
| 32 | +add_definitions(${FULL_WARNINGS}) |
| 33 | + |
| 34 | +# Warn about missing virtual destructor (C++ only) |
| 35 | +add_flags(CMAKE_CXX_FLAGS -Wnon-virtual-dtor) |
| 36 | + |
| 37 | +# Add static and dynamic bounds checks (optimization required) |
| 38 | +if (GCC_VERSION VERSION_GREATER 4.0) |
| 39 | + add_flags(CMAKE_CXX_FLAGS_RELEASE -D_FORTIFY_SOURCE=2) |
| 40 | + add_flags(CMAKE_C_FLAGS_RELEASE -D_FORTIFY_SOURCE=2) |
| 41 | +endif() |
| 42 | + |
| 43 | +# Enable setting FPU rounding mode (needed by FPG) and |
| 44 | +# disable automatic generation of FMAs (would break exact |
| 45 | +# predicates) |
| 46 | +add_flags(CMAKE_CXX_FLAGS -frounding-math -ffp-contract=off) |
| 47 | +add_flags(CMAKE_C_FLAGS -frounding-math -ffp-contract=off) |
| 48 | + |
| 49 | +# Activate AVX2 instruction set |
| 50 | +#add_flags(CMAKE_CXX_FLAGS -mavx2) |
| 51 | +#add_flags(CMAKE_C_FLAGS -mavx2) |
| 52 | + |
| 53 | +# Activate c++ 2011 |
| 54 | +add_flags(CMAKE_CXX_FLAGS -std=c++11) |
| 55 | + |
| 56 | +# Enable glibc parallel mode |
| 57 | +#add_flags(CMAKE_CXX_FLAGS -D_GLIBCXX_PARALLEL) |
| 58 | + |
| 59 | +# Generate debug information even in release mode |
| 60 | +#add_flags(CMAKE_CXX_FLAGS_RELEASE -g) |
| 61 | +#add_flags(CMAKE_C_FLAGS_RELEASE -g) |
| 62 | + |
| 63 | +# Additional debug flags |
| 64 | +# deactivated for now: I added bound checking in VOR::vector<>. |
| 65 | +#add_flags(CMAKE_CXX_FLAGS_DEBUG -D_GLIBCXX_DEBUG) |
| 66 | + |
| 67 | + |
| 68 | +# Compile and link with OpenMP |
| 69 | +if (GCC_VERSION VERSION_GREATER 4.0) |
| 70 | + add_flags(CMAKE_CXX_FLAGS -fopenmp) |
| 71 | + add_flags(CMAKE_C_FLAGS -fopenmp) |
| 72 | +endif() |
| 73 | + |
| 74 | +# Alaways generate position independant code |
| 75 | +# (to allow linking geogram/vorlalib with DLLs) |
| 76 | +add_flags(CMAKE_CXX_FLAGS -fPIC) |
| 77 | +add_flags(CMAKE_C_FLAGS -fPIC) |
| 78 | + |
| 79 | +# Hide symbols that are not explicitly exported |
| 80 | +add_flags(CMAKE_CXX_FLAGS -fvisibility=hidden) |
| 81 | +add_flags(CMAKE_C_FLAGS -fvisibility=hidden) |
| 82 | + |
| 83 | +# Profiler compilation flags |
| 84 | +if(VORPALINE_WITH_GPROF) |
| 85 | + message(STATUS "Building for code profiling") |
| 86 | + add_flags(CMAKE_CXX_FLAGS -pg -DPROFILER) |
| 87 | + add_flags(CMAKE_C_FLAGS -pg -DPROFILER) |
| 88 | +endif() |
| 89 | + |
| 90 | + |
| 91 | +# Code coverage compilation flags |
| 92 | +if(VORPALINE_WITH_GCOV) |
| 93 | + message(STATUS "Building for coverage analysis") |
| 94 | + add_flags(CMAKE_CXX_FLAGS --coverage) |
| 95 | + add_flags(CMAKE_C_FLAGS --coverage) |
| 96 | +endif() |
| 97 | + |
| 98 | + |
| 99 | +# Compilation flags for Google's AddressSanitizer |
| 100 | +# These flags can only be specified for dynamic builds |
| 101 | +if(VORPALINE_WITH_ASAN) |
| 102 | + if(VORPALINE_BUILD_DYNAMIC) |
| 103 | + message(STATUS "Building with AddressSanitizer (debug only)") |
| 104 | + add_flags(CMAKE_CXX_FLAGS_DEBUG -fsanitize=address -fno-omit-frame-pointer) |
| 105 | + add_flags(CMAKE_C_FLAGS_DEBUG -fsanitize=address -fno-omit-frame-pointer) |
| 106 | + else() |
| 107 | + message(WARNING "AddressSanitizer can be used with dynamic builds only") |
| 108 | + set(VORPALINE_WITH_ASAN false) |
| 109 | + endif() |
| 110 | +endif() |
| 111 | +if(NOT VORPALINE_WITH_ASAN) |
| 112 | + # Use native GCC stack smash Protection and buffer overflow detection (debug only) |
| 113 | + add_flags(CMAKE_CXX_FLAGS_DEBUG -fstack-protector-all) |
| 114 | + add_flags(CMAKE_C_FLAGS_DEBUG -fstack-protector-all) |
| 115 | +endif() |
| 116 | + |
| 117 | + |
| 118 | +# Compilation flags for Google's ThreadSanitizer |
| 119 | +# Does not work for the moment: cannot figure out how to link with library libtsan |
| 120 | +if(VORPALINE_WITH_TSAN) |
| 121 | + message(STATUS "Building with ThreadSanitizer (debug only)") |
| 122 | + message(FATAL_ERROR "ThreadSanitizer is not available: cannot figure out how to link with library libtsan") |
| 123 | + add_flags(CMAKE_CXX_FLAGS_DEBUG -fsanitize=thread) |
| 124 | + add_flags(CMAKE_C_FLAGS_DEBUG -fsanitize=thread) |
| 125 | + if(NOT VORPALINE_BUILD_DYNAMIC) |
| 126 | + add_flags(CMAKE_EXE_LINKER_FLAGS -static-libtsan) |
| 127 | + endif() |
| 128 | +endif() |
| 129 | + |
| 130 | + |
| 131 | +# Reset the warning level for third parties |
| 132 | +function(vor_reset_warning_level) |
| 133 | + remove_definitions(${FULL_WARNINGS}) |
| 134 | + add_definitions(${NORMAL_WARNINGS}) |
| 135 | +endfunction() |
| 136 | + |
| 137 | +macro(vor_add_executable) |
| 138 | + if(NOT VORPALINE_BUILD_DYNAMIC) |
| 139 | + # Create a statically linked executable |
| 140 | + # Link with static libraries |
| 141 | + add_flags(CMAKE_CXX_FLAGS -static-libstdc++ -static-libgcc -static) |
| 142 | + add_flags(CMAKE_C_FLAGS -static-libgcc -static) |
| 143 | + endif() |
| 144 | + |
| 145 | + add_executable(${ARGN}) |
| 146 | + |
| 147 | + if(NOT VORPALINE_BUILD_DYNAMIC AND DEFINED VORPALINE_WITH_DDT) |
| 148 | + # Static builds running with Allinea's DDT must be linked with a |
| 149 | + # special malloc library which replaces the malloc primitives of |
| 150 | + # the Glibc (We must allow multiple definitions) |
| 151 | + add_flags(CMAKE_EXE_LINKER_FLAGS -Wl,--allow-multiple-definition) |
| 152 | + |
| 153 | + if(VORPALINE_ARCH_64) |
| 154 | + link_directories(${VORPALINE_WITH_DDT}/lib/64) |
| 155 | + else() |
| 156 | + link_directories(${VORPALINE_WITH_DDT}/lib/32) |
| 157 | + endif() |
| 158 | + target_link_libraries(${ARGV0} dmallocthcxx) |
| 159 | + endif() |
| 160 | + |
| 161 | + if(UNIX) |
| 162 | + target_link_libraries(${ARGV0} m pthread) |
| 163 | + endif() |
| 164 | +endmacro() |
| 165 | + |
0 commit comments