Commit 0f64f3b7 by Baruch Sterin

CMake: only add compiler flags that are actually compatible with the compiler…

CMake: only add compiler flags that are actually compatible with the compiler being used - the compiler detection logic in the Makefile is not perfect and that sometime results in weird conflicts
parent 9322493e
cmake_minimum_required(VERSION 2.8.12)
include(CMakeParseArguments)
include(CheckCCompilerFlag)
# filter out flags that are not appropriate for the compiler 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} )
endif()
endif()
endforeach()
endfunction()
project(abc)
# run make to extract compiler options, linker options and list of source files
execute_process(
COMMAND make ABC_MAKE_NO_DEPS=1 cmake_info
COMMAND make ABC_MAKE_NO_DEPS=1 CC=${CMAKE_C_COMPILER} CXX=${CMAKE_CXX_COMPILER} LD=${CMAKE_CXX_COMPILER} cmake_info
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE MAKE_OUTPUT
)
......@@ -26,5 +44,5 @@ extract_var(SEPARATOR_CFLAGS ABC_CFLAGS ${MAKE_OUTPUT})
add_executable(abc ${ABC_SRC})
target_include_directories(abc PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src )
target_compile_options(abc PRIVATE ${ABC_CFLAGS} )
target_compile_options_filtered(abc PRIVATE ${ABC_CFLAGS} -Wno-unused-but-set-variable )
target_link_libraries(abc PRIVATE ${ABC_LIBS})
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