CMake: set -fno-strict-aliasing only if the compiler supports it

This commit is contained in:
Rolf Eike Beer 2017-08-02 13:13:53 +02:00 committed by Rolf Eike Beer
parent 65fb9a0406
commit 45a9b99af9
2 changed files with 7 additions and 1 deletions

View file

@ -39,7 +39,10 @@ endif(BUILD_tests)
include(${CMAKE_CURRENT_LIST_DIR}/ConfigureChecks.cmake)
set(EXTRA_LINK_AND_COMPILE_FLAGS "-fno-strict-aliasing")
set(EXTRA_LINK_AND_COMPILE_FLAGS)
if(FLAG_NO_STRICT_ALIASING)
set(EXTRA_LINK_AND_COMPILE_FLAGS "${EXTRA_LINK_AND_COMPILE_FLAGS} -fno-strict-aliasing")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_LINK_AND_COMPILE_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_LINK_AND_COMPILE_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${EXTRA_LINK_AND_COMPILE_FLAGS}")

View file

@ -1,3 +1,4 @@
include(CheckCCompilerFlag)
include(CheckIncludeFile)
include(CheckIncludeFiles)
include(CheckFunctionExists)
@ -42,3 +43,5 @@ endif(HAVE_SYS_TYPES_H)
configure_file(expat_config.h.cmake "${CMAKE_CURRENT_BINARY_DIR}/expat_config.h")
add_definitions(-DHAVE_EXPAT_CONFIG_H)
check_c_compiler_flag("-fno-strict-aliasing" FLAG_NO_STRICT_ALIASING)