Skip to content

Instantly share code, notes, and snippets.

@autosquid
Created December 22, 2015 19:00
Show Gist options
  • Save autosquid/cebad7e33e54fb5cde1d to your computer and use it in GitHub Desktop.
Save autosquid/cebad7e33e54fb5cde1d to your computer and use it in GitHub Desktop.
cmake get_gcc_compile_flags
macro(get_gcc_compile_flags target flags)
string(TOUPPER "CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}" name)
set(flags "${${name}} ${CMAKE_CXX_COMPILER_ARG1}")
get_target_property(value ${target} COMPILE_FLAGS)
if (value)
list(APPEND flags ${value})
endif()
get_target_property(value ${target} TYPE)
get_target_property(value ${target} COMPILE_DEFINITIONS)
if (value)
foreach(item ${value})
list(APPEND flags "-D${item}")
endforeach()
endif()
STRING(TOUPPER "COMPILE_DEFINITIONS_${CMAKE_BUILD_TYPE}" name)
get_target_property(value ${target} ${name})
if (value)
foreach(item ${value})
list(APPEND flags "-D${item}")
endforeach()
endif()
get_directory_property(value COMPILE_DEFINITIONS)
if (value)
set( value_list ${value} )
separate_arguments(value_list)
foreach (item ${value_list})
list(APPEND flags ${item})
endforeach()
endif()
get_directory_property(value INCLUDE_DIRECTORIES)
if (value)
foreach(item ${value})
list(APPEND flags "-I${item}")
endforeach()
endif()
#separate_arguments(flags)
endmacro()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment