2014-11-09 05:52:15 -07:00
|
|
|
function(get_compile_flags _compile_flags)
|
|
|
|
# Create template akin to CMAKE_C_COMPILE_OBJECT.
|
2019-07-07 04:01:38 -07:00
|
|
|
set(compile_flags "<CMAKE_C_COMPILER> <CFLAGS> <BUILD_TYPE_CFLAGS> <COMPILE_OPTIONS><COMPILE_DEFINITIONS> <INCLUDES>")
|
2014-11-09 05:52:15 -07:00
|
|
|
|
|
|
|
# Get C compiler.
|
2019-09-24 15:09:23 -07:00
|
|
|
if(CMAKE_C_COMPILER_ARG1)
|
|
|
|
string(REPLACE
|
|
|
|
"<CMAKE_C_COMPILER>"
|
|
|
|
"<CMAKE_C_COMPILER> ${CMAKE_C_COMPILER_ARG1}"
|
|
|
|
compile_flags
|
|
|
|
"${compile_flags}")
|
|
|
|
endif()
|
2014-11-09 05:52:15 -07:00
|
|
|
string(REPLACE
|
|
|
|
"<CMAKE_C_COMPILER>"
|
|
|
|
"${CMAKE_C_COMPILER}"
|
|
|
|
compile_flags
|
|
|
|
"${compile_flags}")
|
|
|
|
|
2019-06-29 11:37:48 -07:00
|
|
|
# Get flags set by add_definitions().
|
2019-09-06 11:36:05 -07:00
|
|
|
get_property(compile_definitions DIRECTORY PROPERTY COMPILE_DEFINITIONS)
|
2019-08-14 18:00:45 -07:00
|
|
|
get_target_property(compile_definitions_target nvim COMPILE_DEFINITIONS)
|
|
|
|
if(compile_definitions_target)
|
|
|
|
list(APPEND compile_definitions ${compile_definitions_target})
|
|
|
|
list(REMOVE_DUPLICATES compile_definitions)
|
|
|
|
endif()
|
2019-07-07 04:01:38 -07:00
|
|
|
# NOTE: list(JOIN) requires CMake 3.12, string(CONCAT) requires CMake 3.
|
2019-06-29 11:37:48 -07:00
|
|
|
string(REPLACE ";" " -D" compile_definitions "${compile_definitions}")
|
2019-07-07 04:01:38 -07:00
|
|
|
if(compile_definitions)
|
|
|
|
set(compile_definitions " -D${compile_definitions}")
|
|
|
|
endif()
|
2014-11-09 05:52:15 -07:00
|
|
|
string(REPLACE
|
2019-06-29 11:37:48 -07:00
|
|
|
"<COMPILE_DEFINITIONS>"
|
|
|
|
"${compile_definitions}"
|
|
|
|
compile_flags
|
|
|
|
"${compile_flags}")
|
|
|
|
|
|
|
|
# Get flags set by add_compile_options().
|
2019-09-06 11:36:05 -07:00
|
|
|
get_property(compile_options DIRECTORY PROPERTY COMPILE_OPTIONS)
|
2019-08-14 18:00:45 -07:00
|
|
|
get_target_property(compile_options_target nvim COMPILE_OPTIONS)
|
|
|
|
if(compile_options_target)
|
|
|
|
list(APPEND compile_options ${compile_options_target})
|
|
|
|
list(REMOVE_DUPLICATES compile_options)
|
|
|
|
endif()
|
2019-06-29 11:37:48 -07:00
|
|
|
# NOTE: list(JOIN) requires CMake 3.12.
|
|
|
|
string(REPLACE ";" " " compile_options "${compile_options}")
|
|
|
|
string(REPLACE
|
|
|
|
"<COMPILE_OPTIONS>"
|
|
|
|
"${compile_options}"
|
2014-11-09 05:52:15 -07:00
|
|
|
compile_flags
|
|
|
|
"${compile_flags}")
|
|
|
|
|
|
|
|
# Get general C flags.
|
|
|
|
string(REPLACE
|
|
|
|
"<CFLAGS>"
|
|
|
|
"${CMAKE_C_FLAGS}"
|
|
|
|
compile_flags
|
|
|
|
"${compile_flags}")
|
|
|
|
|
|
|
|
# Get C flags specific to build type.
|
|
|
|
string(TOUPPER "${CMAKE_BUILD_TYPE}" build_type)
|
|
|
|
string(REPLACE
|
|
|
|
"<BUILD_TYPE_CFLAGS>"
|
|
|
|
"${CMAKE_C_FLAGS_${build_type}}"
|
|
|
|
compile_flags
|
|
|
|
"${compile_flags}")
|
|
|
|
|
|
|
|
# Get include directories.
|
2019-09-06 11:36:05 -07:00
|
|
|
get_property(include_directories_list DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
|
2018-02-13 23:57:38 -07:00
|
|
|
list(REMOVE_DUPLICATES include_directories_list)
|
2014-11-09 05:52:15 -07:00
|
|
|
foreach(include_directory ${include_directories_list})
|
|
|
|
set(include_directories "${include_directories} -I${include_directory}")
|
|
|
|
endforeach()
|
|
|
|
string(REPLACE
|
|
|
|
"<INCLUDES>"
|
|
|
|
"${include_directories}"
|
|
|
|
compile_flags
|
|
|
|
"${compile_flags}")
|
|
|
|
|
|
|
|
# Clean duplicate whitespace.
|
|
|
|
string(REPLACE
|
|
|
|
" "
|
|
|
|
" "
|
|
|
|
compile_flags
|
|
|
|
"${compile_flags}")
|
|
|
|
|
|
|
|
set(${_compile_flags} "${compile_flags}" PARENT_SCOPE)
|
|
|
|
endfunction()
|