Support for building utils

This commit is contained in:
Thomas Arp 2025-04-21 01:29:52 +02:00
parent 7196c012a6
commit bf5ee52c2a
3 changed files with 87 additions and 10 deletions

View file

@ -162,7 +162,9 @@ if (NOT HAVE_SOCKET)
endif()
# ========== Define generelt UNIX-system ==========
set(CIRCLE_UNIX 1)
if (UNIX)
set(CIRCLE_UNIX 1)
endif()
# ========== Generate conf.h ==========
configure_file(
@ -177,6 +179,7 @@ file(GLOB SRC_FILES src/*.c)
add_executable(circle ${SRC_FILES})
target_link_libraries(circle ${EXTRA_LIBS})
add_subdirectory(src/util)
if (MEMORY_DEBUG)
message(STATUS "MEMORY_DEBUG is activated, setting up zmalloc")

View file

@ -12,7 +12,9 @@ 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.
CMake's GUIs.
NOTE: The current CMakeLists.txt only supports linux.
# Configuring
@ -30,35 +32,61 @@ that is apart from the source tree.
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 .
```shell
$ cmake -B build -S .
```
- Build in the source tree. Not recommended.
$ cmake -B .
```shell
$ cmake -B .
```
The examples below will assume you have created a build folder.
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
```shell
$ rm build/CMakeCache.txt
```
Once the build files are generated, the build is run with cmake
$ cmake --build build
# or, if
$ cmake --build .
```shell
$ cmake --build 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.
### Utilities
It is possible to build only single tools, none or all of them,
by specifying the target in the build command:
```shell
# only build the mud
$ cmake --build build --target circle
# only build tools
$ cmake --build build --target utils
# only build one tool
$ cmake --build build --target wld2html
```
### 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
```shell
$ 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

46
src/util/CMakeLists.txt Normal file
View file

@ -0,0 +1,46 @@
set(TOOLS
asciipasswd
autowiz
plrtoascii
rebuildIndex
rebuildMailIndex
shopconv
sign
split
wld2html
webster
)
# common includes and flags
include_directories(${CMAKE_SOURCE_DIR}/src)
add_definitions(-DCIRCLE_UTIL)
find_library(CRYPT_LIBRARY crypt)
find_library(NETLIB_LIBRARY nsl socket) # for sign.c, hvis nødvendig
foreach(tool ${TOOLS})
if(${tool} STREQUAL "rebuildIndex")
add_executable(rebuildIndex rebuildAsciiIndex.c)
else()
add_executable(${tool} ${tool}.c)
endif()
# Set output location
set_target_properties(${tool} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin
)
# Link to libcrypt for asciipasswd
if(${tool} STREQUAL "asciipasswd" AND CRYPT_LIBRARY)
target_link_libraries(${tool} ${CRYPT_LIBRARY})
endif()
# Link to netlib for sign
if(${tool} STREQUAL "sign" AND NETLIB_LIBRARY)
target_link_libraries(${tool} ${NETLIB_LIBRARY})
endif()
endforeach()
add_custom_target(utils DEPENDS ${TOOLS})