Skip to content

Commit c34bf91

Browse files
committed
cmake: improve: configure proxyres_config.h for preprocessor conditions
1 parent 2bd7289 commit c34bf91

8 files changed

Lines changed: 48 additions & 14 deletions

File tree

CMakeLists.txt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ set(PROXYRES_HDRS
4040
include/proxyres/config.h
4141
include/proxyres/log.h
4242
include/proxyres/proxyres.h
43-
include/proxyres/resolver.h)
43+
include/proxyres/resolver.h
44+
${PROJECT_BINARY_DIR}/proxyres_config.h)
4445
if(PROXYRES_EXECUTE)
4546
list(APPEND PROXYRES_HDRS
4647
include/proxyres/execute.h)
@@ -254,24 +255,25 @@ if(PROXYRES_USE_CXX)
254255
endif()
255256
endif()
256257

258+
if(NOT WIN32)
259+
check_include_file("net/if_arp.h" HAVE_NET_IF_ARP_H)
260+
check_include_file("netdb.h" HAVE_NETDB_H)
261+
endif()
262+
263+
configure_file(proxyres_config.h.in proxyres_config.h @ONLY NEWLINE_STYLE UNIX)
264+
257265
add_library(proxyres ${PROXYRES_HDRS} ${PROXYRES_SRCS} ${PROXYRES_C_SRCS})
258266
set_property(TARGET proxyres PROPERTY C_STANDARD 11 CXX_STANDARD 11)
259267
if(PROXYRES_BUILD_TESTS)
260268
target_compile_definitions(proxyres PRIVATE PROXYRES_TESTING)
261269
endif()
262270
target_include_directories(proxyres PRIVATE
263271
${CMAKE_CURRENT_SOURCE_DIR}
264-
${CMAKE_CURRENT_SOURCE_DIR}/include/proxyres)
272+
${CMAKE_CURRENT_SOURCE_DIR}/include/proxyres
273+
${PROJECT_BINARY_DIR})
265274
target_include_directories(proxyres PUBLIC
266275
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
267276

268-
if(NOT WIN32)
269-
check_include_file("net/if_arp.h" HAVE_NET_IF_ARP_H)
270-
if(HAVE_NET_IF_ARP_H)
271-
target_compile_definitions(proxyres PRIVATE HAVE_NET_IF_ARP_H)
272-
endif()
273-
endif()
274-
275277
if(PROXYRES_CURL AND (PROXYRES_EXECUTE OR PROXYRES_BUILD_CLI))
276278
if(NOT TARGET CURL::libcurl)
277279
include(FetchContent)

fetch_posix.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include "proxyres_config.h"
2+
13
#include <stdint.h>
24
#include <stdbool.h>
35
#include <stdlib.h>
@@ -6,13 +8,16 @@
68
#include <string.h>
79
#include <errno.h>
810

11+
#if HAVE_NETDB_H
12+
# include <netdb.h>
13+
#endif
14+
915
#ifdef _WIN32
1016
# include <winsock2.h>
1117
# include <ws2tcpip.h>
1218
#else
1319
# include <sys/types.h>
1420
# include <sys/socket.h>
15-
# include <netdb.h>
1621
# include <unistd.h>
1722
#endif
1823

net_adapter_linux.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1+
#include "proxyres_config.h"
2+
13
#include <stdint.h>
24
#include <stdbool.h>
35
#include <stdlib.h>
46
#include <stdio.h>
57
#include <string.h>
68

9+
#if HAVE_NETDB_H
10+
# include <netdb.h>
11+
#endif
12+
713
#include <sys/types.h>
814
#include <sys/socket.h>
9-
#include <netdb.h>
1015
#include <unistd.h>
1116
#include <ifaddrs.h>
1217
#include <net/if.h>

net_adapter_mac.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include "proxyres_config.h"
2+
13
#include <stdint.h>
24
#include <stdbool.h>
35
#include <stdlib.h>

net_util.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include "proxyres_config.h"
2+
13
#include <stdint.h>
24
#include <stdbool.h>
35
#include <stddef.h>
@@ -6,14 +8,17 @@
68
#include <string.h>
79
#include <errno.h>
810

11+
#if HAVE_NETDB_H
12+
# include <netdb.h>
13+
#endif
14+
915
#ifdef _WIN32
1016
# include <winsock2.h>
1117
# include <ws2tcpip.h>
1218
#else
1319
# include <arpa/inet.h>
1420
# include <sys/types.h>
1521
# include <sys/socket.h>
16-
# include <netdb.h>
1722
# include <unistd.h>
1823
#endif
1924

proxyres_config.h.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Define to 1 if you have the <net/if_arp.h> header file.
2+
#cmakedefine HAVE_NET_IF_ARP_H 1
3+
4+
// Define to 1 if you have the <netdb.h> header file.
5+
#cmakedefine HAVE_NETDB_H 1

wpad_dhcp_posix.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include "proxyres_config.h"
2+
13
#include <stdint.h>
24
#include <stdbool.h>
35
#include <stdlib.h>
@@ -7,6 +9,10 @@
79
#include <time.h>
810
#include <errno.h>
911

12+
#if HAVE_NETDB_H
13+
# include <netdb.h>
14+
#endif
15+
1016
#ifdef _WIN32
1117
# include <winsock2.h>
1218
# include <ws2tcpip.h>
@@ -15,7 +21,6 @@
1521
# include <arpa/inet.h>
1622
# include <sys/types.h>
1723
# include <sys/socket.h>
18-
# include <netdb.h>
1924
# include <unistd.h>
2025
#endif
2126

wpad_dns.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include "proxyres_config.h"
2+
13
#include <stdint.h>
24
#include <stdbool.h>
35
#include <stdio.h>
@@ -6,14 +8,17 @@
68
#include <string.h>
79
#include <errno.h>
810

11+
#if HAVE_NETDB_H
12+
# include <netdb.h>
13+
#endif
14+
915
#ifdef _WIN32
1016
# include <winsock2.h>
1117
# include <ws2tcpip.h>
1218
# include <windows.h>
1319
#else
1420
# include <sys/types.h>
1521
# include <sys/socket.h>
16-
# include <netdb.h>
1722
# include <unistd.h>
1823
#endif
1924

0 commit comments

Comments
 (0)