Commit 36d43737 authored by François Grisez's avatar François Grisez

Add a CMake macro for generating default compilation flags

parent dde5dce8
......@@ -145,40 +145,11 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/config.h PROPERTIES GENERATED ON)
add_definitions("-DHAVE_CONFIG_H")
set(STRICT_OPTIONS_CPP )
set(STRICT_OPTIONS_C )
bc_init_compilation_flags(STRICT_OPTIONS_CPP STRICT_OPTIONS_C STRICT_OPTIONS_CXX ENABLE_STRICT)
if(CMAKE_VERSION VERSION_LESS 3.1 AND NOT APPLE AND NOT MSVC)
set(STRICT_OPTIONS_CXX "-std=c++11")
else()
set(STRICT_OPTIONS_CXX )
endif()
if(MSVC)
if(ENABLE_STRICT)
list(APPEND STRICT_OPTIONS_CPP "/WX")
endif()
else()
list(APPEND STRICT_OPTIONS_CPP "-Wall" "-Wuninitialized")
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
list(APPEND STRICT_OPTIONS_CPP "-Wno-error=unknown-warning-option" "-Qunused-arguments" "-Wno-tautological-compare" "-Wno-builtin-requires-header" "-Wno-unused-function" "-Wno-gnu-designator" "-Wno-array-bounds")
elseif(CMAKE_C_COMPILER_ID STREQUAL "GNU")
list(APPEND STRICT_OPTIONS_CPP "-Wno-error=pragmas")
endif()
if(APPLE)
list(APPEND STRICT_OPTIONS_CPP "-Wno-error=unknown-warning-option" "-Qunused-arguments" "-Wno-tautological-compare" "-Wno-unused-function" "-Wno-array-bounds")
endif()
if(ENABLE_STRICT)
list(APPEND STRICT_OPTIONS_CPP "-Werror" "-Wextra" "-Wno-unused-parameter" "-Wno-error=unknown-pragmas" "-Wuninitialized" "-Wno-missing-field-initializers" "-fno-strict-aliasing")
list(APPEND STRICT_OPTIONS_C "-Werror" "-Wdeclaration-after-statement" "-Wstrict-prototypes")
endif()
endif()
if(STRICT_OPTIONS_CPP)
list(REMOVE_DUPLICATES STRICT_OPTIONS_CPP)
string(REPLACE ";" " " STRICT_OPTIONS_CPP "${STRICT_OPTIONS_CPP}")
endif()
if(STRICT_OPTIONS_C)
list(REMOVE_DUPLICATES STRICT_OPTIONS_C)
string(REPLACE ";" " " STRICT_OPTIONS_C "${STRICT_OPTIONS_C}")
list(APPEND STRICT_OPTIONS_CXX "-std=c++11")
endif()
set(LINK_FLAGS )
if(APPLE)
list(APPEND LINK_FLAGS "-framework Foundation")
......
......@@ -22,6 +22,33 @@
set(BCTOOLBOX_CMAKE_UTILS_DIR "${CMAKE_CURRENT_LIST_DIR}")
macro(bc_init_compilation_flags CPP_FLAGS C_FLAGS CXX_FLAGS STRICT_COMPILATION)
set(${CPP_FLAGS} )
set(${C_FLAGS} )
set(${CXX_FLAGS} )
if(MSVC)
if(${STRICT_COMPILATION})
list(APPEND ${CPP_FLAGS} "/WX")
list(APPEND STRICT_OPTIONS_CPP "/wd4996") # Disable deprecated function warnings
endif()
else()
list(APPEND ${CPP_FLAGS} "-Wall" "-Wuninitialized")
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
list(APPEND ${CPP_FLAGS} "-Wno-error=unknown-warning-option" "-Qunused-arguments" "-Wno-tautological-compare" "-Wno-builtin-requires-header" "-Wno-unused-function" "-Wno-gnu-designator" "-Wno-array-bounds")
elseif(CMAKE_C_COMPILER_ID STREQUAL "GNU")
list(APPEND ${CPP_FLAGS} "-Wno-error=pragmas")
endif()
if(APPLE)
list(APPEND ${CPP_FLAGS} "-Wno-error=unknown-warning-option" "-Qunused-arguments" "-Wno-tautological-compare" "-Wno-unused-function" "-Wno-array-bounds")
endif()
if(ENABLE_STRICT)
list(APPEND ${CPP_FLAGS} "-Werror" "-Wextra" "-Wno-unused-parameter" "-Wno-error=unknown-pragmas" "-Wuninitialized" "-Wno-missing-field-initializers"
"-fno-strict-aliasing" "-Wno-error=deprecated" "-Wno-error=deprecated-declarations")
list(APPEND ${C_FLAGS} "-Werror" "-Wdeclaration-after-statement" "-Wstrict-prototypes")
endif()
endif()
endmacro()
macro(bc_apply_compile_flags SOURCE_FILES)
if(${SOURCE_FILES})
set(options "")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment