1 cmake_minimum_required(VERSION 3.9)
3 get_property(is_multi_config GLOBAL PROPERTY GENERATOR_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)
8 elseif(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_C_FLAGS)
9 message(WARNING "No CMAKE_BUILD_TYPE is selected")
14 include(CheckIncludeFiles)
15 include(CheckFunctionExists)
16 include(CheckStructHasMember)
17 include(CheckCSourceCompiles)
19 mark_as_advanced(CMAKE_INSTALL_PREFIX)
21 option(USE_WIDECHAR "Enable wide character support" ON)
22 option(USE_ICONV "Enable iconv support" ON)
24 add_compile_options(-fcolor-diagnostics)
25 add_compile_options($<$<CONFIG:Debug>:-Wall>)
26 add_compile_options($<$<CONFIG:Debug>:-Wno-parentheses>)
27 add_compile_options($<$<CONFIG:Debug>:-Wno-uninitialized>)
28 add_compile_options($<$<CONFIG:Debug>:-Wmissing-prototypes>)
29 add_compile_options($<$<CONFIG:Debug>:-Wsystem-headers>)
30 add_compile_options($<$<CONFIG:Release>:-Wuninitialized>)
31 add_compile_options($<$<CONFIG:Release>:-Wno-dangling-else>)
32 add_compile_options(-Wstack-protector -fstack-protector)
33 add_compile_options(-Wstrict-aliasing -fstrict-aliasing)
35 include_directories(${CMAKE_CURRENT_BINARY_DIR})
38 cl/extern.h common/extern.h ex/extern.h vi/extern.h
39 common/options_def.h ex/ex_def.h ex/version.h)
42 cl/cl_funcs.c cl/cl_main.c cl/cl_read.c cl/cl_screen.c cl/cl_term.c)
45 common/conv.c common/cut.c common/delete.c common/encoding.c common/exf.c
46 common/key.c common/line.c common/log.c common/main.c common/mark.c
47 common/msg.c common/options.c common/options_f.c common/put.c
48 common/recover.c common/screen.c common/search.c common/seq.c
52 ex/ex.c ex/ex_abbrev.c ex/ex_append.c ex/ex_args.c ex/ex_argv.c ex/ex_at.c
53 ex/ex_bang.c ex/ex_cd.c ex/ex_cmd.c ex/ex_cscope.c ex/ex_delete.c
54 ex/ex_display.c ex/ex_edit.c ex/ex_equal.c ex/ex_file.c ex/ex_filter.c
55 ex/ex_global.c ex/ex_init.c ex/ex_join.c ex/ex_map.c ex/ex_mark.c
56 ex/ex_mkexrc.c ex/ex_move.c ex/ex_open.c ex/ex_preserve.c ex/ex_print.c
57 ex/ex_put.c ex/ex_quit.c ex/ex_read.c ex/ex_screen.c ex/ex_script.c
58 ex/ex_set.c ex/ex_shell.c ex/ex_shift.c ex/ex_source.c ex/ex_stop.c
59 ex/ex_subst.c ex/ex_tag.c ex/ex_txt.c ex/ex_undo.c ex/ex_usage.c
60 ex/ex_util.c ex/ex_version.c ex/ex_visual.c ex/ex_write.c ex/ex_yank.c
64 vi/getc.c vi/v_at.c vi/v_ch.c vi/v_cmd.c vi/v_delete.c vi/v_ex.c
65 vi/v_increment.c vi/v_init.c vi/v_itxt.c vi/v_left.c vi/v_mark.c
66 vi/v_match.c vi/v_paragraph.c vi/v_put.c vi/v_redraw.c vi/v_replace.c
67 vi/v_right.c vi/v_screen.c vi/v_scroll.c vi/v_search.c vi/v_section.c
68 vi/v_sentence.c vi/v_status.c vi/v_txt.c vi/v_ulcase.c vi/v_undo.c
69 vi/v_util.c vi/v_word.c vi/v_xchar.c vi/v_yank.c vi/v_z.c vi/v_zexit.c
70 vi/vi.c vi/vs_line.c vi/vs_msg.c vi/vs_refresh.c vi/vs_relative.c
71 vi/vs_smap.c vi/vs_split.c)
74 regex/regcomp.c regex/regerror.c regex/regexec.c regex/regfree.c)
76 # commands to generate the public headers
77 set(extract_protos sed -n 's/^ \\* PUBLIC: \\\(.*\\\)/\\1/p')
78 set(extract_version sed -n
79 's/^.*version \\\([^\)]*\)\\\).*/\#define VI_VERSION \\\"\\1\\\"/p')
81 add_custom_command(OUTPUT cl/extern.h
82 COMMAND ${extract_protos} ${CL_SRCS} > cl/extern.h
83 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
85 add_custom_command(OUTPUT common/extern.h
86 COMMAND ${extract_protos} ${COMMON_SRCS} > common/extern.h
87 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
88 DEPENDS ${COMMON_SRCS})
89 add_custom_command(OUTPUT ex/extern.h
90 COMMAND ${extract_protos} ${EX_SRCS} > ex/extern.h
91 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
93 add_custom_command(OUTPUT vi/extern.h
94 COMMAND ${extract_protos} ${VI_SRCS} > vi/extern.h
95 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
97 add_custom_command(OUTPUT common/options_def.h
98 COMMAND awk -f common/options.awk
99 common/options.c > common/options_def.h
100 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
101 DEPENDS common/options.c)
102 add_custom_command(OUTPUT ex/ex_def.h
103 COMMAND awk -f ex/ex.awk ex/ex_cmd.c > ex/ex_def.h
104 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
106 add_custom_command(OUTPUT ex/version.h
107 COMMAND ${extract_version} README > ex/version.h
108 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
112 target_sources(nvi PRIVATE ${MAIN_PROTOS} ${CL_SRCS} ${COMMON_SRCS}
113 ${EX_SRCS} ${VI_SRCS})
114 target_compile_definitions(nvi PRIVATE $<$<CONFIG:Debug>:DEBUG>
115 $<$<CONFIG:Debug>:COMLOG>)
117 check_function_exists(openpty UTIL_IN_LIBC)
119 find_library(UTIL_LIBRARY util)
120 target_link_libraries(nvi PRIVATE ${UTIL_LIBRARY})
123 check_function_exists(__b64_ntop RESOLV_IN_LIBC)
124 if(NOT RESOLV_IN_LIBC)
125 find_library(RESOLV_LIBRARY resolv)
126 target_link_libraries(nvi PRIVATE ${RESOLV_LIBRARY})
130 find_library(CURSES_LIBRARY NAMES ncursesw cursesw curses HINTS /usr/lib)
131 find_library(TERMINFO_LIBRARY NAMES tinfow terminfo HINTS /usr/lib)
133 # link to the wchar_t awared BSD libregex.a
134 add_library(regex STATIC)
135 target_sources(regex PRIVATE ${REGEX_SRCS})
136 target_include_directories(regex PUBLIC regex)
137 target_compile_definitions(regex PUBLIC __REGEX_PRIVATE)
138 target_link_libraries(nvi PRIVATE regex)
140 find_library(CURSES_LIBRARY NAMES ncurses curses HINTS /usr/lib)
141 find_library(TERMINFO_LIBRARY NAMES tinfo terminfo HINTS /usr/lib)
142 target_compile_options(nvi PRIVATE -Wno-pointer-sign)
145 target_link_libraries(nvi PRIVATE ${CURSES_LIBRARY} ${TERMINFO_LIBRARY})
148 check_function_exists(iconv ICONV_IN_LIBC)
149 if(NOT ICONV_IN_LIBC)
150 find_path(ICONV_INCLUDE_DIR iconv.h)
151 find_library(ICONV_LIBRARY iconv)
154 # detect the prototype of iconv(3)
155 set(CMAKE_C_FLAGS_BACKUP "${CMAKE_C_FLAGS}")
156 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
157 set(CMAKE_REQUIRED_INCLUDES "${ICONV_INCLUDE_DIR}")
158 set(CMAKE_REQUIRED_LIBRARIES "${ICONV_LIBRARY}")
159 check_c_source_compiles("
167 iconv(conv, &in, &ilen, &out, &olen);
171 set(CMAKE_REQUIRED_INCLUDES)
172 set(CMAKE_REQUIRED_LIBRARIES)
173 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS_BACKUP}")
175 target_include_directories(nvi PRIVATE ${ICONV_INCLUDE_DIR})
176 target_link_libraries(nvi PRIVATE ${ICONV_LIBRARY})
179 check_function_exists(getprogname GETPROGNAME_IN_LIBC)
180 check_function_exists(strlcpy STRLCPY_IN_LIBC)
181 if(NOT GETPROGNAME_IN_LIBC OR NOT STRLCPY_IN_LIBC)
182 find_package(PkgConfig REQUIRED)
183 pkg_check_modules(LIBBSD libbsd-overlay)
184 add_definitions(${LIBBSD_CFLAGS})
185 target_link_libraries(nvi PRIVATE ${LIBBSD_LIBRARIES})
188 check_function_exists(dbopen DBOPEN_IN_LIBC)
189 if(NOT DBOPEN_IN_LIBC)
190 target_link_libraries(nvi PRIVATE db1)
193 check_include_files(libutil.h HAVE_LIBUTIL_H)
194 check_include_files(ncurses.h HAVE_NCURSES_H)
195 check_include_files(ncursesw/ncurses.h HAVE_NCURSESW_NCURSES_H)
196 check_include_files(pty.h HAVE_PTY_H)
197 check_include_files(term.h HAVE_TERM_H)
198 check_struct_has_member("struct dirent" d_namlen dirent.h HAVE_DIRENT_D_NAMLEN LANGUAGE C)
200 configure_file(files/config.h.in config.h)
202 set(vi_cv_path_preserve /var/tmp/vi.recover/)
204 set(vi_cv_path_msgcat /usr/local/share/vi/catalog/)
206 set(vi_cv_path_msgcat /usr/share/vi/catalog/)
209 configure_file(files/pathnames.h.in pathnames.h)
210 configure_file(files/recover.in recover @ONLY)