diff options
-rw-r--r-- | CMakeLists.txt | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index e84c376a..08f771e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,27 @@ 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}) |