From 08b73b8a770c66cafa4978f205f6db6cd4bf3e39 Mon Sep 17 00:00:00 2001 From: Florent Castelli Date: Wed, 25 Jan 2017 01:48:16 +0100 Subject: [PATCH] cmake: Move check_and_add_flag to a separate file Also make it add flags to both C and C++ when appropriate --- CMakeLists.txt | 15 +++++++-------- CMakeTests/CheckAndAddFlag.cmake | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 CMakeTests/CheckAndAddFlag.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index b55c77e304..d9fea02207 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/CMakeTests/CheckAndAddFlag.cmake b/CMakeTests/CheckAndAddFlag.cmake new file mode 100644 index 0000000000..34ab8e60b1 --- /dev/null +++ b/CMakeTests/CheckAndAddFlag.cmake @@ -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()