Files
neovim/test/includes/CMakeLists.txt
dundargoc 438b4361cc build: use modern cmake (#21589)
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.
2023-01-10 18:49:57 +01:00

32 lines
1.1 KiB
CMake

file(GLOB_RECURSE PRE_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} pre/*.h)
# We need to add the SDK directories on OS X, and perhaps other operating
# systems.
set(gen_cflags)
foreach(gen_include ${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES})
list(APPEND gen_cflags ${CMAKE_INCLUDE_FLAG_C}${gen_include})
endforeach()
get_directory_property(gen_cdefs COMPILE_DEFINITIONS)
foreach(gen_cdef ${gen_cdefs})
if(NOT ${gen_cdef} MATCHES "INCLUDE_GENERATED_DECLARATIONS")
list(APPEND gen_cflags "-D${gen_cdef}")
endif()
endforeach()
foreach(hfile ${PRE_HEADERS})
string(REGEX REPLACE ^pre/ post/ post_hfile ${hfile})
get_filename_component(hdir ${CMAKE_CURRENT_BINARY_DIR}/${post_hfile} DIRECTORY)
file(MAKE_DIRECTORY ${hdir})
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${post_hfile}
COMMAND ${CMAKE_C_COMPILER} -std=c99 -E -P
${CMAKE_CURRENT_SOURCE_DIR}/${hfile}
${gen_cflags}
-o ${CMAKE_CURRENT_BINARY_DIR}/${post_hfile})
list(APPEND POST_HEADERS ${post_hfile})
endforeach()
add_custom_target(unittest-headers DEPENDS ${POST_HEADERS})
set_target_properties(unittest-headers PROPERTIES FOLDER test)