mirror of
https://github.com/neovim/neovim.git
synced 2024-12-20 03:05:11 -07:00
438b4361cc
Replace old-school cmake with the so-called "Modern CMake", meaning preferring using targets and properties over directory settings and variables. This allows greater flexibility, robustness and clarity over how the code works. The following deprecated commands will be replaced with their modern alternatives that operates on a specific target, rather than all targets in the current directory: - add_compile_options -> target_compile_options - include_directories -> target_include_directories - link_libraries -> target_link_libraries - add_definitions -> target_compile_definitions There are mainly four main targets that we currently use: nvim, libnvim, nvim-test (used by unittests) and ${texe} (used by check-single-includes). The goal is to explicitly define the dependencies of each target fully, rather than having everything be dependent on everything else.
58 lines
1.5 KiB
CMake
58 lines
1.5 KiB
CMake
function(get_compile_flags _compile_flags)
|
|
string(TOUPPER "${CMAKE_BUILD_TYPE}" build_type)
|
|
set(compile_flags ${CMAKE_C_COMPILER} ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${build_type}})
|
|
|
|
# Get flags set by target_compile_options().
|
|
get_target_property(opt main_lib INTERFACE_COMPILE_OPTIONS)
|
|
if(opt)
|
|
list(APPEND compile_flags ${opt})
|
|
endif()
|
|
|
|
get_target_property(opt nvim COMPILE_OPTIONS)
|
|
if(opt)
|
|
list(APPEND compile_flags ${opt})
|
|
endif()
|
|
|
|
# Get flags set by target_compile_definitions().
|
|
get_target_property(defs main_lib INTERFACE_COMPILE_DEFINITIONS)
|
|
if(defs)
|
|
foreach(def ${defs})
|
|
list(APPEND compile_flags "-D${def}")
|
|
endforeach()
|
|
endif()
|
|
|
|
get_target_property(defs nvim COMPILE_DEFINITIONS)
|
|
if(defs)
|
|
foreach(def ${defs})
|
|
list(APPEND compile_flags "-D${def}")
|
|
endforeach()
|
|
endif()
|
|
|
|
# Get include directories.
|
|
get_target_property(dirs main_lib INTERFACE_INCLUDE_DIRECTORIES)
|
|
if(dirs)
|
|
foreach(dir ${dirs})
|
|
list(APPEND compile_flags "-I${dir}")
|
|
endforeach()
|
|
endif()
|
|
|
|
get_target_property(dirs main_lib INTERFACE_SYSTEM_INCLUDE_DIRECTORIES)
|
|
if(dirs)
|
|
foreach(dir ${dirs})
|
|
list(APPEND compile_flags "-I${dir}")
|
|
endforeach()
|
|
endif()
|
|
|
|
get_target_property(dirs nvim INCLUDE_DIRECTORIES)
|
|
if(dirs)
|
|
foreach(dir ${dirs})
|
|
list(APPEND compile_flags "-I${dir}")
|
|
endforeach()
|
|
endif()
|
|
|
|
list(REMOVE_DUPLICATES compile_flags)
|
|
string(REPLACE ";" " " compile_flags "${compile_flags}")
|
|
|
|
set(${_compile_flags} "${compile_flags}" PARENT_SCOPE)
|
|
endfunction()
|