| 1 |
# put in this file everything that needs to be setup depending |
| 2 |
# on the target architecture |
| 3 |
|
| 4 |
# our own modules |
| 5 |
set(CMAKE_MODULE_PATH |
| 6 |
${CMAKE_SOURCE_DIR}/cmake/Modules |
| 7 |
) |
| 8 |
|
| 9 |
# include used modules |
| 10 |
include(DefineInstallationPaths) |
| 11 |
include(CheckIncludeFileCXX) |
| 12 |
include(CheckFunctionExists) |
| 13 |
include(CheckSymbolExists) |
| 14 |
include(CheckLibraryExists) |
| 15 |
include(CheckCXXCompilerFlag) |
| 16 |
include(CheckCXXSourceCompiles) |
| 17 |
include(CheckMkdirArgs) |
| 18 |
include(CheckIncludeFiles) |
| 19 |
|
| 20 |
# setup short variable path names |
| 21 |
set(BINDIR ${BIN_INSTALL_DIR}) |
| 22 |
set(SBINDIR ${SBIN_INSTALL_DIR}) |
| 23 |
set(SYSCONFDIR ${SYSCONF_INSTALL_DIR}) |
| 24 |
set(LOCALSTATEDIR ${LOCALSTATE_INSTALL_DIR}) |
| 25 |
set(MANDIR ${MAN_INSTALL_DIR}) |
| 26 |
|
| 27 |
# set default hardcoded config paths |
| 28 |
if(WIN32) |
| 29 |
set(BNETD_DEFAULT_CONF_FILE "conf/bnetd.conf") |
| 30 |
set(D2CS_DEFAULT_CONF_FILE "conf/d2cs.conf") |
| 31 |
set(D2DBS_DEFAULT_CONF_FILE "conf/d2dbs.conf") |
| 32 |
else(WIN32) |
| 33 |
set(BNETD_DEFAULT_CONF_FILE "${SYSCONFDIR}/bnetd.conf") |
| 34 |
set(D2CS_DEFAULT_CONF_FILE "${SYSCONFDIR}/d2cs.conf") |
| 35 |
set(D2DBS_DEFAULT_CONF_FILE "${SYSCONFDIR}/d2dbs.conf") |
| 36 |
endif(WIN32) |
| 37 |
|
| 38 |
enable_language(C) |
| 39 |
# library checks |
| 40 |
find_package(ZLIB REQUIRED) |
| 41 |
check_library_exists(nsl gethostbyname "" HAVE_LIBNSL) |
| 42 |
check_library_exists(socket socket "" HAVE_LIBSOCKET) |
| 43 |
check_library_exists(resolv inet_aton "" HAVE_LIBRESOLV) |
| 44 |
check_library_exists(bind __inet_aton "" HAVE_LIBBIND) |
| 45 |
|
| 46 |
if(WITH_LUA) |
| 47 |
find_package(Lua REQUIRED) |
| 48 |
endif(WITH_LUA) |
| 49 |
|
| 50 |
# storage module checks |
| 51 |
if(WITH_ODBC) |
| 52 |
find_package(ODBC REQUIRED) |
| 53 |
endif(WITH_ODBC) |
| 54 |
if(WITH_MYSQL) |
| 55 |
find_package(MySQL REQUIRED) |
| 56 |
endif(WITH_MYSQL) |
| 57 |
if(WITH_SQLITE3) |
| 58 |
find_package(SQLite3 REQUIRED) |
| 59 |
endif(WITH_SQLITE3) |
| 60 |
if(WITH_PGSQL) |
| 61 |
find_package(PostgreSQL REQUIRED) |
| 62 |
endif(WITH_PGSQL) |
| 63 |
|
| 64 |
# if any of nsl or socket exists we need to make sure the following tests |
| 65 |
# use them otherwise some functions may not be found |
| 66 |
if(HAVE_LIBNSL) |
| 67 |
SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} nsl) |
| 68 |
SET(NETWORK_LIBRARIES ${NETWORK_LIBRARIES} nsl) |
| 69 |
endif(HAVE_LIBNSL) |
| 70 |
if(HAVE_LIBSOCKET) |
| 71 |
SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} socket) |
| 72 |
SET(NETWORK_LIBRARIES ${NETWORK_LIBRARIES} socket) |
| 73 |
endif(HAVE_LIBSOCKET) |
| 74 |
if(HAVE_LIBRESOLV) |
| 75 |
SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} resolv) |
| 76 |
SET(NETWORK_LIBRARIES ${NETWORK_LIBRARIES} resolv) |
| 77 |
endif(HAVE_LIBRESOLV) |
| 78 |
if(HAVE_LIBBIND) |
| 79 |
# this is used for BeOS BONE, when someone will want |
| 80 |
# to test pvpgn with cmake on BeOS please contact us |
| 81 |
SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} bind) |
| 82 |
SET(NETWORK_LIBRARIES ${NETWORK_LIBRARIES} bind) |
| 83 |
endif(HAVE_LIBBIND) |
| 84 |
|
| 85 |
# for win32 unconditionally add network library linking to "ws2_32" |
| 86 |
if(WIN32) |
| 87 |
SET(NETWORK_LIBRARIES ${NETWORK_LIBRARIES} ws2_32) |
| 88 |
endif(WIN32) |
| 89 |
|
| 90 |
|
| 91 |
message(STATUS "Checking POSIX headers") |
| 92 |
check_include_file_cxx(arpa/inet.h HAVE_ARPA_INET_H) |
| 93 |
check_include_file_cxx(dirent.h HAVE_DIRENT_H) |
| 94 |
check_include_file_cxx(grp.h HAVE_GRP_H) |
| 95 |
check_include_file_cxx(fcntl.h HAVE_FCNTL_H) |
| 96 |
check_include_file_cxx(netdb.h HAVE_NETDB_H) |
| 97 |
check_include_file_cxx(netinet/in.h HAVE_NETINET_IN_H) |
| 98 |
check_include_file_cxx(poll.h HAVE_POLL_H) |
| 99 |
check_include_file_cxx(pwd.h HAVE_PWD_H) |
| 100 |
check_include_file_cxx(sys/mman.h HAVE_SYS_MMAN_H) |
| 101 |
check_include_file_cxx(sys/resource.h HAVE_SYS_RESOURCE_H) |
| 102 |
check_include_file_cxx(sys/select.h HAVE_SYS_SELECT_H) |
| 103 |
check_include_file_cxx(sys/socket.h HAVE_SYS_SOCKET_H) |
| 104 |
check_include_file_cxx(sys/stat.h HAVE_SYS_STAT_H) |
| 105 |
check_include_file_cxx(sys/time.h HAVE_SYS_TIME_H) |
| 106 |
check_include_file_cxx(sys/types.h HAVE_SYS_TYPES_H) |
| 107 |
check_include_file_cxx(sys/utsname.h HAVE_SYS_UTSNAME_H) |
| 108 |
check_include_file_cxx(sys/wait.h HAVE_SYS_WAIT_H) |
| 109 |
check_include_file_cxx(termios.h HAVE_TERMIOS_H) |
| 110 |
check_include_file_cxx(unistd.h HAVE_UNISTD_H) |
| 111 |
|
| 112 |
message(STATUS "Checking optional POSIX/required SUS headers") |
| 113 |
check_include_file_cxx(sys/timeb.h HAVE_SYS_TIMEB_H) |
| 114 |
|
| 115 |
message(STATUS "Checking FreeBSD-based headers") |
| 116 |
check_include_files("sys/types.h;sys/event.h" HAVE_SYS_EVENT_H) |
| 117 |
check_include_file_cxx(sys/param.h HAVE_SYS_PARAM_H) |
| 118 |
|
| 119 |
message(STATUS "Checking BSD headers") |
| 120 |
check_include_file_cxx(sys/file.h HAVE_SYS_FILE_H) |
| 121 |
|
| 122 |
message(STATUS "Checking Linux headers") |
| 123 |
check_include_file_cxx(sys/epoll.h HAVE_SYS_EPOLL_H) |
| 124 |
|
| 125 |
message(STATUS "Checking Win32 headers") |
| 126 |
check_include_file_cxx(windows.h HAVE_WINDOWS_H) |
| 127 |
check_include_file_cxx(winsock2.h HAVE_WINSOCK2_H) |
| 128 |
check_include_file_cxx(ws2tcpip.h HAVE_WS2TCPIP_H) |
| 129 |
check_include_file_cxx(process.h HAVE_PROCESS_H) |
| 130 |
|
| 131 |
message(STATUS "Checking other headers") |
| 132 |
check_include_file_cxx(dir.h HAVE_DIR_H) |
| 133 |
check_include_file_cxx(direct.h HAVE_DIRECT_H) |
| 134 |
check_include_file_cxx(ndir.h HAVE_NDIR_H) |
| 135 |
check_include_file_cxx(sys/dir.h HAVE_SYS_DIR_H) |
| 136 |
check_include_file_cxx(sys/ndir.h HAVE_SYS_NDIR_H) |
| 137 |
check_include_file_cxx(sys/poll.h HAVE_SYS_POLL_H) |
| 138 |
|
| 139 |
check_function_exists(chdir HAVE_CHDIR) |
| 140 |
check_function_exists(epoll_create HAVE_EPOLL_CREATE) |
| 141 |
check_function_exists(fork HAVE_FORK) |
| 142 |
check_function_exists(ftime HAVE_FTIME) |
| 143 |
check_function_exists(getgid HAVE_GETGID) |
| 144 |
check_function_exists(getgrnam HAVE_GETGRNAM) |
| 145 |
check_function_exists(getlogin HAVE_GETLOGIN) |
| 146 |
check_function_exists(getopt HAVE_GETOPT) |
| 147 |
check_function_exists(getpid HAVE_GETPID) |
| 148 |
check_function_exists(getpwnam HAVE_GETPWNAME) |
| 149 |
check_function_exists(getrlimit HAVE_GETRLIMIT) |
| 150 |
check_function_exists(gettimeofday HAVE_GETTIMEOFDAY) |
| 151 |
check_function_exists(getuid HAVE_GETUID) |
| 152 |
check_function_exists(ioctl HAVE_IOCTL) |
| 153 |
check_function_exists(kqueue HAVE_KQUEUE) |
| 154 |
check_function_exists(_mkdir HAVE__MKDIR) |
| 155 |
check_function_exists(mkdir HAVE_MKDIR) |
| 156 |
check_function_exists(mmap HAVE_MMAP) |
| 157 |
check_function_exists(pipe HAVE_PIPE) |
| 158 |
check_function_exists(poll HAVE_POLL) |
| 159 |
check_function_exists(setitimer HAVE_SETITIMER) |
| 160 |
check_function_exists(setpgid HAVE_SETPGID) |
| 161 |
check_function_exists(setpgrp HAVE_SETPGRP) |
| 162 |
check_function_exists(setsid HAVE_SETSID) |
| 163 |
check_function_exists(setuid HAVE_SETUID) |
| 164 |
check_function_exists(sigaction HAVE_SIGACTION) |
| 165 |
check_function_exists(sigaddset HAVE_SIGADDSET) |
| 166 |
check_function_exists(sigprocmask HAVE_SIGPROCMASK) |
| 167 |
check_function_exists(strcasecmp HAVE_STRCASECMP) |
| 168 |
check_function_exists(strdup HAVE_STRDUP) |
| 169 |
check_function_exists(stricmp HAVE_STRICMP) |
| 170 |
check_function_exists(strncasecmp HAVE_STRNCASECMP) |
| 171 |
check_function_exists(strnicmp HAVE_STRNICMP) |
| 172 |
check_function_exists(strsep HAVE_STRSEP) |
| 173 |
check_function_exists(uname HAVE_UNAME) |
| 174 |
check_function_exists(wait HAVE_WAIT) |
| 175 |
check_function_exists(waitpid HAVE_WAITPID) |
| 176 |
|
| 177 |
CHECK_CXX_SOURCE_COMPILES( |
| 178 |
" |
| 179 |
#include <memory> |
| 180 |
int main() { |
| 181 |
auto foo = std::make_unique<int>(1); |
| 182 |
return 0; |
| 183 |
} |
| 184 |
" HAVE_MAKE_UNIQUE) |
| 185 |
|
| 186 |
|
| 187 |
# winsock2.h and ws2_32 should provide these |
| 188 |
if(HAVE_WINSOCK2_H) |
| 189 |
set(HAVE_GETHOSTNAME ON) |
| 190 |
set(HAVE_SELECT ON) |
| 191 |
set(HAVE_SOCKET ON) |
| 192 |
set(HAVE_RECV ON) |
| 193 |
set(HAVE_SEND ON) |
| 194 |
set(HAVE_RECVFROM ON) |
| 195 |
set(HAVE_SENDTO ON) |
| 196 |
set(HAVE_GETHOSTBYNAME ON) |
| 197 |
set(HAVE_GETSERVBYNAME ON) |
| 198 |
else(HAVE_WINSOCK2_H) |
| 199 |
check_function_exists(gethostname HAVE_GETHOSTNAME) |
| 200 |
check_function_exists(select HAVE_SELECT) |
| 201 |
check_function_exists(socket HAVE_SOCKET) |
| 202 |
check_function_exists(recv HAVE_RECV) |
| 203 |
check_function_exists(send HAVE_SEND) |
| 204 |
check_function_exists(recvfrom HAVE_RECVFROM) |
| 205 |
check_function_exists(sendto HAVE_SENDTO) |
| 206 |
check_function_exists(gethostbyname HAVE_GETHOSTBYNAME) |
| 207 |
check_function_exists(getservbyname HAVE_GETSERVBYNAME) |
| 208 |
endif(HAVE_WINSOCK2_H) |
| 209 |
|
| 210 |
check_mkdir_args(MKDIR_TAKES_ONE_ARG) |
| 211 |
|
| 212 |
configure_file(config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h) |
| 213 |
|
| 214 |
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") |
| 215 |
# using Visual Studio |
| 216 |
|
| 217 |
add_definitions( |
| 218 |
-D_CRT_SECURE_NO_DEPRECATE |
| 219 |
-D_CRT_NONSTDC_NO_DEPRECATE |
| 220 |
-DUNICODE |
| 221 |
-D_UNICODE |
| 222 |
) |
| 223 |
endif() |