11include (CheckIncludeFile)
22include (CheckSymbolExists)
33
4- function (configure_system_header name )
4+ function (configure_flavor_header name flavor )
55 configure_file (
6- "${CMAKE_CURRENT_FUNCTION_LIST_DIR} /${name} .${CMAKE_HOST_SYSTEM_NAME } .h.in"
6+ "${CMAKE_CURRENT_FUNCTION_LIST_DIR} /${name} .${flavor } .h.in"
77 "include/config/${name} .h" )
88endfunction ()
99
1010function (configure_trn)
1111 #
1212 # Perform inspections of the system and configure accordingly.
1313 #
14+ check_include_file(fcntl.h I_FCNTL)
15+ check_include_file(io.h I_IO)
1416 check_include_file(pwd.h I_PWD)
1517 check_include_file(sgtty.h I_SGTTY)
1618 check_include_file(strings .h I_STRINGS)
@@ -24,11 +26,52 @@ function(configure_trn)
2426 check_include_file(unistd.h I_UNISTD)
2527 check_include_file(utime.h I_UTIME)
2628 check_include_file(vfork.h I_VFORK)
27- if (I_PWD)
28- check_symbol_exists(getpwent "pwd.h" HAS_GETPWENT)
29+
30+ # Determine method used for file descriptor I/O
31+ if (I_FCNTL)
32+ check_symbol_exists(open "fcntl.h" HAS_FCNTL_OPEN)
33+ if (HAS_FCNTL_OPEN)
34+ set (FDIO_FLAVOR "fcntl" )
35+ endif ()
36+ endif ()
37+ if (NOT FDIO_FLAVOR AND I_IO)
38+ check_symbol_exists(open "io.h" HAS_IO_OPEN)
39+ if (HAS_IO_OPEN)
40+ set (FDIO_FLAVOR "io" )
41+ endif ()
42+ endif ()
43+ if (NOT FDIO_FLAVOR)
44+ message (FATAL_ERROR "Couldn't find open() in <fcntl.h> or <io.h>; file descriptor I/O not found." )
45+ endif ()
46+
47+ # Pipe open/close functions
48+ check_symbol_exists(_popen "stdio.h" HAS_UNDERSCORE_POPEN)
49+ if (HAS_UNDERSCORE_POPEN)
50+ set (PIPE_IO_FLAVOR "underscore" )
51+ endif ()
52+ if (NOT PIPE_IO_FLAVOR)
53+ check_symbol_exists(popen "stdio.h" HAS_STANDARD_POPEN)
54+ if (HAS_STANDARD_POPEN)
55+ set (PIPE_IO_FLAVOR "standard" )
56+ endif ()
57+ endif ()
58+ if (NOT PIPE_IO_FLAVOR)
59+ message (FATAL_ERROR "Couldn't determine functions for pipe open/close." )
2960 endif ()
61+
62+ # String case-insensitive compare functions
3063 if (I_STRINGS)
3164 check_symbol_exists(strcasecmp "strings.h" HAS_STRCASECMP)
65+ if (HAS_STRCASECMP)
66+ set (STRING_CASE_COMPARE_FLAVOR "strings" )
67+ endif ()
68+ endif ()
69+ if (NOT STRING_CASE_COMPARE_FLAVOR)
70+ set (STRING_CASE_COMPARE_FLAVOR "manual" )
71+ endif ()
72+
73+ if (I_PWD)
74+ check_symbol_exists(getpwent "pwd.h" HAS_GETPWENT)
3275 endif ()
3376 if (I_UNISTD)
3477 check_symbol_exists(getdomainname "unistd.h" HAS_GETDOMAINNAME)
@@ -129,15 +172,13 @@ function(configure_trn)
129172 set (SUPPORT_XTHREAD ON )
130173
131174 configure_file ("${CMAKE_CURRENT_FUNCTION_LIST_DIR} /config.h.in" include /config/config.h)
132- set (STRING_CASE_COMPARE_SOURCES "" )
133- if (NOT HAS_STRCASECMP)
134- set (STRING_CASE_COMPARE_SOURCES "string_case_compare.cpp" )
135- endif ()
175+ set (STRING_CASE_COMPARE_SOURCES_strings "" )
176+ set (STRING_CASE_COMPARE_SOURCES_manual "string_case_compare.cpp" )
177+ set (STRING_CASE_COMPARE_SOURCES ${STRING_CASE_COMPARE_SOURCES_${STRING_CASE_COMPARE_FLAVOR} } PARENT_SCOPE)
136178 if ((NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux" ) AND (NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows" ))
137179 message (FATAL_ERROR "Unknown system ${CMAKE_HOST_SYSTEM_NAME} ; expected 'Linux' or 'Windows'" )
138180 endif ()
139- configure_system_header("fdio" )
140- configure_system_header("pipe_io" )
141- configure_system_header("string_case_compare" )
142- set (STRING_CASE_COMPARE_SOURCES "${STRING_CASE_COMPARE_SOURCES} " PARENT_SCOPE)
181+ configure_flavor_header("fdio" "${FDIO_FLAVOR} " )
182+ configure_flavor_header("pipe_io" "${PIPE_IO_FLAVOR} " )
183+ configure_flavor_header("string_case_compare" "${STRING_CASE_COMPARE_FLAVOR} " )
143184endfunction ()
0 commit comments