cmake: Move check_and_add_flag to a separate file

Also make it add flags to both C and C++ when appropriate
This commit is contained in:
Florent Castelli 2017-01-25 01:48:16 +01:00
parent eed64bb0fe
commit 08b73b8a77
2 changed files with 21 additions and 8 deletions

View File

@ -72,7 +72,13 @@ endif()
# TODO: Add DSPSpy
option(DSPTOOL "Build dsptool" OFF)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/CMakeTests)
list(APPEND CMAKE_MODULE_PATH
${CMAKE_SOURCE_DIR}/CMakeTests
)
# Support functions
include(CheckAndAddFlag)
# Libraries to link
set(LIBS)
@ -198,13 +204,6 @@ else()
message(FATAL_ERROR "You're building on an unsupported platform. Enable generic build if you really want a JIT-less binary.")
endif()
include(CheckCXXCompilerFlag)
macro(check_and_add_flag var flag)
CHECK_CXX_COMPILER_FLAG(${flag} FLAG_${var})
if(FLAG_${var})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
endif()
endmacro()
# Enforce minimum GCC version
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)

View File

@ -0,0 +1,14 @@
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
macro(check_and_add_flag var flag)
check_c_compiler_flag(${flag} FLAG_C_${var})
if(FLAG_C_${var})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}")
endif()
check_cxx_compiler_flag(${flag} FLAG_CXX_${var})
if(FLAG_CXX_${var})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
endif()
endmacro()