Skip to content

Commit 58793bf

Browse files
Use system queries instead of CMAKE_HOST_SYSTEM_NAME to select alternatives
Fixes #28
1 parent 516a86a commit 58793bf

File tree

8 files changed

+59
-18
lines changed

8 files changed

+59
-18
lines changed

config/CMakeLists.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ add_library(config
1212
include/config/user_id.h
1313
cmake/config.h.in
1414
cmake/configure_trn.cmake
15-
cmake/fdio.Linux.h.in
16-
cmake/fdio.Windows.h.in
17-
cmake/pipe_io.Linux.h.in
18-
cmake/pipe_io.Windows.h.in
19-
cmake/string_case_compare.Linux.h.in
20-
cmake/string_case_compare.Windows.h.in
15+
cmake/fdio.fcntl.h.in
16+
cmake/fdio.io.h.in
17+
cmake/pipe_io.standard.h.in
18+
cmake/pipe_io.underscore.h.in
19+
cmake/string_case_compare.strings.h.in
20+
cmake/string_case_compare.manual.h.in
2121
"${CMAKE_CURRENT_BINARY_DIR}/include/config/config.h"
2222
"${CMAKE_CURRENT_BINARY_DIR}/include/config/fdio.h"
2323
"${CMAKE_CURRENT_BINARY_DIR}/include/config/pipe_io.h"

config/cmake/configure_trn.cmake

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
include(CheckIncludeFile)
22
include(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")
88
endfunction()
99

1010
function(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}")
143184
endfunction()
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)