CMakeLists.txt 10.1 KB
Newer Older
1 2
include(CheckLibraryExists)

3 4
option(USE_GCOV "Enable gcov support" OFF)

5 6
if(NOT CLANG_TSAN)
# GCOV and TSAN results in false data race reports
7 8 9 10 11 12
if(USE_GCOV)
  message(STATUS "Enabling gcov support")
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage")
  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
  set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage")
endif()
13
endif()
14

15
set(GENERATED_DIR ${PROJECT_BINARY_DIR}/src/nvim/auto)
16
set(DISPATCH_GENERATOR ${PROJECT_SOURCE_DIR}/scripts/msgpack-gen.lua)
17
file(GLOB API_HEADERS api/*.h)
18
file(GLOB MSGPACK_RPC_HEADERS msgpack_rpc/*.h)
19
set(MSGPACK_DISPATCH ${GENERATED_DIR}/msgpack_dispatch.c)
20 21
set(HEADER_GENERATOR ${PROJECT_SOURCE_DIR}/scripts/gendeclarations.lua)
set(GENERATED_INCLUDES_DIR ${PROJECT_BINARY_DIR}/include)
22 23
set(GENERATED_EX_CMDS_ENUM ${GENERATED_INCLUDES_DIR}/ex_cmds_enum.generated.h)
set(GENERATED_EX_CMDS_DEFS ${GENERATED_DIR}/ex_cmds_defs.generated.h)
24 25
set(GENERATED_EVENTS_ENUM ${GENERATED_INCLUDES_DIR}/auevents_enum.generated.h)
set(GENERATED_EVENTS_NAMES_MAP ${GENERATED_DIR}/auevents_name_map.generated.h)
26
set(GENERATED_OPTIONS ${GENERATED_DIR}/options.generated.h)
27
set(EX_CMDS_GENERATOR ${PROJECT_SOURCE_DIR}/scripts/genex_cmds.lua)
28
set(EVENTS_GENERATOR ${PROJECT_SOURCE_DIR}/scripts/gen_events.lua)
29
set(OPTIONS_GENERATOR ${PROJECT_SOURCE_DIR}/scripts/genoptions.lua)
30
set(EVENTS_LIST_FILE ${PROJECT_SOURCE_DIR}/src/nvim/auevents.lua)
31
set(EX_CMDS_DEFS_FILE ${PROJECT_SOURCE_DIR}/src/nvim/ex_cmds.lua)
32
set(OPTIONS_LIST_FILE ${PROJECT_SOURCE_DIR}/src/nvim/options.lua)
33
set(UNICODE_TABLES_GENERATOR ${PROJECT_SOURCE_DIR}/scripts/genunicodetables.lua)
34 35 36 37
set(UNICODE_DIR ${PROJECT_SOURCE_DIR}/unicode)
set(UNICODEDATA_FILE ${UNICODE_DIR}/UnicodeData.txt)
set(CASEFOLDING_FILE ${UNICODE_DIR}/CaseFolding.txt)
set(EASTASIANWIDTH_FILE ${UNICODE_DIR}/EastAsianWidth.txt)
38
set(GENERATED_UNICODE_TABLES ${GENERATED_DIR}/unicode_tables.generated.h)
39

40 41
include_directories(${GENERATED_DIR})
include_directories(${GENERATED_INCLUDES_DIR})
42

43 44 45 46
file(MAKE_DIRECTORY ${GENERATED_DIR})
file(MAKE_DIRECTORY ${GENERATED_DIR}/os)
file(MAKE_DIRECTORY ${GENERATED_DIR}/api)
file(MAKE_DIRECTORY ${GENERATED_DIR}/api/private)
47
file(MAKE_DIRECTORY ${GENERATED_DIR}/msgpack_rpc)
48
file(MAKE_DIRECTORY ${GENERATED_DIR}/tui)
49
file(MAKE_DIRECTORY ${GENERATED_DIR}/event)
50 51 52 53
file(MAKE_DIRECTORY ${GENERATED_INCLUDES_DIR})
file(MAKE_DIRECTORY ${GENERATED_INCLUDES_DIR}/os)
file(MAKE_DIRECTORY ${GENERATED_INCLUDES_DIR}/api)
file(MAKE_DIRECTORY ${GENERATED_INCLUDES_DIR}/api/private)
54
file(MAKE_DIRECTORY ${GENERATED_INCLUDES_DIR}/msgpack_rpc)
55
file(MAKE_DIRECTORY ${GENERATED_INCLUDES_DIR}/tui)
56
file(MAKE_DIRECTORY ${GENERATED_INCLUDES_DIR}/event)
57

58
file(GLOB NEOVIM_SOURCES *.c os/*.c api/*.c api/private/*.c msgpack_rpc/*.c
59
  tui/*.c event/*.c)
60
file(GLOB_RECURSE NEOVIM_HEADERS *.h)
61
file(GLOB UNIT_TEST_FIXTURES ${PROJECT_SOURCE_DIR}/test/unit/fixtures/*.c)
62 63 64

foreach(sfile ${NEOVIM_SOURCES})
  get_filename_component(f ${sfile} NAME)
65
  if(${f} MATCHES "^(regexp_nfa.c)$")
66 67 68 69 70 71
    list(APPEND to_remove ${sfile})
  endif()
endforeach()

list(REMOVE_ITEM NEOVIM_SOURCES ${to_remove})

72
# Handle legacy files that don't yet pass -Wconversion.
73
set(CONV_SOURCES
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
  buffer.c
  charset.c
  diff.c
  edit.c
  eval.c
  ex_cmds2.c
  ex_cmds.c
  ex_docmd.c
  ex_getln.c
  fileio.c
  getchar.c
  mbyte.c
  memline.c
  message.c
  misc1.c
  ops.c
  path.c
  quickfix.c
  regexp.c
  screen.c
  search.c
  spell.c
  syntax.c
  tag.c
  window.c)
99

100 101
foreach(sfile ${CONV_SOURCES})
  if(NOT EXISTS "${PROJECT_SOURCE_DIR}/src/nvim/${sfile}")
102
    message(FATAL_ERROR "${sfile} doesn't exist (it was added to CONV_SOURCES)")
103 104 105
  endif()
endforeach()

106 107 108 109
if(NOT MSVC)
  set_source_files_properties(
    ${CONV_SOURCES} PROPERTIES COMPILE_FLAGS "${COMPILE_FLAGS} -Wno-conversion")
endif()
110

111 112 113 114
if(DEFINED MIN_LOG_LEVEL)
  add_definitions(-DMIN_LOG_LEVEL=${MIN_LOG_LEVEL})
endif()

115
get_directory_property(gen_cdefs COMPILE_DEFINITIONS)
116 117 118 119
foreach(gen_cdef ${gen_cdefs} DO_NOT_DEFINE_EMPTY_ATTRIBUTES)
  if(NOT "${gen_cdef}" MATCHES "INCLUDE_GENERATED_DECLARATIONS")
    list(APPEND gen_cflags "-D${gen_cdef}")
  endif()
120
endforeach()
121
if(CLANG_ASAN_UBSAN OR CLANG_MSAN OR CLANG_TSAN)
122 123
  list(APPEND gen_cflags "-DEXITFREE")
endif()
124 125 126

get_directory_property(gen_includes INCLUDE_DIRECTORIES)
foreach(gen_include ${gen_includes})
127
  list(APPEND gen_cflags "-I${gen_include}")
128
endforeach()
129
string(TOUPPER "${CMAKE_BUILD_TYPE}" build_type)
130 131 132
separate_arguments(C_FLAGS_ARRAY UNIX_COMMAND ${CMAKE_C_FLAGS})
separate_arguments(C_FLAGS_${build_type}_ARRAY UNIX_COMMAND ${CMAKE_C_FLAGS_${build_type}})
set(gen_cflags ${gen_cflags} ${C_FLAGS_${build_type}_ARRAY} ${C_FLAGS_ARRAY})
133 134

foreach(sfile ${NEOVIM_SOURCES}
135
              "${PROJECT_SOURCE_DIR}/src/nvim/regexp_nfa.c")
136 137 138 139 140 141 142 143 144 145
  get_filename_component(full_d ${sfile} PATH)
  file(RELATIVE_PATH d "${PROJECT_SOURCE_DIR}/src/nvim" "${full_d}")
  get_filename_component(f ${sfile} NAME)
  get_filename_component(r ${sfile} NAME_WE)
  if(NOT ${d} EQUAL ".")
    set(f "${d}/${f}")
    set(r "${d}/${r}")
  endif()
  set(gf1 "${GENERATED_DIR}/${r}.c.generated.h")
  set(gf2 "${GENERATED_INCLUDES_DIR}/${r}.h.generated.h")
146
  set(gf3 "${GENERATED_DIR}/${r}.i")
147 148 149 150 151 152 153

  if(MSVC)
    set(PREPROC_OUTPUT /P /Fi${gf3})
  else()
    set(PREPROC_OUTPUT -E -o ${gf3})
  endif()

154 155
  add_custom_command(
    OUTPUT "${gf1}" "${gf2}"
156
    COMMAND ${CMAKE_C_COMPILER} ${sfile} ${PREPROC_OUTPUT} ${gen_cflags} ${C_FLAGS_ARRAY}
157
    COMMAND "${LUA_PRG}" "${HEADER_GENERATOR}" "${sfile}" "${gf1}" "${gf2}" "${gf3}"
158 159 160 161 162 163 164 165 166
    DEPENDS "${HEADER_GENERATOR}" "${sfile}"
    )
  list(APPEND NEOVIM_GENERATED_SOURCES "${gf1}")
  list(APPEND NEOVIM_GENERATED_SOURCES "${gf2}")
  if(${d} MATCHES "^api$" AND NOT ${f} MATCHES "^api/helpers.c$")
    list(APPEND API_HEADERS ${gf2})
  endif()
endforeach()

167 168
add_custom_command(OUTPUT ${GENERATED_UNICODE_TABLES}
  COMMAND ${LUA_PRG} ${UNICODE_TABLES_GENERATOR}
169 170 171
                     ${UNICODEDATA_FILE}
                     ${CASEFOLDING_FILE}
                     ${EASTASIANWIDTH_FILE}
172 173 174
                     ${GENERATED_UNICODE_TABLES}
  DEPENDS
    ${UNICODE_TABLES_GENERATOR}
175 176 177
    ${UNICODEDATA_FILE}
    ${CASEFOLDING_FILE}
    ${EASTASIANWIDTH_FILE}
178 179
)

180 181 182 183
add_custom_command(OUTPUT ${MSGPACK_DISPATCH}
  COMMAND ${LUA_PRG} ${DISPATCH_GENERATOR} ${API_HEADERS} ${MSGPACK_DISPATCH}
  DEPENDS
    ${API_HEADERS}
184
    ${MSGPACK_RPC_HEADERS}
185
    ${DISPATCH_GENERATOR}
186
)
187

188 189
list(APPEND NEOVIM_GENERATED_SOURCES
  "${PROJECT_BINARY_DIR}/config/auto/pathdef.c"
190 191 192
  "${MSGPACK_DISPATCH}"
  "${GENERATED_EX_CMDS_ENUM}"
  "${GENERATED_EX_CMDS_DEFS}"
193 194
  "${GENERATED_EVENTS_ENUM}"
  "${GENERATED_EVENTS_NAMES_MAP}"
195
  "${GENERATED_OPTIONS}"
196
  "${GENERATED_UNICODE_TABLES}"
197 198 199 200 201 202 203
)

add_custom_command(OUTPUT ${GENERATED_EX_CMDS_ENUM} ${GENERATED_EX_CMDS_DEFS}
  COMMAND ${LUA_PRG} ${EX_CMDS_GENERATOR}
      ${PROJECT_SOURCE_DIR}/src/nvim ${GENERATED_INCLUDES_DIR} ${GENERATED_DIR}
  DEPENDS ${EX_CMDS_GENERATOR} ${EX_CMDS_DEFS_FILE}
)
204

205 206 207 208 209 210
add_custom_command(OUTPUT ${GENERATED_EVENTS_ENUM} ${GENERATED_EVENTS_NAMES_MAP}
  COMMAND ${LUA_PRG} ${EVENTS_GENERATOR}
      ${PROJECT_SOURCE_DIR}/src/nvim ${GENERATED_EVENTS_ENUM} ${GENERATED_EVENTS_NAMES_MAP}
  DEPENDS ${EVENTS_GENERATOR} ${EVENTS_LIST_FILE}
)

211 212 213 214 215 216
add_custom_command(OUTPUT ${GENERATED_OPTIONS}
  COMMAND ${LUA_PRG} ${OPTIONS_GENERATOR}
                     ${PROJECT_SOURCE_DIR}/src/nvim ${GENERATED_OPTIONS}
  DEPENDS ${OPTIONS_GENERATOR} ${OPTIONS_LIST_FILE}
)

217
# Our dependencies come first.
218

219 220 221 222
if (LibIntl_FOUND)
  list(APPEND NVIM_LINK_LIBRARIES ${LibIntl_LIBRARY})
endif()

223 224
if(Iconv_LIBRARIES)
  list(APPEND NVIM_LINK_LIBRARIES ${Iconv_LIBRARIES})
Nicolas Hillegeer's avatar
Nicolas Hillegeer committed
225 226
endif()

227 228
# Put these last on the link line, since multiple things may depend on them.
list(APPEND NVIM_LINK_LIBRARIES
229 230 231 232 233 234 235 236 237 238 239
  ${LIBUV_LIBRARIES}
  ${MSGPACK_LIBRARIES}
  ${LUAJIT_LIBRARIES}
  ${LIBVTERM_LIBRARIES}
  ${LIBTERMKEY_LIBRARIES}
  ${UNIBILIUM_LIBRARIES}
  ${CMAKE_THREAD_LIBS_INIT}
)

if(UNIX)
  list(APPEND NVIM_LINK_LIBRARIES
240
    m
241
    util
242 243
  )
endif()
244

245 246
set(NVIM_EXEC_LINK_LIBRARIES ${NVIM_LINK_LIBRARIES})

247 248
# Don't use jemalloc in the unit test library.
if(JEMALLOC_FOUND)
249 250 251
  list(APPEND NVIM_EXEC_LINK_LIBRARIES ${JEMALLOC_LIBRARIES})
endif()

252 253
add_executable(nvim ${NEOVIM_GENERATED_SOURCES} ${NEOVIM_SOURCES}
  ${NEOVIM_HEADERS})
254
target_link_libraries(nvim ${NVIM_EXEC_LINK_LIBRARIES})
255
install_helper(TARGETS nvim)
256

257 258
if(CLANG_ASAN_UBSAN)
  message(STATUS "Enabling Clang address sanitizer and undefined behavior sanitizer for nvim.")
259
  set_property(TARGET nvim APPEND_STRING PROPERTY COMPILE_FLAGS "-DEXITFREE ")
260
  set_property(TARGET nvim APPEND_STRING PROPERTY COMPILE_FLAGS "-fno-sanitize-recover -fno-omit-frame-pointer -fno-optimize-sibling-calls -fsanitize=address -fsanitize=undefined -fsanitize-blacklist=${PROJECT_SOURCE_DIR}/.asan-blacklist")
261
  set_property(TARGET nvim APPEND_STRING PROPERTY LINK_FLAGS "-fsanitize=address -fsanitize=undefined ")
262 263
elseif(CLANG_MSAN)
  message(STATUS "Enabling Clang memory sanitizer for nvim.")
264
  set_property(TARGET nvim APPEND_STRING PROPERTY COMPILE_FLAGS "-DEXITFREE ")
265 266
  set_property(TARGET nvim APPEND_STRING PROPERTY COMPILE_FLAGS "-fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer -fno-optimize-sibling-calls ")
  set_property(TARGET nvim APPEND_STRING PROPERTY LINK_FLAGS "-fsanitize=memory -fsanitize-memory-track-origins ")
267 268
elseif(CLANG_TSAN)
  message(STATUS "Enabling Clang thread sanitizer for nvim.")
269
  set_property(TARGET nvim APPEND_STRING PROPERTY COMPILE_FLAGS "-DEXITFREE ")
270 271
  set_property(TARGET nvim APPEND_STRING PROPERTY COMPILE_FLAGS "-fsanitize=thread ")
  set_property(TARGET nvim APPEND_STRING PROPERTY LINK_FLAGS "-fsanitize=thread ")
272 273
endif()

274 275 276 277 278 279 280 281
add_library(libnvim STATIC EXCLUDE_FROM_ALL ${NEOVIM_GENERATED_SOURCES}
  ${NEOVIM_SOURCES} ${NEOVIM_HEADERS})
target_link_libraries(libnvim ${NVIM_LINK_LIBRARIES})
set_target_properties(libnvim PROPERTIES
  POSITION_INDEPENDENT_CODE ON
  OUTPUT_NAME nvim)
set_property(TARGET libnvim APPEND_STRING PROPERTY COMPILE_FLAGS " -DMAKE_LIB ")

282
add_library(nvim-test MODULE EXCLUDE_FROM_ALL ${NEOVIM_GENERATED_SOURCES}
283
    ${NEOVIM_SOURCES} ${UNIT_TEST_FIXTURES} ${NEOVIM_HEADERS})
284
target_link_libraries(nvim-test ${NVIM_LINK_LIBRARIES})
285
set_property(TARGET nvim-test APPEND_STRING PROPERTY COMPILE_FLAGS -DUNIT_TESTING)
286 287

add_subdirectory(po)