forked from alepharchives/hiawatha
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
177 lines (157 loc) · 6.56 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
cmake_minimum_required(VERSION 3.0)
project(Hiawatha VERSION 10.7 LANGUAGES C)
# Compiler
set(CMAKE_C_FLAGS "-O2 -Wall -Wextra ${CMAKE_C_FLAGS}")
set(CMAKE_BUILD_TYPE "RelWithDebInfo")
# Options
option(ENABLE_CACHE "Enable cache support in Hiawatha." on)
option(ENABLE_IPV6 "Enable IPv6 support in Hiawatha." on)
option(ENABLE_MONITOR "Enable support for the Hiawatha Monitor." off)
option(ENABLE_RPROXY "Enable reverse proxy support in Hiawatha." on)
option(ENABLE_TLS "Enable TLS (mbed TLS) support in Hiawatha." on)
option(ENABLE_TOMAHAWK "Enable Tomahawk in Hiawatha" off)
option(ENABLE_TOOLKIT "Enable the URL toolkit in Hiawatha" on)
option(ENABLE_XSLT "Enable XSLT support in Hiawatha." on)
option(USE_SYSTEM_MBEDTLS "Use the system's mbed TLS (>=2.0.0) library." off)
# Includes
include(CMakeFiles.txt)
include(CheckIncludeFile)
include(CheckIncludeFiles)
include(CheckFunctionExists)
include(CheckLibraryExists)
include(CheckSymbolExists)
include(GNUInstallDirs)
if(ENABLE_XSLT)
include(FindLibXml2)
include(FindLibXslt)
if (NOT LIBXSLT_FOUND)
message(FATAL_ERROR "The XSLT library (libxslt1-dev) has not been found.")
return()
endif()
endif()
include(FindZLIB)
include(cmake/CopyIfNotExists.cmake)
# Settings
if(EXISTS "/proc/loadavg")
option(ENABLE_LOADCHECK "Enable the ability to check for server load." on)
endif()
set(CONFIG_DIR ${CMAKE_INSTALL_FULL_SYSCONFDIR}/hiawatha CACHE STRING "Configuration directory")
set(LOG_DIR ${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/log/hiawatha CACHE STRING "Log directory")
set(PID_DIR ${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/run CACHE STRING "PID directory")
set(WEBROOT_DIR ${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/www/hiawatha CACHE STRING "Webroot directory")
set(WORK_DIR ${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/hiawatha CACHE STRING "Work directory")
# Compiler directives
check_include_file(crypt.h HAVE_CRYPT_H)
check_include_file(arpa/inet.h HAVE_ARPA_INET_H)
check_include_files("sys/types.h;netinet/in.h" HAVE_NETINET_IN_H)
check_include_files("sys/types.h;netinet/tcp.h" HAVE_NETINET_TCP_H)
check_include_file(rpcsvc/crypt.h HAVE_RPCSVC_CRYPT_H)
check_function_exists(setenv HAVE_SETENV)
check_function_exists(unsetenv HAVE_UNSETENV)
check_function_exists(clearenv HAVE_CLEARENV)
check_function_exists(strcasecmp HAVE_STRCASECMP)
check_function_exists(strncasecmp HAVE_STRNCASECMP)
check_function_exists(strnstr HAVE_STRNSTR)
check_function_exists(strcasestr HAVE_STRCASESTR)
check_function_exists(strncasestr HAVE_STRNCASESTR)
check_library_exists(crypt crypt_r "" HAVE_CRYPT_R)
check_library_exists(crypt crypt "" HAVE_CRYPT_LIBRARY)
check_library_exists(${ZLIB_LIBRARY} gzdopen "" HAVE_Z_LIBRARY)
check_symbol_exists("SO_ACCEPTFILTER" "sys/socket.h" HAVE_ACCF)
if(HAVE_CRYPT_LIBRARY)
set(CRYPT_LIBRARY "crypt")
endif()
if(HAVE_Z_LIBRARY)
set(Z_LIBRARY ${ZLIB_LIBRARY})
include_directories(${ZLIB_INCLUDE_DIR})
endif()
if(APPLE OR CYGWIN)
set(CIFS 1)
endif()
# CPack
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
set(CPACK_SOURCE_GENERATOR "TGZ")
string(TOLOWER ${PROJECT_NAME} PROJECT_NAME)
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}")
set(CPACK_SOURCE_IGNORE_FILES "/build(/|_.*/)")
include(CPack)
# mbed TLS
if(ENABLE_TLS)
set(CMAKE_INSTALL_NAME_DIR ${CMAKE_INSTALL_FULL_LIBDIR}/hiawatha)
set(LIB_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/hiawatha)
if (APPLE)
set(CMAKE_MACOSX_RPATH ${CMAKE_MACOSX_RPATH};${CMAKE_INSTALL_FULL_LIBDIR}/hiawatha)
endif()
if(USE_SYSTEM_MBEDTLS)
message(WARNING "Make sure the mbed TLS shared library has been built with the MBEDTLS_THREADING_PTHREAD and MBEDTLS_THREADING_C flags set. Otherwise, it may crash the Hiawatha webserver.")
find_library(MBEDTLS mbedtls)
else()
option(USE_STATIC_MBEDTLS_LIBRARY "Build mbed TLS static library." off)
option(USE_SHARED_MBEDTLS_LIBRARY "Build mbed TLS shared library." on)
if (CMAKE_SYSTEM MATCHES "OpenBSD")
option(LINK_WITH_PTHREAD "Explicitly link mbed TLS library to pthread." on)
endif()
cmake_policy(SET CMP0048 NEW)
add_subdirectory(mbedtls)
endif()
set(MBEDTLS_LIBRARIES "mbedtls" "mbedx509" "mbedcrypto")
endif()
# Hiawatha
include_directories(${CMAKE_CURRENT_BINARY_DIR})
if(NOT USE_SYSTEM_MBEDTLS)
include_directories(mbedtls/include)
endif()
if(ENABLE_XSLT)
include_directories(${LIBXML2_INCLUDE_DIR} ${LIBXSLT_INCLUDE_DIR})
endif()
# Configure files
configure_file(config.h.in config.h)
foreach (configfile ${config_files_in})
configure_file(${configfile}.in ${configfile} @ONLY)
endforeach()
foreach(manpage ${manual_pages_in})
configure_file(${manpage}.in ${manpage})
endforeach()
configure_file(extra/logrotate.in logrotate.d/hiawatha)
# Binaries
add_executable(cgi-wrapper ${cgi_wrapper_src})
add_executable(hiawatha ${hiawatha_src})
add_executable(ssi-cgi ${ssi_cgi_src})
add_executable(wigwam ${wigwam_src})
target_link_libraries(cgi-wrapper ${Z_LIBRARY})
target_link_libraries(hiawatha ${CRYPT_LIBRARY} pthread ${Z_LIBRARY})
target_link_libraries(ssi-cgi ${Z_LIBRARY})
target_link_libraries(wigwam ${CRYPT_LIBRARY} ${Z_LIBRARY})
if(ENABLE_TLS)
target_link_libraries(hiawatha ${MBEDTLS_LIBRARIES})
target_link_libraries(wigwam ${MBEDTLS_LIBRARIES})
if(NOT USE_SYSTEM_MBEDTLS)
set_target_properties(hiawatha PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR}/hiawatha)
set_target_properties(wigwam PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR}/hiawatha)
endif()
endif()
if(ENABLE_XSLT)
target_link_libraries(hiawatha ${LIBXML2_LIBRARIES} ${LIBXSLT_LIBRARIES})
endif()
# Installation
install(TARGETS hiawatha wigwam DESTINATION ${CMAKE_INSTALL_SBINDIR})
install(TARGETS cgi-wrapper DESTINATION ${CMAKE_INSTALL_SBINDIR}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE SETUID)
install(TARGETS ssi-cgi DESTINATION ${CMAKE_INSTALL_BINDIR})
foreach(configfile ${config_files})
install(CODE "copy_if_not_exists(\"${CMAKE_SOURCE_DIR}/${configfile}\" \"${CONFIG_DIR}\")")
endforeach()
foreach(configfile ${config_files_in})
install(CODE "copy_if_not_exists(\"${CMAKE_CURRENT_BINARY_DIR}/${configfile}\" \"${CONFIG_DIR}\")")
endforeach()
install(FILES ${manual_pages} DESTINATION ${CMAKE_INSTALL_FULL_MANDIR}/man1)
foreach(manpage ${manual_pages_in})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${manpage} DESTINATION ${CMAKE_INSTALL_FULL_MANDIR}/man1)
endforeach()
install(FILES extra/index.html DESTINATION ${WEBROOT_DIR})
# Create directories
install(DIRECTORY DESTINATION ${LOG_DIR})
install(DIRECTORY DESTINATION ${PID_DIR})
install(DIRECTORY DESTINATION ${WORK_DIR})