1cmake_minimum_required(VERSION 3.9) 2 3get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) 4if(is_multi_config) 5 set(CMAKE_CONFIGURATION_TYPES Debug Release CACHE STRING 6 "Semicolon separated list of supported configuration types") 7 mark_as_advanced(CMAKE_CONFIGURATION_TYPES) 8elseif(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_C_FLAGS) 9 message(WARNING "No CMAKE_BUILD_TYPE is selected") 10endif() 11 12project(nvi2 C) 13 14include(CheckIncludeFiles) 15include(CheckFunctionExists) 16include(CheckCSourceCompiles) 17 18mark_as_advanced(CMAKE_INSTALL_PREFIX) 19 20option(USE_WIDECHAR "Enable wide character support" ON) 21option(USE_ICONV "Enable iconv support" ON) 22 23add_compile_options(-fcolor-diagnostics) 24add_compile_options($<$<CONFIG:Debug>:-Wall>) 25add_compile_options($<$<CONFIG:Debug>:-Wno-parentheses>) 26add_compile_options($<$<CONFIG:Debug>:-Wno-uninitialized>) 27add_compile_options($<$<CONFIG:Debug>:-Wmissing-prototypes>) 28add_compile_options($<$<CONFIG:Debug>:-Wsystem-headers>) 29add_compile_options($<$<CONFIG:Release>:-Wuninitialized>) 30add_compile_options($<$<CONFIG:Release>:-Wno-dangling-else>) 31add_compile_options(-Wstack-protector -fstack-protector) 32add_compile_options(-Wstrict-aliasing -fstrict-aliasing) 33 34include_directories(${CMAKE_CURRENT_BINARY_DIR}) 35 36set(MAIN_PROTOS 37 cl/extern.h common/extern.h ex/extern.h vi/extern.h 38 common/options_def.h ex/ex_def.h ex/version.h) 39 40set(CL_SRCS 41 cl/cl_funcs.c cl/cl_main.c cl/cl_read.c cl/cl_screen.c cl/cl_term.c) 42 43set(COMMON_SRCS 44 common/conv.c common/cut.c common/delete.c common/encoding.c common/exf.c 45 common/key.c common/line.c common/log.c common/main.c common/mark.c 46 common/msg.c common/options.c common/options_f.c common/put.c 47 common/recover.c common/screen.c common/search.c common/seq.c 48 common/util.c) 49 50set(EX_SRCS 51 ex/ex.c ex/ex_abbrev.c ex/ex_append.c ex/ex_args.c ex/ex_argv.c ex/ex_at.c 52 ex/ex_bang.c ex/ex_cd.c ex/ex_cmd.c ex/ex_cscope.c ex/ex_delete.c 53 ex/ex_display.c ex/ex_edit.c ex/ex_equal.c ex/ex_file.c ex/ex_filter.c 54 ex/ex_global.c ex/ex_init.c ex/ex_join.c ex/ex_map.c ex/ex_mark.c 55 ex/ex_mkexrc.c ex/ex_move.c ex/ex_open.c ex/ex_preserve.c ex/ex_print.c 56 ex/ex_put.c ex/ex_quit.c ex/ex_read.c ex/ex_screen.c ex/ex_script.c 57 ex/ex_set.c ex/ex_shell.c ex/ex_shift.c ex/ex_source.c ex/ex_stop.c 58 ex/ex_subst.c ex/ex_tag.c ex/ex_txt.c ex/ex_undo.c ex/ex_usage.c 59 ex/ex_util.c ex/ex_version.c ex/ex_visual.c ex/ex_write.c ex/ex_yank.c 60 ex/ex_z.c) 61 62set(VI_SRCS 63 vi/getc.c vi/v_at.c vi/v_ch.c vi/v_cmd.c vi/v_delete.c vi/v_ex.c 64 vi/v_increment.c vi/v_init.c vi/v_itxt.c vi/v_left.c vi/v_mark.c 65 vi/v_match.c vi/v_paragraph.c vi/v_put.c vi/v_redraw.c vi/v_replace.c 66 vi/v_right.c vi/v_screen.c vi/v_scroll.c vi/v_search.c vi/v_section.c 67 vi/v_sentence.c vi/v_status.c vi/v_txt.c vi/v_ulcase.c vi/v_undo.c 68 vi/v_util.c vi/v_word.c vi/v_xchar.c vi/v_yank.c vi/v_z.c vi/v_zexit.c 69 vi/vi.c vi/vs_line.c vi/vs_msg.c vi/vs_refresh.c vi/vs_relative.c 70 vi/vs_smap.c vi/vs_split.c) 71 72set(REGEX_SRCS 73 regex/regcomp.c regex/regerror.c regex/regexec.c regex/regfree.c) 74 75# commands to generate the public headers 76set(extract_protos sed -n 's/^ \\* PUBLIC: \\\(.*\\\)/\\1/p') 77set(extract_version sed -n 78 's/^.*version \\\([^\)]*\)\\\).*/\#define VI_VERSION \\\"\\1\\\"/p') 79 80add_custom_command(OUTPUT cl/extern.h 81 COMMAND ${extract_protos} ${CL_SRCS} > cl/extern.h 82 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 83 DEPENDS ${CL_SRCS}) 84add_custom_command(OUTPUT common/extern.h 85 COMMAND ${extract_protos} ${COMMON_SRCS} > common/extern.h 86 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 87 DEPENDS ${COMMON_SRCS}) 88add_custom_command(OUTPUT ex/extern.h 89 COMMAND ${extract_protos} ${EX_SRCS} > ex/extern.h 90 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 91 DEPENDS ${EX_SRCS}) 92add_custom_command(OUTPUT vi/extern.h 93 COMMAND ${extract_protos} ${VI_SRCS} > vi/extern.h 94 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 95 DEPENDS ${VI_SRCS}) 96add_custom_command(OUTPUT common/options_def.h 97 COMMAND awk -f common/options.awk 98 common/options.c > common/options_def.h 99 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 100 DEPENDS common/options.c) 101add_custom_command(OUTPUT ex/ex_def.h 102 COMMAND awk -f ex/ex.awk ex/ex_cmd.c > ex/ex_def.h 103 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 104 DEPENDS ex/ex_cmd.c) 105add_custom_command(OUTPUT ex/version.h 106 COMMAND ${extract_version} README > ex/version.h 107 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 108 DEPENDS README) 109 110add_executable(nvi) 111target_sources(nvi PRIVATE ${MAIN_PROTOS} ${CL_SRCS} ${COMMON_SRCS} 112 ${EX_SRCS} ${VI_SRCS}) 113target_compile_definitions(nvi PRIVATE $<$<CONFIG:Debug>:DEBUG> 114 $<$<CONFIG:Debug>:COMLOG>) 115 116check_function_exists(openpty UTIL_IN_LIBC) 117if(NOT UTIL_IN_LIBC) 118 find_library(UTIL_LIBRARY util) 119 target_link_libraries(nvi PRIVATE ${UTIL_LIBRARY}) 120endif() 121 122check_function_exists(__b64_ntop RESOLV_IN_LIBC) 123if(NOT RESOLV_IN_LIBC) 124 find_library(RESOLV_LIBRARY resolv) 125 target_link_libraries(nvi PRIVATE ${RESOLV_LIBRARY}) 126endif() 127 128if(USE_WIDECHAR) 129 find_library(CURSES_LIBRARY NAMES ncursesw cursesw curses HINTS /usr/lib) 130 131 # link to the wchar_t awared BSD libregex.a 132 add_library(regex STATIC) 133 target_sources(regex PRIVATE ${REGEX_SRCS}) 134 target_include_directories(regex PUBLIC regex) 135 target_compile_definitions(regex PUBLIC __REGEX_PRIVATE) 136 target_link_libraries(nvi PRIVATE regex) 137else() 138 find_library(CURSES_LIBRARY NAMES ncurses curses HINTS /usr/lib) 139 target_compile_options(nvi PRIVATE -Wno-pointer-sign) 140endif() 141 142target_link_libraries(nvi PRIVATE ${CURSES_LIBRARY}) 143 144if(USE_ICONV) 145 check_function_exists(__iconv ICONV_IN_LIBC) 146 if(NOT ICONV_IN_LIBC) 147 find_path(ICONV_INCLUDE_DIR iconv.h) 148 find_library(ICONV_LIBRARY iconv) 149 endif() 150 151 # detect the prototype of iconv(3) 152 set(CMAKE_C_FLAGS_BACKUP "${CMAKE_C_FLAGS}") 153 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror") 154 set(CMAKE_REQUIRED_INCLUDES "${ICONV_INCLUDE_DIR}") 155 set(CMAKE_REQUIRED_LIBRARIES "${ICONV_LIBRARY}") 156 check_c_source_compiles(" 157 #include <iconv.h> 158 int main() { 159 iconv_t conv = 0; 160 char* in = 0; 161 size_t ilen = 0; 162 char* out = 0; 163 size_t olen = 0; 164 iconv(conv, &in, &ilen, &out, &olen); 165 return 0; 166 } 167 " ICONV_TRADITIONAL) 168 set(CMAKE_REQUIRED_INCLUDES) 169 set(CMAKE_REQUIRED_LIBRARIES) 170 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS_BACKUP}") 171 172 target_include_directories(nvi PRIVATE ${ICONV_INCLUDE_DIR}) 173 target_link_libraries(nvi PRIVATE ${ICONV_LIBRARY}) 174endif() 175 176check_include_files(libutil.h HAVE_LIBUTIL_H) 177check_include_files(ncurses.h HAVE_NCURSES_H) 178check_include_files(term.h HAVE_TERM_H) 179 180configure_file(files/config.h.in config.h) 181 182set(vi_cv_path_preserve /var/tmp/vi.recover/) 183if(APPLE) 184 set(vi_cv_path_msgcat /usr/local/share/vi/catalog/) 185else() 186 set(vi_cv_path_msgcat /usr/share/vi/catalog/) 187endif() 188 189configure_file(files/pathnames.h.in pathnames.h) 190configure_file(files/recover.in recover @ONLY) 191