From a9cc014094eb08c25a248498280a1ee426a1aae9 Mon Sep 17 00:00:00 2001 From: Ryan Burns Date: Tue, 17 Nov 2020 12:25:08 -0800 Subject: [PATCH] Enable -fno-common by default to catch ODR violations This should prevent ODR-violating code in the future --- .cmake/isce2_buildflags.cmake | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.cmake/isce2_buildflags.cmake b/.cmake/isce2_buildflags.cmake index 5570353..255a56a 100644 --- a/.cmake/isce2_buildflags.cmake +++ b/.cmake/isce2_buildflags.cmake @@ -31,3 +31,19 @@ list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES ${abs_libdir} isSystemDir) if("${isSystemDir}" STREQUAL "-1") list(APPEND CMAKE_INSTALL_RPATH ${abs_libdir}) endif() + +option(ISCE2_STRICT_COMPILATION "Enable strict checks during compilation" ON) +if(ISCE2_STRICT_COMPILATION) + + # Set -fno-common when supported to catch ODR violations + include(CheckCCompilerFlag) + check_c_compiler_flag(-fno-common C_FNO_COMMON) + if(C_FNO_COMMON) + add_compile_options($<$:-fno-common>) + endif() + include(CheckCXXCompilerFlag) + check_cxx_compiler_flag(-fno-common CXX_FNO_COMMON) + if(CXX_FNO_COMMON) + add_compile_options($<$:-fno-common>) + endif() +endif()