Skip to content

Commit 67fac0e

Browse files
committed
Separate CMake and Autoconf logic
1 parent 4b7f717 commit 67fac0e

File tree

6 files changed

+63
-45
lines changed

6 files changed

+63
-45
lines changed

CMakeLists.txt

+16-38
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,27 @@ target_include_directories(
168168
target_link_libraries(zone-bench PRIVATE zone)
169169

170170
check_include_file(endian.h HAVE_ENDIAN_H)
171-
172171
check_include_file(unistd.h HAVE_UNISTD_H)
173-
check_symbol_exists(getopt "stdio.h;unistd.h" HAVE_GETOPT)
174-
if(NOT HAVE_UNISTD_H OR NOT HAVE_GETOPT)
172+
173+
set(CMAKE_REQUIRED_DEFINITIONS "-D_DEFAULT_SOURCE")
174+
check_symbol_exists(getopt "stdlib.h;unistd.h" HAVE_GETOPT)
175+
unset(CMAKE_REQUIRED_DEFINITIONS)
176+
if(NOT HAVE_GETOPT)
175177
target_include_directories(
176178
zone-bench PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/compat>)
177179
target_sources(zone-bench PRIVATE compat/getopt.c)
178180
endif()
179181

182+
if(NOT WIN32)
183+
# _fullpath is used on Microsoft Windows.
184+
set(CMAKE_REQUIRED_DEFINITIONS "-D_DEFAULT_SOURCE")
185+
check_symbol_exists(realpath "stdlib.h" HAVE_REALPATH)
186+
unset(CMAKE_REQUIRED_DEFINITIONS)
187+
if(NOT HAVE_REALPATH)
188+
message(FATAL_ERROR "realpath is not available")
189+
endif()
190+
endif()
191+
180192
# Multiple instruction sets may be supported by a specific architecture.
181193
# e.g. x86_64 may (or may not) support any of SSE42, AVX2 and AVX-512. The
182194
# best instruction set is automatically selected at runtime, but the compiler
@@ -223,41 +235,7 @@ if(architecture STREQUAL "x86_64" OR architecture STREQUAL "amd64")
223235
endif()
224236

225237

226-
# Autoconf is supported for easy inclusion of simdzone in NSD. To avoid having
227-
# to maintain multiple configuration headers, instead of using configure_file,
228-
# read configure.ac and replace occurences of "AC_SUBST([<define>])". If an
229-
# instance of AC_SUBST does not match expectations, throw an error.
230-
file(READ configure.ac template)
231-
232-
set(pattern "(^|\n)[ \t]*AC_SUBST\([^\n]*)[ \t]*(\n|$)")
233-
string(REGEX MATCHALL "${pattern}" matches "${template}")
234-
foreach(match ${matches})
235-
if (match MATCHES "[ \t]*AC_SUBST\\(\\[([a-zA-Z0-9_]+)\\]\\)[ \t]*")
236-
set(variable "${CMAKE_MATCH_1}")
237-
# Ignore any variables that do not start with HAVE_
238-
if (variable MATCHES "^HAVE_")
239-
if(NOT DEFINED ${variable} OR NOT ${variable} OR
240-
${variable} MATCHES "^[Ff][Aa][Ll][Ss][Ee]$" OR
241-
${variable} MATCHES "^[Oo][Ff][Ff]")
242-
string(APPEND header "/* #undef ${variable} */\n")
243-
elseif(${variable} MATCHES "^[Tt][Rr][Uu][Ee]$" OR
244-
${variable} MATCHES "^[Oo][Nn]$")
245-
string(APPEND header "#define ${variable} 1\n")
246-
elseif(${variable} MATCHES "^[01234567890]+$")
247-
string(APPEND header "#define ${variable} ${${variable}}\n")
248-
else()
249-
string(APPEND header "#define ${variable} \"${${variable}}\"\n")
250-
endif()
251-
else()
252-
continue()
253-
endif()
254-
255-
else()
256-
message(FATAL_ERROR "Found AC_SUBST that not match expression")
257-
endif()
258-
endforeach()
259-
260-
file(GENERATE OUTPUT config.h CONTENT "${header}")
238+
configure_file(src/config.h.in config.h)
261239

262240
if(BUILD_TESTING)
263241
add_subdirectory(tests)

configure.ac

+10-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ AC_CONFIG_FILES([Makefile])
1818
m4_include(m4/ax_check_compile_flag.m4)
1919
m4_version_prereq([2.70], [AC_PROG_CC], [AC_PROG_CC_STDC])
2020

21-
AC_CHECK_HEADER(endian.h, AC_DEFINE(HAVE_ENDIAN_H, 1, [Wether or not have the <endian.h> header file]))
21+
AC_CHECK_HEADER(endian.h, AC_DEFINE(HAVE_ENDIAN_H, 1, [Define to 1 if you have the <endian.h> header file.]))
2222

2323
AC_ARG_ENABLE(westmere, AS_HELP_STRING([--disable-westmere],[Disable Westmere (SSE4.2) kernel]))
2424
case "$enable_westmere" in
@@ -95,8 +95,17 @@ if test $x86_64 = "yes"; then
9595
fi
9696
fi
9797

98+
AC_CHECK_FUNCS([realpath],,[AC_MSG_ERROR([realpath is not available])])
99+
98100
AC_SUBST([HAVE_ENDIAN_H])
99101
AC_SUBST([HAVE_WESTMERE])
100102
AC_SUBST([HAVE_HASWELL])
101103

104+
AH_BOTTOM([
105+
/* Defines _XOPEN_SOURCE and _POSIX_C_SOURCE implicitly in features.h */
106+
#ifndef _DEFAULT_SOURCE
107+
# define _DEFAULT_SOURCE 1
108+
#endif
109+
])
110+
102111
AC_OUTPUT

src/config.h.in

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* config.h.in -- comment
3+
*
4+
* Copyright (c) 2024, NLnet Labs. All rights reserved.
5+
*
6+
* SPDX-License-Identifier: BSD-3-Clause
7+
*
8+
*/
9+
#ifndef CONFIG_H
10+
#define CONFIG_H
11+
12+
/* Define to 1 if you have the <endian.h> header file. */
13+
#cmakedefine HAVE_ENDIAN_H 1
14+
15+
/* Define to 1 if you have the `getopt' function. */
16+
#cmakedefine HAVE_GETOPT 1
17+
18+
/* Wether or not to compile support for AVX2 */
19+
#cmakedefine HAVE_HASWELL 1
20+
21+
/* Wether or not to compile support for SSE4.2 */
22+
#cmakedefine HAVE_WESTMERE 1
23+
24+
/* Defines _XOPEN_SOURCE and _POSIX_C_SOURCE implicitly in features.h */
25+
#ifndef _DEFAULT_SOURCE
26+
# define _DEFAULT_SOURCE 1
27+
#endif
28+
29+
#endif // CONFIG_H

src/generic/endian.h

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
#include "config.h"
1313

14+
// https://www.austingroupbugs.net/view.php?id=162#c665
15+
1416
#if _WIN32
1517
#include <stdlib.h>
1618

src/zone.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* SPDX-License-Identifier: BSD-3-Clause
77
*
88
*/
9+
#include "config.h"
10+
911
#include <assert.h>
1012
#include <errno.h>
1113
#include <string.h>
@@ -38,7 +40,6 @@ typedef zone_file_t file_t;
3840

3941
static const char not_a_file[] = "<string>";
4042

41-
#include "config.h"
4243
#include "isadetection.h"
4344

4445
#ifndef PATH_MAX

tests/include.c

+4-5
Original file line numberDiff line numberDiff line change
@@ -526,11 +526,10 @@ void include_relative(void **state)
526526
options.default_class = 1;
527527
options.include_limit = 1;
528528

529-
#if _WIN32
530-
int pid = _getpid();
531-
#else
532-
pid_t pid = getpid();
533-
#endif
529+
diagnostic_push()
530+
msvc_diagnostic_ignored(4996)
531+
unsigned int pid = getpid();
532+
diagnostic_pop()
534533

535534
char* inc1file = "content.inc";
536535
char* inc2file = "example.com.zone";

0 commit comments

Comments
 (0)