ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libptytty/CMakeLists.txt
Revision: 1.2
Committed: Tue Jul 27 07:12:32 2021 UTC (2 years, 9 months ago) by sf-exg
Content type: text/plain
Branch: MAIN
Changes since 1.1: +40 -1 lines
Log Message:
Add test for libsupc++

NetBSD 9.2 ships with a libsupc++ that is not position independent and
cannot therefore be used in a position independent shared library.

File Contents

# User Rev Content
1 sf-exg 1.1 cmake_minimum_required(VERSION 3.6)
2     project(libptytty VERSION 1.9)
3     set(CMAKE_CXX_STANDARD 11)
4     set(CMAKE_EXPORT_COMPILE_COMMANDS YES)
5    
6     include(CheckCSourceCompiles)
7     include(CheckCSourceRuns)
8     include(CheckFunctionExists)
9     include(CheckIncludeFiles)
10     include(CheckLibraryExists)
11     include(CheckStructHasMember)
12     include(CheckTypeSize)
13     include(GNUInstallDirs)
14    
15     set(VERSION ${PROJECT_VERSION})
16     set(prefix ${CMAKE_INSTALL_PREFIX})
17     set(includedir ${CMAKE_INSTALL_FULL_INCLUDEDIR})
18     set(libdir ${CMAKE_INSTALL_FULL_LIBDIR})
19    
20     option(BUILD_SHARED_LIBS "build a shared library" ON)
21     option(UTMP_SUPPORT "enable utmp support" ON)
22     option(WTMP_SUPPORT "enable wtmp support (requires UTMP_SUPPORT)" ON)
23     option(LASTLOG_SUPPORT "enable lastlog support (requires UTMP_SUPPORT)" ON)
24    
25     function(PT_FIND_FILE name id)
26     if(DEFINED ${id})
27     return()
28     elseif(CMAKE_CROSSCOMPILING)
29     message(STATUS "Checking for a fallback location of ${name} - define ${id} in config.h manually")
30     set(${id} "" CACHE STRING "")
31     else()
32     foreach(arg ${ARGN})
33     if(EXISTS ${arg})
34     message(STATUS "Checking for a fallback location of ${name} - ${arg}")
35     set(${id} ${arg} CACHE STRING "")
36     return()
37     endif()
38     endforeach()
39     message(STATUS "Checking for a fallback location of ${name} - not found")
40     set(${id} "" CACHE STRING "")
41     endif()
42     endfunction()
43    
44 sf-exg 1.2 if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
45     file(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/test.cxx"
46     "
47     struct e { };
48    
49     void f ()
50     {
51     try
52     {
53     new e ();
54     }
55     catch (...)
56     {
57     throw;
58     }
59     }
60     ")
61     execute_process(
62     WORKING_DIRECTORY "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp"
63     COMMAND ${CMAKE_C_COMPILER} -x c++ -shared -fPIC -o test.so test.cxx -lsupc++
64     OUTPUT_VARIABLE OUTPUT
65     ERROR_VARIABLE OUTPUT
66     RESULT_VARIABLE RESULT)
67     if(RESULT EQUAL 0)
68     message(STATUS "Checking for working libsupc++ - yes")
69     set(HAVE_LIBSUPCXX 1 CACHE BOOL "")
70     file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
71     "libsupc++ test succeeded with the following output:\n"
72     "${OUTPUT}\n")
73     else()
74     message(STATUS "Checking for working libsupc++ - no")
75     set(HAVE_LIBSUPCXX 0 CACHE BOOL "")
76     file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
77     "libsupc++ test failed with the following output:\n"
78     "${OUTPUT}\n")
79     endif()
80     endif()
81    
82 sf-exg 1.1 check_include_files(pty.h HAVE_PTY_H)
83     check_include_files(util.h HAVE_UTIL_H)
84     check_include_files(libutil.h HAVE_LIBUTIL_H)
85     check_include_files(sys/ioctl.h HAVE_SYS_IOCTL_H)
86     check_include_files(stropts.h HAVE_STROPTS_H)
87    
88     check_function_exists(revoke HAVE_REVOKE)
89     check_function_exists(_getpty HAVE__GETPTY)
90     check_function_exists(getpt HAVE_GETPT)
91     check_function_exists(posix_openpt HAVE_POSIX_OPENPT)
92     check_function_exists(isastream HAVE_ISASTREAM)
93     check_function_exists(setuid HAVE_SETUID)
94     check_function_exists(setreuid HAVE_SETREUID)
95     check_function_exists(setresuid HAVE_SETRESUID)
96    
97     check_c_source_compiles(
98     "#include <stdlib.h>
99    
100     int main ()
101     {
102     grantpt (0);
103     unlockpt (0);
104     ptsname (0);
105     }
106     "
107    
108     UNIX98_PTY)
109    
110     if(NOT UNIX98_PTY)
111     check_function_exists(openpty HAVE_OPENPTY)
112     if(NOT HAVE_OPENPTY)
113     find_library(LIBUTIL_PATH util)
114     check_library_exists(util openpty ${LIBUTIL_PATH} HAVE_LIBUTIL)
115     if(HAVE_LIBUTIL)
116     set(HAVE_OPENPTY 1)
117     endif()
118     endif()
119     endif()
120    
121     if(CMAKE_HOST_SOLARIS)
122     # Enable declarations in utmp.h on Solaris when the XPG4v2 namespace is active
123     set(__EXTENSIONS__ 1)
124     endif()
125    
126     check_include_files("sys/types.h;utmp.h" HAVE_UTMP_H)
127     if(HAVE_UTMP_H)
128     set(CMAKE_EXTRA_INCLUDE_FILES "sys/types.h;utmp.h")
129     check_type_size("struct utmp" STRUCT_UTMP)
130     if (HAVE_STRUCT_UTMP)
131     check_struct_has_member(
132     "struct utmp"
133     ut_host
134     "sys/types.h;utmp.h"
135     HAVE_UTMP_HOST)
136     check_struct_has_member(
137     "struct utmp"
138     ut_pid
139     "sys/types.h;utmp.h"
140     HAVE_UTMP_PID)
141    
142     check_function_exists(updwtmp HAVE_UPDWTMP)
143     check_include_files("sys/types.h;lastlog.h" HAVE_LASTLOG_H)
144     if (HAVE_LASTLOG_H)
145     set(CMAKE_EXTRA_INCLUDE_FILES "sys/types.h;lastlog.h")
146     endif()
147     check_type_size("struct lastlog" STRUCT_LASTLOG)
148     endif()
149     set(CMAKE_EXTRA_INCLUDE_FILES)
150    
151     PT_FIND_FILE(
152     utmp
153     PT_UTMP_FILE
154     "/var/run/utmp"
155     "/var/adm/utmp"
156     "/etc/utmp"
157     "/usr/etc/utmp"
158     "/usr/adm/utmp")
159    
160     PT_FIND_FILE(
161     wtmp
162     PT_WTMP_FILE
163     "/var/log/wtmp"
164     "/var/adm/wtmp"
165     "/etc/wtmp"
166     "/usr/etc/wtmp"
167     "/usr/adm/wtmp")
168    
169     PT_FIND_FILE(
170     lastlog
171     PT_LASTLOG_FILE
172     "/var/log/lastlog"
173     "/var/adm/lastlog")
174     endif()
175    
176     check_include_files(utmpx.h HAVE_UTMPX_H)
177     if(HAVE_UTMPX_H)
178     set(CMAKE_EXTRA_INCLUDE_FILES "utmpx.h")
179     check_type_size("struct utmpx" STRUCT_UTMPX)
180     if (HAVE_STRUCT_UTMPX)
181     check_struct_has_member(
182     "struct utmpx"
183     ut_host
184     "sys/types.h;utmpx.h"
185     HAVE_UTMPX_HOST)
186    
187     check_function_exists(updwtmpx HAVE_UPDWTMPX)
188     check_function_exists(updlastlogx HAVE_UPDLASTLOGX)
189     check_type_size("struct lastlogx" STRUCT_LASTLOGX)
190     endif()
191     set(CMAKE_EXTRA_INCLUDE_FILES)
192    
193     PT_FIND_FILE(
194     wtmpx
195     PT_WTMPX_FILE
196     "/var/log/wtmpx"
197     "/var/adm/wtmpx")
198    
199     PT_FIND_FILE(
200     lastlogx
201     PT_LASTLOGX_FILE
202     "/var/log/lastlogx"
203     "/var/adm/lastlogx")
204     endif()
205    
206     if(CMAKE_HOST_SOLARIS)
207     # Enable declarations of msg_control and msg_controllen on Solaris
208     set(CMAKE_REQUIRED_QUIET ON)
209     check_c_source_compiles(
210     "
211     int main ()
212     {
213     #if __STDC_VERSION__ < 199901L
214     error
215     #endif
216     }
217     "
218    
219     C99)
220     set(CMAKE_REQUIRED_QUIET OFF)
221     if(C99)
222     set(_XOPEN_SOURCE 600)
223     else()
224     set(_XOPEN_SOURCE 500)
225     endif()
226     set(CMAKE_REQUIRED_DEFINITIONS -D_XOPEN_SOURCE=${_XOPEN_SOURCE})
227    
228     find_library(LIBSOCKET_PATH socket)
229     check_library_exists(socket sendmsg ${LIBSOCKET_PATH} HAVE_LIBSOCKET)
230     if(HAVE_LIBSOCKET)
231     set(CMAKE_REQUIRED_LIBRARIES socket)
232     endif()
233     endif()
234    
235     # Check for unix-compliant filehandle passing ability
236     check_c_source_compiles(
237     "
238     #include <stddef.h> // broken bsds (is that redundant?) need this
239     #include <sys/types.h>
240     #include <sys/socket.h>
241     #include <sys/uio.h>
242    
243     int main ()
244     {
245     struct msghdr msg;
246     struct iovec iov;
247     char buf [100];
248     char data = 0;
249    
250     iov.iov_base = &data;
251     iov.iov_len = 1;
252    
253     msg.msg_iov = &iov;
254     msg.msg_iovlen = 1;
255     msg.msg_control = buf;
256     msg.msg_controllen = sizeof buf;
257    
258     struct cmsghdr *cmsg = CMSG_FIRSTHDR (&msg);
259     cmsg->cmsg_level = SOL_SOCKET;
260     cmsg->cmsg_type = SCM_RIGHTS;
261     cmsg->cmsg_len = 100;
262    
263     *(int *)CMSG_DATA (cmsg) = 5;
264    
265     return sendmsg (3, &msg, 0);
266     }
267     "
268    
269     HAVE_UNIX_FDPASS)
270     if(NOT HAVE_UNIX_FDPASS)
271     message(FATAL_ERROR "libptytty requires unix-compliant filehandle passing ability")
272     endif()
273    
274     check_c_source_runs(
275     "
276     #include <grp.h>
277     #include <sys/stat.h>
278     #include <sys/types.h>
279     #include <unistd.h>
280    
281     int main ()
282     {
283     struct stat st;
284     struct group *gr = getgrnam (\"tty\");
285     char *tty = ttyname (0);
286     return
287     !(gr
288     && tty
289     && stat (tty, &st) == 0
290     && st.st_gid == gr->gr_gid);
291     }
292     "
293    
294     TTY_GID_SUPPORT)
295    
296     configure_file(
297     config.h.cmake
298     config.h)
299    
300     add_library(ptytty
301     src/c-api.C
302     src/fdpass.C
303     src/logging.C
304     src/proxy.C
305     src/ptytty.C)
306     target_include_directories(ptytty PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
307     set_target_properties(ptytty PROPERTIES VERSION 0)
308 sf-exg 1.2 if(HAVE_LIBSUPCXX)
309 sf-exg 1.1 set_target_properties(ptytty PROPERTIES LINKER_LANGUAGE C)
310     target_link_libraries(ptytty PRIVATE supc++)
311 sf-exg 1.2 set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES)
312 sf-exg 1.1 endif()
313     if(HAVE_LIBSOCKET)
314     target_link_libraries(ptytty PRIVATE socket)
315     list(APPEND LIBS -lsocket)
316     endif()
317     if(HAVE_LIBUTIL)
318     target_link_libraries(ptytty PRIVATE util)
319     list(APPEND LIBS -lutil)
320     endif()
321    
322     configure_file(
323     libptytty.pc.in
324     libptytty.pc)
325    
326     add_executable(c-sample eg/c-sample.c)
327     target_include_directories(c-sample PRIVATE src)
328     target_link_libraries(c-sample ptytty)
329    
330     add_custom_command(
331     OUTPUT ${CMAKE_SOURCE_DIR}/doc/libptytty.3
332     DEPENDS ${CMAKE_SOURCE_DIR}/doc/libptytty.3.pod
333     COMMAND pod2man -n libptytty -r ${PROJECT_VERSION} -q\" -c LIBPTYTTY -s3
334     < ${CMAKE_SOURCE_DIR}/doc/libptytty.3.pod
335     > ${CMAKE_SOURCE_DIR}/doc/libptytty.3
336     VERBATIM)
337    
338     add_custom_command(
339     OUTPUT ${CMAKE_SOURCE_DIR}/README
340     DEPENDS ${CMAKE_SOURCE_DIR}/doc/libptytty.3.pod
341     COMMAND pod2text
342     < ${CMAKE_SOURCE_DIR}/doc/libptytty.3.pod
343     > ${CMAKE_SOURCE_DIR}/README
344     VERBATIM)
345    
346     add_custom_target(alldoc
347     DEPENDS ${CMAKE_SOURCE_DIR}/doc/libptytty.3
348     ${CMAKE_SOURCE_DIR}/README)
349    
350     install(
351     TARGETS ptytty
352     DESTINATION ${CMAKE_INSTALL_LIBDIR})
353     install(
354     FILES src/libptytty.h
355     DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
356     install(
357     FILES doc/libptytty.3
358     DESTINATION ${CMAKE_INSTALL_MANDIR}/man3)
359     install(
360     FILES ${CMAKE_BINARY_DIR}/libptytty.pc
361     DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
362    
363     set(DISTFILES
364     CMakeLists.txt
365     COPYING
366     Changes
367     README
368     config.h.cmake
369     doc/libptytty.3
370     doc/libptytty.3.pod
371     eg/c-sample.c
372     libptytty.pc.in
373     src/c-api.C
374     src/ecb.h
375     src/estl.h
376     src/fdpass.C
377     src/libptytty.h
378     src/logging.C
379     src/proxy.C
380     src/ptytty.C
381     src/ptytty.h
382     src/ptytty_conf.h)
383    
384     set(DISTDIR ${PROJECT_NAME}-${PROJECT_VERSION})
385    
386     add_custom_target(distdir
387     DEPENDS alldoc
388     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
389     COMMAND rm -rf ${CMAKE_BINARY_DIR}/${DISTDIR}
390     COMMAND rsync -aRv ${DISTFILES} ${CMAKE_BINARY_DIR}/${DISTDIR})
391    
392     add_custom_target(dist
393     COMMAND tar cvf - ${DISTDIR} | gzip -vf9 > ${DISTDIR}.tar.gz)
394    
395     add_dependencies(dist distdir)