-
Notifications
You must be signed in to change notification settings - Fork 100
/
CMakeLists.txt
223 lines (191 loc) · 7.63 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
if (POLICY CMP0075)
cmake_policy(SET CMP0075 NEW)
endif ()
# The following must be set BEFORE doing project() or enable_language().
if (NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type defined; defaulting to 'Debug'")
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING
"The type of build. Possible values are: Debug, Release, RelWithDebInfo and MinSizeRel.")
endif ()
set(PACKAGE "stubby")
set(PACKAGE_NAME "Stubby")
set(PACKAGE_VERSION_MAJOR 0)
set(PACKAGE_VERSION_MINOR 4)
set(PACKAGE_VERSION_RELEASE 4)
set(PACKAGE_VERSION "${PACKAGE_VERSION_MAJOR}.${PACKAGE_VERSION_MINOR}.${PACKAGE_VERSION_RELEASE}")
set(PACKAGE_BUGREPORT "[email protected]")
set(RELEASE_CANDIDATE "rc1")
set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}${RELEASE_CANDIDATE}")
set(PACKAGE_TARNAME "${PACKAGE}-${PACKAGE_VERSION}${RELEASE_CANDIDATE}")
set(STUBBY_PACKAGE "${PACKAGE}")
set(STUBBY_PACKAGE_STRING "${PACKAGE_STRING}")
if (WIN32)
option(PATCH_LEVEL_GIT "Get patch level from git." OFF)
set(STUBBY_ON_WINDOWS 1)
project (stubby VERSION ${PACKAGE_VERSION} LANGUAGES C RC)
else()
project (stubby VERSION ${PACKAGE_VERSION} LANGUAGES C)
endif()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
include(CheckIncludeFile)
include(CheckSymbolExists)
include(GNUInstallDirs)
include(CMakeDependentOption)
# Options.
find_package(Libsystemd)
if (Libsystemd_FOUND)
option(ENABLE_SYSTEMD "Enable systemd support." ON)
endif()
option(ENABLE_GETDNS_STATIC_LINK "Link GetDNS statically." ON)
if (ENABLE_GETDNS_STATIC_LINK)
set(GETDNS_STATIC ON)
endif ()
# Directories
if (DEFINED CMAKE_INSTALL_FULL_RUNSTATEDIR)
set(RUNSTATEDIR "${CMAKE_INSTALL_FULL_RUNSTATEDIR}")
else ()
set(RUNSTATEDIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/run")
endif ()
install(DIRECTORY
DESTINATION ${RUNSTATEDIR}
DIRECTORY_PERMISSIONS
OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE
)
set(STUBBYCONFDIR "${CMAKE_INSTALL_FULL_SYSCONFDIR}/stubby")
find_package(Libyaml REQUIRED)
if (STUBBY_ON_WINDOWS)
check_include_file(windows.h HAVE_WINDOWS_H)
option(ENABLE_WINDOWS_SERVICE "Enable Windows service interface." ON)
find_program(CMAKE_MC_COMPILER mc.exe DOC "path to message compiler")
if (NOT CMAKE_MC_COMPILER)
message(FATAL_ERROR "message compiler not found: required to build")
endif (NOT CMAKE_MC_COMPILER)
message(STATUS "Found message compiler: ${CMAKE_MC_COMPILER}")
mark_as_advanced(CMAKE_MC_COMPILER)
set(PACKAGE_VERSION_PATCH 0)
if (PATCH_LEVEL_GIT)
execute_process(COMMAND git describe --long OUTPUT_VARIABLE ver)
if (ver)
string(REGEX REPLACE "v[^-]*-([0-9]+)-.*" "\\1" PACKAGE_VERSION_PATCH ${ver})
endif ()
endif ()
else ()
set(ENABLE_WINDOWS_SERVICE OFF)
endif ()
check_include_file(os/log.h HAVE_OS_LOG_H)
check_include_file(inttypes.h HAVE_INTTYPES_H)
check_include_file(sys/types.h HAVE_SYS_TYPES_H)
option(ENABLE_DEBUG_ALL "Enable all debugging messages.")
cmake_dependent_option(ENABLE_DEBUG_SERVER "Enable server debugging messages." OFF "NOT ENABLE_DEBUG_ALL" ON)
set(SERVER_DEBUG ${ENABLE_DEBUG_SERVER})
check_symbol_exists(getopt "unistd.h" HAVE_GETOPT)
# Does the compiler accept the "format" attribute?
try_compile(HAVE_ATTR_FORMAT
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/cmake/tests/test_format_attr.c
)
# Does the compiler accept the "unused" attribute?
try_compile(HAVE_ATTR_UNUSED
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/cmake/tests/test_unused_attr.c
)
configure_file(cmake/include/cmakeconfig.h.in config.h)
set(ETCDIR "${STUBBYCONFDIR}")
configure_file(doc/stubby.1.in stubby.1 @ONLY)
if (STUBBY_ON_WINDOWS)
set(VER_PRODUCTVERSION "${PACKAGE_VERSION_MAJOR},${PACKAGE_VERSION_MINOR},${PACKAGE_VERSION_RELEASE},${PACKAGE_VERSION_PATCH}")
set(VER_PRODUCTVERSION_STR "${PACKAGE_VERSION}${RELEASE_CANDIDATE}")
set(PACKAGE_VERSION "${PACKAGE_VERSION_MAJOR}.${PACKAGE_VERSION_MINOR}.${PACKAGE_VERSION_RELEASE}.${PACKAGE_VERSION_PATCH}")
configure_file(src/windows/stubby.rc.in stubby.rc @ONLY)
configure_file(src/windows/stubby.ico stubby.ico COPYONLY)
configure_file(package_version.in package_version @ONLY)
if (ENABLE_WINDOWS_SERVICE)
configure_file(src/windows/stubres.rc.in stubres.rc @ONLY)
endif ()
add_custom_command(
OUTPUT service.rc service.h
MAIN_DEPENDENCY src/windows/service.mc
COMMAND ${CMAKE_MC_COMPILER}
ARGS -U
-n
-r ${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/src/windows/service.mc
)
endif ()
add_executable(stubby
src/stubby.c
src/configfile.c
src/log.c
src/server.c
src/util.c
src/yaml/convert_yaml_to_json.c
src/sldns/sbuffer.c
)
if (NOT HAVE_GETOPT)
target_sources(stubby PRIVATE src/compat/getopt.c)
target_include_directories(stubby PRIVATE src/compat)
endif ()
if (STUBBY_ON_WINDOWS)
target_sources(stubby PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/stubby.rc)
endif ()
if (ENABLE_WINDOWS_SERVICE)
target_sources(stubby PRIVATE src/windows/service.c ${CMAKE_CURRENT_BINARY_DIR}/service.h)
target_include_directories(stubby PRIVATE src/windows ${CMAKE_CURRENT_BINARY_DIR})
add_library(stubres SHARED
src/windows/stubres.c
${CMAKE_CURRENT_BINARY_DIR}/service.rc
${CMAKE_CURRENT_BINARY_DIR}/stubres.rc
)
set_property(TARGET stubres PROPERTY C_STANDARD 11)
endif()
target_include_directories(stubby PRIVATE src ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(stubby PRIVATE Libyaml::Libyaml)
if (ENABLE_SYSTEMD)
target_link_libraries(stubby PRIVATE Libsystemd::Libsystemd)
endif()
# Are we being built from getdns? If so, use the build tree getdns.
if (TARGET getdns)
target_link_libraries(stubby PRIVATE getdns)
else ()
find_package(Getdns "1.5.0" REQUIRED)
target_link_libraries(stubby PRIVATE Getdns::Getdns)
endif ()
set_property(TARGET stubby PROPERTY C_STANDARD 11)
install(TARGETS stubby RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )
if (ENABLE_WINDOWS_SERVICE)
install(TARGETS stubres LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif ()
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/stubby.1 DESTINATION share/man/man1)
install(FILES AUTHORS COPYING ChangeLog NEWS README.md DESTINATION share/doc/stubby)
# Ensure the file gets CRLF line endings on Windows.
file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/stubby.yml INPUT ${CMAKE_CURRENT_SOURCE_DIR}/stubby.yml.example)
# Copy stubby.yml to destination iff no destination file exists.
# This is complicated by (a) not being able to use generators, due to
# CMake minimum version requirement, and (b) to account for DESTDIR.
# And in the latter case, if we're adding DESTDIR to the start of the
# path, we must on Windows remove any initial drive letter. That's what
# INSTALL appears to do.
install(CODE "\
set(targetdir \"${STUBBYCONFDIR}\")\n\
set(destdir \"\$ENV{DESTDIR}\")\n\
if (destdir)\n\
string(REGEX REPLACE \"^([A-Z]:)?/(.*)\" \"\\\\2\" newtarget \"\${targetdir}\")\n\
if (newtarget)\n\
set(targetdir \"\${newtarget}\")\n\
endif ()\n\
set(targetdir \"\${destdir}/\${newtarget}\")\n\
endif ()\n\
if (NOT EXISTS \"\${targetdir}/stubby.yml\")\n\
file(COPY \"${CMAKE_CURRENT_BINARY_DIR}/stubby.yml\" DESTINATION \"\${targetdir}\")\n\
message(\"-- Installing: \${targetdir}/stubby.yml\")\n\
endif ()")
if (APPLE)
find_library(security Security REQUIRED)
add_executable(stubby-ui-helper macos/stubby-ui-helper.c)
target_include_directories(stubby-ui-helper PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(stubby-ui-helper ${security})
install(FILES macos/stubby-setdns-macos.sh DESTINATION sbin)
endif ()