From be429079b547fa235cd0bbb696a7b73368606291 Mon Sep 17 00:00:00 2001 From: Baruch Sterin Date: Thu, 5 Nov 2015 01:23:31 -0800 Subject: [PATCH] CMakeLists.txt: pass CXX flags from the Makefile --- CMakeLists.txt | 18 +++++++++++++----- Makefile | 1 + 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 08f771e35..5034e5a02 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,17 +1,23 @@ -cmake_minimum_required(VERSION 2.8.12) +cmake_minimum_required(VERSION 3.3.0) include(CMakeParseArguments) include(CheckCCompilerFlag) +include(CheckCXXCompilerFlag) -# filter out flags that are not appropriate for the compiler used +# filter out flags that are not appropriate for the compiler being used function(target_compile_options_filtered target visibility) foreach( flag ${ARGN} ) if( flag MATCHES "^-D.*" ) target_compile_options( ${target} ${visibility} ${flag} ) else() - check_c_compiler_flag( ${flag} COMPILER_SUPPORTS__${flag} ) - if( COMPILER_SUPPORTS__${flag} ) - target_compile_options( ${target} ${visibility} ${flag} ) + check_c_compiler_flag( ${flag} C_COMPILER_SUPPORTS__${flag} ) + if( C_COMPILER_SUPPORTS__${flag} ) + target_compile_options( ${target} ${visibility} $<$:${flag}> ) + endif() + + check_cxx_compiler_flag( ${flag} CXX_COMPILER_SUPPORTS__${flag} ) + if( CXX_COMPILER_SUPPORTS__${flag} ) + target_compile_options( ${target} ${visibility} $<$:${flag}> ) endif() endif() endforeach() @@ -40,6 +46,8 @@ endfunction() extract_var(SEPARATOR_SRC ABC_SRC ${MAKE_OUTPUT}) extract_var(SEPARATOR_LIBS ABC_LIBS ${MAKE_OUTPUT}) extract_var(SEPARATOR_CFLAGS ABC_CFLAGS ${MAKE_OUTPUT}) +extract_var(SEPARATOR_CXXFLAGS ABC_CXXFLAGS ${MAKE_OUTPUT}) + add_executable(abc ${ABC_SRC}) diff --git a/Makefile b/Makefile index e33eb3eb6..769b34993 100644 --- a/Makefile +++ b/Makefile @@ -193,5 +193,6 @@ docs: cmake_info: @echo SEPARATOR_CFLAGS $(CFLAGS) SEPARATOR_CFLAGS + @echo SEPARATOR_CXXFLAGS $(CXXFLAGS) SEPARATOR_CXXFLAGS @echo SEPARATOR_LIBS $(LIBS) SEPARATOR_LIBS @echo SEPARATOR_SRC $(SRC) SEPARATOR_SRC