Skip to content

Commit 5dfc709

Browse files
authored
Merge pull request #1356 from val-ms/cmake-find-curses-separate-tinfo
CMake: improve ncurses detection; separate TINFO_LIBRARY input
2 parents 1e29025 + af6d3e8 commit 5dfc709

File tree

4 files changed

+113
-80
lines changed

4 files changed

+113
-80
lines changed

INSTALL-cross-linux-arm64.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,14 @@ set(CMAKE_SYSROOT /opt/aarch64-wrs-linux-sysroot)
157157
#set(PCRE2_INCLUDE_DIR "/usr/include/")
158158
#set(PCRE2_LIBRARY "/usr/lib64/libpcre2-8.so")
159159
160-
#set(CURSES_INCLUDE_DIR "/usr/include/")
161-
#set(CURSES_LIBRARY "/usr/lib/aarch64-linux-gnu/libncurses.a;/usr/lib/aarch64-linux-gnu/libtinfo.a")
162-
# Tip: You may not need to also link with libtinfo.a, depending on what your distribution provides:
163-
#set(CURSES_LIBRARY "/usr/lib/aarch64-linux-gnu/libncurses.a")
164-
# Tip: Alternatively, you could link with the shared library:
160+
set(NCURSES_INCLUDE_DIR "/usr/include/")
161+
set(CURSES_LIBRARY "/usr/lib/aarch64-linux-gnu/libncurses.a")
162+
set(TINFO_LIBRARY "/usr/lib/aarch64-linux-gnu/libtinfo.a")
163+
# Tip: You may not need to also link with libtinfo.a, depending on what your distribution provides.
164+
165+
# Tip 2: Alternatively, you could link with the shared libraries:
165166
#set(CURSES_LIBRARY "/usr/lib/aarch64-linux-gnu/libncurses.so")
167+
#set(TINFO_LIBRARY "/usr/lib/aarch64-linux-gnu/libtinfo.so")
166168
167169
#set(ZLIB_INCLUDE_DIR "/usr/include/")
168170
#set(ZLIB_LIBRARY "/usr/lib64/libz.so")
@@ -225,12 +227,14 @@ set(LIBXML2_LIBRARY "/usr/lib/aarch64-linux-gnu/libxml2.so")
225227
set(PCRE2_INCLUDE_DIR "/usr/include/")
226228
set(PCRE2_LIBRARY "/usr/lib/aarch64-linux-gnu/libpcre2-8.so")
227229
228-
set(CURSES_INCLUDE_DIR "/usr/include/")
229-
set(CURSES_LIBRARY "/usr/lib/aarch64-linux-gnu/libncurses.a;/usr/lib/aarch64-linux-gnu/libtinfo.a")
230-
# Tip: You may not need to also link with libtinfo.a, depending on what your distribution provides:
231-
#set(CURSES_LIBRARY "/usr/lib/aarch64-linux-gnu/libncurses.a")
232-
# Tip: Alternatively, you could link with the shared library:
230+
set(NCURSES_INCLUDE_DIR "/usr/include/")
231+
set(CURSES_LIBRARY "/usr/lib/aarch64-linux-gnu/libncurses.a")
232+
set(TINFO_LIBRARY "/usr/lib/aarch64-linux-gnu/libtinfo.a")
233+
# Tip: You may not need to also link with libtinfo.a, depending on what your distribution provides.
234+
235+
# Tip 2: Alternatively, you could link with the shared libraries:
233236
#set(CURSES_LIBRARY "/usr/lib/aarch64-linux-gnu/libncurses.so")
237+
#set(TINFO_LIBRARY "/usr/lib/aarch64-linux-gnu/libtinfo.so")
234238
235239
set(ZLIB_INCLUDE_DIR "/usr/include/")
236240
set(ZLIB_LIBRARY "/usr/lib/aarch64-linux-gnu/libz.so")

INSTALL.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,11 @@ and:
675675
-D CURSES_LIBRARY="_filepath of curses library_"
676676
```
677677
678+
and, if tinfo is separate from ncurses:
679+
```sh
680+
-D TINFO_LIBRARY="_filepath of tinfo library_"
681+
```
682+
678683
### Bytecode Runtime
679684
680685
Bytecode signatures are a type of executable plugin that provide extra

Jenkinsfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,9 @@ pipeline {
9999
-D LIBXML2_LIBRARY="$HOME/.mussels/install/host-static/lib/libxml2.a" \
100100
-D PCRE2_INCLUDE_DIR="$HOME/.mussels/install/host-static/include" \
101101
-D PCRE2_LIBRARY="$HOME/.mussels/install/host-static/lib/libpcre2-8.a" \
102-
-D CURSES_INCLUDE_DIR="$HOME/.mussels/install/host-static/include" \
103-
-D CURSES_LIBRARY="$HOME/.mussels/install/host-static/lib/libncurses.a;$HOME/.mussels/install/host-static/lib/libtinfo.a" \
102+
-D NCURSES_INCLUDE_DIR="$HOME/.mussels/install/host-static/include" \
103+
-D CURSES_LIBRARY="$HOME/.mussels/install/host-static/lib/libncurses.a" \
104+
-D TINFO_LIBRARY="$HOME/.mussels/install/host-static/lib/libtinfo.a" \
104105
-D ZLIB_INCLUDE_DIR="$HOME/.mussels/install/host-static/include" \
105106
-D ZLIB_LIBRARY="$HOME/.mussels/install/host-static/lib/libz.a" \
106107
-D LIBCHECK_INCLUDE_DIR="$HOME/.mussels/install/host-static/include" \

cmake/FindCURSES.cmake

Lines changed: 91 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Imported Targets
1313
This module provides the following imported targets, if found:
1414
1515
``Curses::curses``
16-
The CURSES library
16+
The CURSES library and possibly TINFO library
1717
1818
Result Variables
1919
^^^^^^^^^^^^^^^^
@@ -34,20 +34,26 @@ Cache Variables
3434
3535
The following cache variables may also be set:
3636
37-
``CURSES_INCLUDE_DIR``
38-
The directory containing ``foo.h``.
37+
``NCURSES_INCLUDE_DIR``
38+
The directory containing ``ncurses.h``.
39+
``PDCURSES_INCLUDE_DIR``
40+
The directory containing ``curses.h``.
3941
``CURSES_LIBRARY``
4042
The path to the CURSES library.
43+
``TINFO_LIBRARY``
44+
The path to the TINFO library.
4145
4246
#]=======================================================================]
4347

44-
find_package(PkgConfig QUIET)
45-
# First try for NCurses
46-
pkg_search_module (PC_NCurses QUIET ncurses ncursesw)
48+
if(NOT NCURSES_INCLUDE_DIR)
49+
find_package(PkgConfig QUIET)
50+
# First try for NCurses
51+
pkg_search_module (PC_NCurses QUIET ncurses ncursesw)
52+
endif()
4753

4854
find_path(NCURSES_INCLUDE_DIR
49-
NAMES ncurses.h
50-
PATHS ${PC_NCurses_INCLUDE_DIRS} ${CURSES_INCLUDE_DIR}
55+
NAMES ncurses.h
56+
PATHS ${PC_NCurses_INCLUDE_DIRS} ${CURSES_INCLUDE_DIR}
5157
)
5258

5359
string(FIND ${NCURSES_INCLUDE_DIR} "-NOTFOUND" NCURSES_NOT_FOUND)
@@ -69,82 +75,99 @@ if(NCURSES_NOT_FOUND EQUAL -1)
6975

7076
include(FindPackageHandleStandardArgs)
7177
find_package_handle_standard_args(CURSES
72-
FOUND_VAR CURSES_FOUND
73-
REQUIRED_VARS
74-
CURSES_LIBRARY
75-
NCURSES_INCLUDE_DIR
76-
VERSION_VAR CURSES_VERSION
78+
FOUND_VAR CURSES_FOUND
79+
REQUIRED_VARS
80+
CURSES_LIBRARY
81+
NCURSES_INCLUDE_DIR
82+
VERSION_VAR CURSES_VERSION
83+
)
84+
85+
include(FindPackageHandleStandardArgs)
86+
find_package_handle_standard_args(TINFO
87+
FOUND_VAR TINFO_FOUND
88+
REQUIRED_VARS
89+
TINFO_LIBRARY
90+
NCURSES_INCLUDE_DIR
91+
VERSION_VAR CURSES_VERSION
92+
NAME_MISMATCHED
7793
)
7894

7995
set(HAVE_LIBNCURSES 1)
8096
set(CURSES_INCLUDE "<ncurses.h>")
8197

82-
set(CURSES_LIBRARIES ${CURSES_LIBRARY})
98+
if(NOT TINFO_FOUND)
99+
set(CURSES_LIBRARIES "${CURSES_LIBRARY}")
100+
else()
101+
set(CURSES_LIBRARIES "${CURSES_LIBRARY};${TINFO_LIBRARY}")
102+
endif()
103+
83104
set(CURSES_INCLUDE_DIRS ${NCURSES_INCLUDE_DIR})
84105
set(CURSES_DEFINITIONS ${PC_NCurses_CFLAGS_OTHER})
85106

86107
if (NOT TARGET Curses::curses)
87-
add_library(Curses::curses INTERFACE IMPORTED)
88-
set_target_properties(Curses::curses PROPERTIES
89-
INTERFACE_COMPILE_OPTIONS "${PC_NCurses_CFLAGS_OTHER}"
90-
INTERFACE_INCLUDE_DIRECTORIES "${CURSES_INCLUDE_DIRS}"
91-
INTERFACE_LINK_LIBRARIES "${CURSES_LIBRARY}"
92-
)
108+
add_library(Curses::curses INTERFACE IMPORTED)
109+
set_target_properties(Curses::curses PROPERTIES
110+
INTERFACE_COMPILE_OPTIONS "${PC_NCurses_CFLAGS_OTHER}"
111+
INTERFACE_INCLUDE_DIRECTORIES "${CURSES_INCLUDE_DIRS}"
112+
INTERFACE_LINK_LIBRARIES "${CURSES_LIBRARIES}"
113+
)
93114
endif()
94115
else()
95-
# Try for PDCurses
96-
pkg_check_modules(PC_PDCurses QUIET curses)
97-
98-
find_path(PDCURSES_INCLUDE_DIR
99-
NAMES curses.h
100-
PATHS ${PC_PDCurses_INCLUDE_DIRS} ${CURSES_INCLUDE_DIR}
101-
)
102-
103-
string(FIND ${PDCURSES_INCLUDE_DIR} "-NOTFOUND" PDCURSES_NOT_FOUND)
104-
if(PDCURSES_NOT_FOUND EQUAL -1)
105-
#
106-
# pdcurses WAS found!
107-
#
108-
set(HAVE_LIBPDCURSES 1)
109-
set(CURSES_INCLUDE "<curses.h>")
110-
111-
find_library(CURSES_LIBRARY
112-
NAMES curses pdcurses
113-
PATHS ${PC_PDCurses_LIBRARY_DIRS}
114-
)
115-
116-
set(CURSES_VERSION ${PC_PDCurses_VERSION})
117-
118-
include(FindPackageHandleStandardArgs)
119-
find_package_handle_standard_args(CURSES
120-
FOUND_VAR CURSES_FOUND
121-
REQUIRED_VARS
122-
CURSES_LIBRARY
123-
PDCURSES_INCLUDE_DIR
124-
VERSION_VAR CURSES_VERSION
125-
)
116+
# Try for PDCurses
117+
pkg_check_modules(PC_PDCurses QUIET curses)
126118

127-
set(HAVE_LIBPDCURSES 1)
128-
set(CURSES_INCLUDE "<curses.h>")
119+
find_path(PDCURSES_INCLUDE_DIR
120+
NAMES curses.h
121+
PATHS ${PC_PDCurses_INCLUDE_DIRS} ${CURSES_INCLUDE_DIR}
122+
)
129123

130-
set(CURSES_LIBRARIES ${CURSES_LIBRARY})
131-
set(CURSES_INCLUDE_DIRS ${PDCURSES_INCLUDE_DIR})
132-
set(CURSES_DEFINITIONS ${PC_PDCurses_CFLAGS_OTHER})
124+
string(FIND ${PDCURSES_INCLUDE_DIR} "-NOTFOUND" PDCURSES_NOT_FOUND)
125+
if(PDCURSES_NOT_FOUND EQUAL -1)
126+
#
127+
# pdcurses WAS found!
128+
#
129+
set(HAVE_LIBPDCURSES 1)
130+
set(CURSES_INCLUDE "<curses.h>")
133131

134-
if (NOT TARGET Curses::curses)
135-
add_library(Curses::curses UNKNOWN IMPORTED)
136-
set_target_properties(Curses::curses PROPERTIES
137-
INTERFACE_COMPILE_OPTIONS "${PC_PDCurses_CFLAGS_OTHER}"
138-
INTERFACE_INCLUDE_DIRECTORIES "${CURSES_INCLUDE_DIRS}"
139-
IMPORTED_LOCATION "${CURSES_LIBRARY}"
132+
find_library(CURSES_LIBRARY
133+
NAMES curses pdcurses
134+
PATHS ${PC_PDCurses_LIBRARY_DIRS}
140135
)
141-
endif()
142-
else()
143-
message(FATAL_ERROR "Unable to find ncurses or pdcurses")
144-
endif()
136+
137+
set(CURSES_VERSION ${PC_PDCurses_VERSION})
138+
139+
include(FindPackageHandleStandardArgs)
140+
find_package_handle_standard_args(CURSES
141+
FOUND_VAR CURSES_FOUND
142+
REQUIRED_VARS
143+
CURSES_LIBRARY
144+
PDCURSES_INCLUDE_DIR
145+
VERSION_VAR CURSES_VERSION
146+
)
147+
148+
set(HAVE_LIBPDCURSES 1)
149+
set(CURSES_INCLUDE "<curses.h>")
150+
151+
set(CURSES_LIBRARIES ${CURSES_LIBRARY})
152+
set(CURSES_INCLUDE_DIRS ${PDCURSES_INCLUDE_DIR})
153+
set(CURSES_DEFINITIONS ${PC_PDCurses_CFLAGS_OTHER})
154+
155+
if (NOT TARGET Curses::curses)
156+
add_library(Curses::curses UNKNOWN IMPORTED)
157+
set_target_properties(Curses::curses PROPERTIES
158+
INTERFACE_COMPILE_OPTIONS "${PC_PDCurses_CFLAGS_OTHER}"
159+
INTERFACE_INCLUDE_DIRECTORIES "${CURSES_INCLUDE_DIRS}"
160+
IMPORTED_LOCATION "${CURSES_LIBRARIES}"
161+
)
162+
endif()
163+
else()
164+
message(FATAL_ERROR "Unable to find ncurses or pdcurses")
165+
endif()
145166
endif()
146167

147168
mark_as_advanced(
148-
CURSES_INCLUDE_DIR
149-
CURSES_LIBRARY
169+
NCURSES_INCLUDE_DIR
170+
PDCURSES_INCLUDE_DIR
171+
CURSES_LIBRARY
172+
TINFO_LIBRARY
150173
)

0 commit comments

Comments
 (0)