From 7196c012a6add03ded17fe0854e3148b6abfa4aa Mon Sep 17 00:00:00 2001 From: Thomas Arp <357770+welcor@users.noreply.github.com> Date: Mon, 21 Apr 2025 00:17:17 +0200 Subject: [PATCH] First cmake list file, simple docs. TODO: utils folder. --- .gitignore | 2 - CMakeLists.txt | 184 ++++++++++++++ build/create_solution.bat | 1 - doc/README.CMAKE.md | 65 +++++ build/README.md => doc/README.MSVC2022 | 34 ++- src/conf.h.cmake.in | 337 +++++++++++++++++++++++++ 6 files changed, 606 insertions(+), 17 deletions(-) create mode 100644 CMakeLists.txt delete mode 100644 build/create_solution.bat create mode 100644 doc/README.CMAKE.md rename build/README.md => doc/README.MSVC2022 (60%) create mode 100644 src/conf.h.cmake.in diff --git a/.gitignore b/.gitignore index e671ea7..cfd7ef3 100644 --- a/.gitignore +++ b/.gitignore @@ -11,8 +11,6 @@ src/.accepted src/depend src/util/depend build/* -!build/create_solution.bat -!build/README.md # Do not commit files from players lib/plrfiles/A-E/* diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..1301dff --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,184 @@ +cmake_minimum_required(VERSION 3.12) +project(TbaMUD C) + +set(CMAKE_C_STANDARD 99) + +# Include checker modules +include(CheckFunctionExists) +include(CheckIncludeFile) +include(CheckTypeSize) +include(CheckStructHasMember) +include(CheckSymbolExists) +include(CheckCSourceCompiles) + +# Output paths +set(BIN_OUTPUT_DIR ${CMAKE_SOURCE_DIR}/bin) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BIN_OUTPUT_DIR}) + +# Include source and build paths +include_directories(src ${CMAKE_BINARY_DIR}) + +# ========== Compiler flags ========== +if (CMAKE_COMPILER_IS_GNUCC) + include(CheckCCompilerFlag) + + check_c_compiler_flag(-Wall SUPPORTS_WALL) + check_c_compiler_flag(-Wno-char-subscripts SUPPORTS_WNO_CHAR_SUBSCRIPTS) + + if (SUPPORTS_WALL) + set(MYFLAGS "-Wall") + if (SUPPORTS_WNO_CHAR_SUBSCRIPTS) + set(MYFLAGS "${MYFLAGS} -Wno-char-subscripts") + endif() + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${MYFLAGS}") + endif() +endif() + +# ========== Header checks ========== +check_include_file("fcntl.h" HAVE_FCNTL_H) +check_include_file("errno.h" HAVE_ERRNO_H) +check_include_file("string.h" HAVE_STRING_H) +check_include_file("strings.h" HAVE_STRINGS_H) +check_include_file("limits.h" HAVE_LIMITS_H) +check_include_file("sys/time.h" HAVE_SYS_TIME_H) +check_include_file("sys/select.h" HAVE_SYS_SELECT_H) +check_include_file("sys/types.h" HAVE_SYS_TYPES_H) +check_include_file("unistd.h" HAVE_UNISTD_H) +check_include_file("memory.h" HAVE_MEMORY_H) +check_include_file("assert.h" HAVE_ASSERT_H) +check_include_file("arpa/telnet.h" HAVE_ARPA_TELNET_H) +check_include_file("arpa/inet.h" HAVE_ARPA_INET_H) +check_include_file("sys/stat.h" HAVE_SYS_STAT_H) +check_include_file("sys/socket.h" HAVE_SYS_SOCKET_H) +check_include_file("sys/resource.h" HAVE_SYS_RESOURCE_H) +check_include_file("netinet/in.h" HAVE_NETINET_IN_H) +check_include_file("netdb.h" HAVE_NETDB_H) +check_include_file("signal.h" HAVE_SIGNAL_H) +check_include_file("sys/uio.h" HAVE_SYS_UIO_H) +check_include_file("mcheck.h" HAVE_MCHECK_H) + +# macro for checking for functions in libraries +macro(check_function_with_libx FUNCTION LIB VARIABLE) + check_function_exists(${FUNCTION} ${VARIABLE}) + if (NOT ${VARIABLE}) + find_library(_libpath ${LIB}) + if (_libpath) + message(STATUS "${FUNCTION} not available, trying library: ${_libpath}") + set(_saved_libs ${CMAKE_REQUIRED_LIBRARIES}) + set(CMAKE_REQUIRED_LIBRARIES ${_libpath}) + check_function_exists(${FUNCTION} ${VARIABLE}) + if (VARIABLE) + message(STATUS "...including library ${_libpath} to get access to ${FUNCTION}.") + list(APPEND EXTRA_LIBS ${_libpath}) + else() + message(STATUS "...but didn't find it!") + endif() + set(CMAKE_REQUIRED_LIBRARIES ${_saved_libs}) + else() + message(STATUS "Library ${LIB} not available - ${FUNCTION}() undefined.") + endif() + endif() +endmacro() + +macro(check_function_with_lib FUNCTION LIBNAME VARIABLE) + check_function_exists(${FUNCTION} ${VARIABLE}) + if (NOT ${VARIABLE}) + + find_library(_FOUND_LIB-${LIBNAME} ${LIBNAME}) + if (_FOUND_LIB-${LIBNAME}) + message(STATUS "${FUNCTION} not found without lib, trying with: ${_FOUND_LIB-${LIBNAME}}") + set(_saved_libs ${CMAKE_REQUIRED_LIBRARIES}) + set(CMAKE_REQUIRED_LIBRARIES ${_FOUND_LIB-${LIBNAME}}) + + set(_code " + #include + int main() { + (void)${FUNCTION}; + return 0; + } + ") + + # Testkildekoden + check_c_source_compiles("${_code}" ${VARIABLE}) + if (${VARIABLE}) + message(STATUS "Found ${FUNCTION} using ${_FOUND_LIB-${LIBNAME}}") + list(APPEND EXTRA_LIBS ${_FOUND_LIB-${LIBNAME}}) + else() + message(STATUS "${FUNCTION} still not found with ${_FOUND_LIB-${LIBNAME}}") + endif() + set(CMAKE_REQUIRED_LIBRARIES ${_saved_libs}) + else() + message(STATUS "Could not find library ${LIBNAME} to try ${FUNCTION}") + endif() + endif() +endmacro() + + +# ========== Function checks ========== +foreach(FUNC gettimeofday select snprintf strcasecmp strdup strerror + stricmp strlcpy strncasecmp strnicmp strstr vsnprintf + inet_addr inet_aton) + check_function_exists(${FUNC} HAVE_${FUNC}) +endforeach() + +# ========== Type checks ========== +check_type_size("pid_t" HAVE_PID_T) +check_type_size("size_t" HAVE_SIZE_T) +check_type_size("ssize_t" HAVE_SSIZE_T) +check_type_size("socklen_t" HAVE_SOCKLEN_T) + +# ========== Struct checks ========== +if (HAVE_NETINET_IN_H) + check_struct_has_member("struct in_addr" s_addr netinet/in.h HAVE_STRUCT_IN_ADDR) +endif() + +# ========== crypt()/libcrypt ========== +find_library(CRYPT_LIBRARY crypt) +if (CRYPT_LIBRARY) + message(STATUS "Found libcrypt: ${CRYPT_LIBRARY}") + list(APPEND EXTRA_LIBS ${CRYPT_LIBRARY}) + set(CMAKE_REQUIRED_LIBRARIES ${CRYPT_LIBRARY}) +endif() + +# ========== Ekstra nettverkslibs ========== +check_function_exists(gethostbyaddr HAVE_GETHOSTBYADDR) +if (NOT HAVE_GETHOSTBYADDR) + message(STATUS "gethostbyaddr() not available, trying nsllib") + find_library(NSL_LIBRARY nsl) + if (NSL_LIBRARY) + message(STATUS "...nsllib found.") + list(APPEND EXTRA_LIBS ${NSL_LIBRARY}) + endif() +endif() + +check_function_exists(socket HAVE_SOCKET) +if (NOT HAVE_SOCKET) + message(STATUS "socket() not available, trying socketlib") + find_library(SOCKET_LIBRARY socket) + if (SOCKET_LIBRARY) + message(STATUS "...socketlib found") + list(APPEND EXTRA_LIBS ${SOCKET_LIBRARY}) + endif() +endif() + +# ========== Define generelt UNIX-system ========== +set(CIRCLE_UNIX 1) + +# ========== Generate conf.h ========== +configure_file( + ${CMAKE_SOURCE_DIR}/src/conf.h.cmake.in + ${CMAKE_BINARY_DIR}/conf.h +) + +# ========== Source-filer ========== +file(GLOB SRC_FILES src/*.c) + +# ========== Bygg kjørbar ========== +add_executable(circle ${SRC_FILES}) +target_link_libraries(circle ${EXTRA_LIBS}) + + +if (MEMORY_DEBUG) + message(STATUS "MEMORY_DEBUG is activated, setting up zmalloc") + target_compile_definitions(circle PRIVATE MEMORY_DEBUG) +endif() diff --git a/build/create_solution.bat b/build/create_solution.bat deleted file mode 100644 index ab60043..0000000 --- a/build/create_solution.bat +++ /dev/null @@ -1 +0,0 @@ -cmake -B . -S ..\src -G "Visual Studio 17 2022" \ No newline at end of file diff --git a/doc/README.CMAKE.md b/doc/README.CMAKE.md new file mode 100644 index 0000000..92dc867 --- /dev/null +++ b/doc/README.CMAKE.md @@ -0,0 +1,65 @@ +Updated 2025-04 + +## Building TbaMUD with the cmake tool + +# Building with CMake + +This document describes how to configure, build and install tbamud +from source code using the CMake build tool. To build with CMake, you of +course first have to install CMake. The minimum required version of CMake is +specified in the file `CMakeLists.txt` found in the top of the tbamud source +tree. Once the correct version of CMake is installed you can follow the +instructions below for the platform you are building on. + +CMake builds can be configured either from the command line, or from one of +CMake's GUIs. + +# Configuring + +A CMake configuration of tbamud is similar to the autotools build of curl. +It consists of the following steps after you have unpacked the source. + +We recommend building with CMake on Windows. + +## Using `cmake` + +You can configure for in source tree builds or for a build tree +that is apart from the source tree. + +- Build in a separate directory (parallel to the source tree in this + example). The build directory is created for you. This is recommended over + building in the source tree to separate source and build artifacts. + + $ cmake -B build -S . + +- Build in the source tree. Not recommended. + + $ cmake -B . + +The above commands will generate the build files. If you need to regenerate +the files, you can delete the cmake cache file, and rerun the above command: + + $ rm build/CMakeCache.txt + +Once the build files are generated, the build is run with cmake + + $ cmake --build build + # or, if + $ cmake --build . + +This will generate the object files in a subdirectory under the specified +build folder and link the executable. The resulting binaries will be in the +bin/ folder. + +### Debugging memory + +In case you want to run the mud with memory debugging turned on, you +can set the MEMORY_DEBUG flag during configuration by specifying the +flag: + + $ cmake -B build -S . -DMEMORY_DEBUG:int=1 + $ cmake --build build + +When the mud is shut down, the zmalloc code will identify any leaks in your code. +Note that memory debugging may consume quite a lot of memory and take some time +to be handled on shutdown. \ No newline at end of file diff --git a/build/README.md b/doc/README.MSVC2022 similarity index 60% rename from build/README.md rename to doc/README.MSVC2022 index bd84d9a..7cca485 100644 --- a/build/README.md +++ b/doc/README.MSVC2022 @@ -1,15 +1,21 @@ -### Overview -This guide describes how to build TbaMUD in the Visual Studio through the new experimental CMake environment. - -### Prerequisites -* [Visual Studio 2022+](https://visualstudio.microsoft.com/ru/vs/) -* [CMake 3.27+](https://cmake.org/) - -### Build Steps -1. Goto the folder `src` and copy `conf.h.win` to `conf.h`. - -2. Goto the folder `build` and execute `create_solution.bat`. - -3. Open `build/circle.sln` in Visual Studio. - +Updated: Apr 2025 + Compiling CircleMUD under Microsoft Windows XP + using Microsoft Visual C++ 2022 (8.0) + +### Overview +This guide describes how to build TbaMUD in the Visual Studio through the new experimental CMake environment. + +### Prerequisites +* [Visual Studio 2022+](https://visualstudio.microsoft.com/ru/vs/) +* [CMake 3.27+](https://cmake.org/) + +### Build Steps +1. Goto the folder `src` and copy `conf.h.win` to `conf.h`. + +2. Run this command in the root folder: + + cmake -B build -S . -G "Visual Studio 17 2022" + +3. Open `build/circle.sln` in Visual Studio. + 4. Compile and run. \ No newline at end of file diff --git a/src/conf.h.cmake.in b/src/conf.h.cmake.in new file mode 100644 index 0000000..e24705f --- /dev/null +++ b/src/conf.h.cmake.in @@ -0,0 +1,337 @@ +/* src/conf.h.cmake.in. Used as basis for conf.h when building with cmake */ + +#ifndef _CONF_H_ +#define _CONF_H_ + +/* Define to empty if the keyword does not work. */ +#cmakedefine const + +/* Define if you don't have vprintf but do have _doprnt. */ +#cmakedefine HAVE_DOPRNT TODO + +/* Define if you have that is POSIX.1 compatible. */ +#cmakedefine HAVE_SYS_WAIT_H + +/* Define if you have the vprintf function. */ +#cmakedefine HAVE_VPRINTF + +/* Define to `int' if doesn't define. */ +#cmakedefine pid_t + +/* Define as the return type of signal handlers (int or void). */ +#cmakedefine RETSIGTYPE + +/* Define to `unsigned' if doesn't define. */ +#cmakedefine size_t + +/* Define if you have the ANSI C header files. */ +#cmakedefine STDC_HEADERS + +/* Define if you can safely include both and . */ +#cmakedefine TIME_WITH_SYS_TIME + +/* Define if we're compiling CircleMUD under any type of UNIX system. */ +#cmakedefine CIRCLE_UNIX + +/* Define if the system is capable of using crypt() to encrypt. */ +#cmakedefine CIRCLE_CRYPT + +/* Define if we don't have proper support for the system's crypt(). */ +#cmakedefine HAVE_UNSAFE_CRYPT + +/* Define is the system has struct in_addr. */ +#cmakedefine HAVE_STRUCT_IN_ADDR + +/* Define to `int' if doesn't define. */ +#cmakedefine socklen_t + +/* Define to `int' if doesn't define. */ +#cmakedefine ssize_t + +/* Define if you have the gettimeofday function. */ +#cmakedefine HAVE_GETTIMEOFDAY + +/* Define if you have the inet_addr function. */ +#cmakedefine HAVE_INET_ADDR + +/* Define if you have the inet_aton function. */ +#cmakedefine HAVE_INET_ATON + +/* Define if you have the select function. */ +#cmakedefine HAVE_SELECT + +/* Define if you have the snprintf function. */ +#cmakedefine HAVE_SNPRINTF + +/* Define if you have the strcasecmp function. */ +#cmakedefine HAVE_STRCASECMP + +/* Define if you have the strdup function. */ +#cmakedefine HAVE_STRDUP + +/* Define if you have the strerror function. */ +#cmakedefine HAVE_STRERROR + +/* Define if you have the stricmp function. */ +#cmakedefine HAVE_STRICMP + +/* Define if you have the strlcpy function. */ +#cmakedefine HAVE_STRLCPY + +/* Define if you have the strncasecmp function. */ +#cmakedefine HAVE_STRNCASECMP + +/* Define if you have the strnicmp function. */ +#cmakedefine HAVE_STRNICMP + +/* Define if you have the strstr function. */ +#cmakedefine HAVE_STRSTR + +/* Define if you have the vsnprintf function. */ +#cmakedefine HAVE_VSNPRINTF + +/* Define if you have the header file. */ +#cmakedefine HAVE_ARPA_INET_H + +/* Define if you have the header file. */ +#cmakedefine HAVE_ARPA_TELNET_H + +/* Define if you have the header file. */ +#cmakedefine HAVE_ASSERT_H + +/* Define if you have the header file. */ +#cmakedefine HAVE_CRYPT_H + +/* Define if you have the header file. */ +#cmakedefine HAVE_ERRNO_H + +/* Define if you have the header file. */ +#cmakedefine HAVE_FCNTL_H + +/* Define if you have the header file. */ +#cmakedefine HAVE_LIMITS_H + +/* Define if you have the header file. */ +#cmakedefine HAVE_MCHECK_H + +/* Define if you have the header file. */ +#cmakedefine HAVE_MEMORY_H + +/* Define if you have the header file. */ +#cmakedefine HAVE_NET_ERRNO_H + +/* Define if you have the header file. */ +#cmakedefine HAVE_NETDB_H + +/* Define if you have the header file. */ +#cmakedefine HAVE_NETINET_IN_H + +/* Define if you have the header file. */ +#cmakedefine HAVE_SIGNAL_H + +/* Define if you have the header file. */ +#cmakedefine HAVE_STRING_H + +/* Define if you have the header file. */ +#cmakedefine HAVE_STRINGS_H + +/* Define if you have the header file. */ +#cmakedefine HAVE_SYS_FCNTL_H + +/* Define if you have the header file. */ +#cmakedefine HAVE_SYS_RESOURCE_H + +/* Define if you have the header file. */ +#cmakedefine HAVE_SYS_SELECT_H + +/* Define if you have the header file. */ +#cmakedefine HAVE_SYS_SOCKET_H + +/* Define if you have the header file. */ +#cmakedefine HAVE_SYS_STAT_H + +/* Define if you have the header file. */ +#cmakedefine HAVE_SYS_TIME_H + +/* Define if you have the header file. */ +#cmakedefine HAVE_SYS_TYPES_H + +/* Define if you have the header file. */ +#cmakedefine HAVE_SYS_UIO_H + +/* Define if you have the header file. */ +#cmakedefine HAVE_UNISTD_H + +/* Define if you have the malloc library (-lmalloc). */ +#cmakedefine HAVE_LIBMALLOC + +/* Check for a prototype to accept. */ +#cmakedefine NEED_ACCEPT_PROTO + +/* Check for a prototype to atoi. */ +#cmakedefine NEED_ATOI_PROTO + +/* Check for a prototype to atol. */ +#cmakedefine NEED_ATOL_PROTO + +/* Check for a prototype to bind. */ +#cmakedefine NEED_BIND_PROTO + +/* Check for a prototype to bzero. */ +#cmakedefine NEED_BZERO_PROTO + +/* Check for a prototype to chdir. */ +#cmakedefine NEED_CHDIR_PROTO + +/* Check for a prototype to close. */ +#cmakedefine NEED_CLOSE_PROTO + +/* Check for a prototype to crypt. */ +#cmakedefine NEED_CRYPT_PROTO + +/* Check for a prototype to fclose. */ +#cmakedefine NEED_FCLOSE_PROTO + +/* Check for a prototype to fcntl. */ +#cmakedefine NEED_FCNTL_PROTO + +/* Check for a prototype to fflush. */ +#cmakedefine NEED_FFLUSH_PROTO + +/* Check for a prototype to fprintf. */ +#cmakedefine NEED_FPRINTF_PROTO + +/* Check for a prototype to fputc. */ +#cmakedefine NEED_FPUTC_PROTO + +/* Check for a prototype to fputs. */ +#cmakedefine NEED_FPUTS_PROTO + +/* Check for a prototype to fread. */ +#cmakedefine NEED_FREAD_PROTO + +/* Check for a prototype to fscanf. */ +#cmakedefine NEED_FSCANF_PROTO + +/* Check for a prototype to fseek. */ +#cmakedefine NEED_FSEEK_PROTO + +/* Check for a prototype to fwrite. */ +#cmakedefine NEED_FWRITE_PROTO + +/* Check for a prototype to getpeername. */ +#cmakedefine NEED_GETPEERNAME_PROTO + +/* Check for a prototype to getpid. */ +#cmakedefine NEED_GETPID_PROTO + +/* Check for a prototype to getrlimit. */ +#cmakedefine NEED_GETRLIMIT_PROTO + +/* Check for a prototype to getsockname. */ +#cmakedefine NEED_GETSOCKNAME_PROTO + +/* Check for a prototype to gettimeofday. */ +#cmakedefine NEED_GETTIMEOFDAY_PROTO + +/* Check for a prototype to htonl. */ +#cmakedefine NEED_HTONL_PROTO + +/* Check for a prototype to htons. */ +#cmakedefine NEED_HTONS_PROTO + +/* Check for a prototype to inet_addr. */ +#cmakedefine NEED_INET_ADDR_PROTO + +/* Check for a prototype to inet_aton. */ +#cmakedefine NEED_INET_ATON_PROTO + +/* Check for a prototype to inet_ntoa. */ +#cmakedefine NEED_INET_NTOA_PROTO + +/* Check for a prototype to listen. */ +#cmakedefine NEED_LISTEN_PROTO + +/* Check for a prototype to ntohl. */ +#cmakedefine NEED_NTOHL_PROTO + +/* Check for a prototype to perror. */ +#cmakedefine NEED_PERROR_PROTO + +/* Check for a prototype to printf. */ +#cmakedefine NEED_PRINTF_PROTO + +/* Check for a prototype to qsort. */ +#cmakedefine NEED_QSORT_PROTO + +/* Check for a prototype to read. */ +#cmakedefine NEED_READ_PROTO + +/* Check for a prototype to remove. */ +#cmakedefine NEED_REMOVE_PROTO + +/* Check for a prototype to rewind. */ +#cmakedefine NEED_REWIND_PROTO + +/* Check for a prototype to select. */ +#cmakedefine NEED_SELECT_PROTO + +/* Check for a prototype to setitimer. */ +#cmakedefine NEED_SETITIMER_PROTO + +/* Check for a prototype to setrlimit. */ +#cmakedefine NEED_SETRLIMIT_PROTO + +/* Check for a prototype to setsockopt. */ +#cmakedefine NEED_SETSOCKOPT_PROTO + +/* Check for a prototype to snprintf. */ +#cmakedefine NEED_SNPRINTF_PROTO + +/* Check for a prototype to socket. */ +#cmakedefine NEED_SOCKET_PROTO + +/* Check for a prototype to sprintf. */ +#cmakedefine NEED_SPRINTF_PROTO + +/* Check for a prototype to sscanf. */ +#cmakedefine NEED_SSCANF_PROTO + +/* Check for a prototype to strcasecmp. */ +#cmakedefine NEED_STRCASECMP_PROTO + +/* Check for a prototype to strdup. */ +#cmakedefine NEED_STRDUP_PROTO + +/* Check for a prototype to strerror. */ +#cmakedefine NEED_STRERROR_PROTO + +/* Check for a prototype to stricmp. */ +#cmakedefine NEED_STRICMP_PROTO + +/* Check for a prototype to strlcpy. */ +#cmakedefine NEED_STRLCPY_PROTO + +/* Check for a prototype to strncasecmp. */ +#cmakedefine NEED_STRNCASECMP_PROTO + +/* Check for a prototype to strnicmp. */ +#cmakedefine NEED_STRNICMP_PROTO + +/* Check for a prototype to system. */ +#cmakedefine NEED_SYSTEM_PROTO + +/* Check for a prototype to time. */ +#cmakedefine NEED_TIME_PROTO + +/* Check for a prototype to unlink. */ +#cmakedefine NEED_UNLINK_PROTO + +/* Check for a prototype to vsnprintf. */ +#cmakedefine NEED_VSNPRINTF_PROTO + +/* Check for a prototype to write. */ +#cmakedefine NEED_WRITE_PROTO + + +#endif /* _CONF_H_ */