Skip to content

Commit 6a8af80

Browse files
authored
Support out-of-source build with modern CMake.
1 parent 7d3f435 commit 6a8af80

File tree

7 files changed

+193
-171
lines changed

7 files changed

+193
-171
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
*.o
2-
*.a
31
*.swp
42
*~
53
*.orig
@@ -8,3 +6,4 @@ extern.h
86
*_def.h
97
version.h
108
tags
9+
build/

CMakeLists.txt

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
cmake_minimum_required(VERSION 3.9)
2+
3+
get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
4+
if(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")
10+
endif()
11+
12+
project(nvi2 C)
13+
14+
include(CheckIncludeFiles)
15+
include(CheckFunctionExists)
16+
include(CheckCSourceCompiles)
17+
18+
mark_as_advanced(CMAKE_INSTALL_PREFIX)
19+
20+
option(USE_WIDECHAR "Enable wide character support" ON)
21+
option(USE_ICONV "Enable iconv support" ON)
22+
23+
add_compile_options(-fcolor-diagnostics)
24+
add_compile_options($<$<CONFIG:Debug>:-Wall>)
25+
add_compile_options($<$<CONFIG:Debug>:-Wno-parentheses>)
26+
add_compile_options($<$<CONFIG:Debug>:-Wno-uninitialized>)
27+
add_compile_options($<$<CONFIG:Debug>:-Wmissing-prototypes>)
28+
add_compile_options($<$<CONFIG:Debug>:-Wsystem-headers>)
29+
add_compile_options($<$<CONFIG:Release>:-Wuninitialized>)
30+
add_compile_options($<$<CONFIG:Release>:-Wno-dangling-else>)
31+
add_compile_options(-Wstack-protector -fstack-protector)
32+
add_compile_options(-Wstrict-aliasing -fstrict-aliasing)
33+
34+
include_directories(${CMAKE_CURRENT_BINARY_DIR})
35+
36+
set(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+
40+
set(CL_SRCS
41+
cl/cl_funcs.c cl/cl_main.c cl/cl_read.c cl/cl_screen.c cl/cl_term.c)
42+
43+
set(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+
50+
set(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+
62+
set(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+
72+
set(REGEX_SRCS
73+
regex/regcomp.c regex/regerror.c regex/regexec.c regex/regfree.c)
74+
75+
# commands to generate the public headers
76+
set(extract_protos sed -n 's/^ \\* PUBLIC: \\\(.*\\\)/\\1/p')
77+
set(extract_version sed -n
78+
's/^.*version \\\([^\)]*\)\\\).*/\#define VI_VERSION \\\"\\1\\\"/p')
79+
80+
add_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})
84+
add_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})
88+
add_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})
92+
add_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})
96+
add_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)
101+
add_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)
105+
add_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+
110+
add_executable(nvi)
111+
target_sources(nvi PRIVATE ${MAIN_PROTOS} ${CL_SRCS} ${COMMON_SRCS}
112+
${EX_SRCS} ${VI_SRCS})
113+
target_compile_definitions(nvi PRIVATE $<$<CONFIG:Debug>:DEBUG>
114+
$<$<CONFIG:Debug>:COMLOG>)
115+
116+
check_function_exists(openpty UTIL_IN_LIBC)
117+
if(NOT UTIL_IN_LIBC)
118+
find_library(UTIL_LIBRARY util)
119+
target_link_libraries(nvi PRIVATE ${UTIL_LIBRARY})
120+
endif()
121+
122+
check_function_exists(__b64_ntop RESOLV_IN_LIBC)
123+
if(NOT RESOLV_IN_LIBC)
124+
find_library(RESOLV_LIBRARY resolv)
125+
target_link_libraries(nvi PRIVATE ${RESOLV_LIBRARY})
126+
endif()
127+
128+
if(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)
137+
else()
138+
find_library(CURSES_LIBRARY NAMES ncurses curses HINTS /usr/lib)
139+
target_compile_options(nvi PRIVATE -Wno-pointer-sign)
140+
endif()
141+
142+
target_link_libraries(nvi PRIVATE ${CURSES_LIBRARY})
143+
144+
if(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})
174+
endif()
175+
176+
check_include_files(libutil.h HAVE_LIBUTIL_H)
177+
check_include_files(ncurses.h HAVE_NCURSES_H)
178+
check_include_files(term.h HAVE_TERM_H)
179+
180+
configure_file(files/config.h.in config.h)
181+
182+
set(vi_cv_path_preserve /var/tmp/vi.recover/)
183+
if(APPLE)
184+
set(vi_cv_path_msgcat /usr/local/share/vi/catalog/)
185+
else()
186+
set(vi_cv_path_msgcat /usr/share/vi/catalog/)
187+
endif()
188+
189+
configure_file(files/pathnames.h.in pathnames.h)
190+
configure_file(files/recover.in recover @ONLY)

README

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ The directory layout is as follows:
66

77
LICENSE ....... Copyright, use and redistribution information.
88
README ........ This file.
9-
build ......... Build directory.
109
catalog ....... Message catalogs; see catalog/README.
1110
cl ............ Vi interface to the curses(3) library.
1211
common ........ Code shared by ex and vi.
13-
man ........... Ex/vi documentation.
1412
ex ............ Ex source code.
13+
files ......... Template files.
14+
man ........... Ex/vi documentation.
1515
regex ......... Modified regex library with wide character support.
1616
vi ............ Vi source code.
1717

build/CMakeLists.txt

Lines changed: 0 additions & 164 deletions
This file was deleted.
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
/* Define if you want a debugging version. */
2-
#cmakedefine DEBUG
3-
41
/* Define when using wide characters */
52
#cmakedefine USE_WIDECHAR
63

File renamed without changes.

0 commit comments

Comments
 (0)