diff options
author | Baruch Sterin <baruchs@gmail.com> | 2015-10-23 14:44:17 -0700 |
---|---|---|
committer | Baruch Sterin <baruchs@gmail.com> | 2015-10-23 14:44:17 -0700 |
commit | 0f64f3b7abbc2c0e3ea94c27cface77254127234 (patch) | |
tree | 18a28f43f71c4f18785ee0cff3e7924d12f89bac | |
parent | 9322493e9070d2af2d079698ef9c2320e35a862c (diff) | |
download | abc-0f64f3b7abbc2c0e3ea94c27cface77254127234.tar.gz abc-0f64f3b7abbc2c0e3ea94c27cface77254127234.tar.bz2 abc-0f64f3b7abbc2c0e3ea94c27cface77254127234.zip |
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
-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}) |