Change build outputs and paths, use cmake's defaults, change some build definitions, remove unistd dep listing (it isn't used), add option summary, instruct for out of tree builds, fix a assembler bug and add ircv3 test for the msg assembler

This commit is contained in:
Alex 2020-07-23 15:59:41 +02:00
parent e71d730947
commit 160c3fddd5
Signed by: caskd
GPG Key ID: F92BA85F61F4C173
5 changed files with 21 additions and 20 deletions

7
.gitignore vendored
View File

@ -1,8 +1 @@
build build
CMakeCache.txt
CMakeFiles
cmake_install.cmake
install_manifest.txt
Makefile
Testing
CTestTestfile.cmake

View File

@ -7,11 +7,8 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -pedantic -Werror -Wformat-ove
if (NOT CMAKE_BUILD_TYPE) if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug) set(CMAKE_BUILD_TYPE Debug)
endif() endif()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build/archive)
if ( UIRC_IRCV3 ) if ( IRCV3 )
add_definitions(-DUIRC_IRCV3) add_definitions(-DUIRC_IRCV3)
endif() endif()
if ( BUILD_TESTS ) if ( BUILD_TESTS )
@ -24,7 +21,7 @@ set(build_FILES
src/tokenizers.c src/tokenizers.c
src/validators.c src/validators.c
) )
if ( USE_HELPERS ) if ( BUILD_HELPERS )
message("Helper functions are going to be built.") message("Helper functions are going to be built.")
set(build_FILES ${build_FILES} src/helpers.c) set(build_FILES ${build_FILES} src/helpers.c)
endif() endif()

View File

@ -3,21 +3,25 @@
## Requirements ## Requirements
- CMake (tested on 3.17) - CMake (tested on 3.17)
- Standard UNIX library
- C99+ compiler - C99+ compiler
## Building ## Building
First, create the required build files (usually the Makefile) First, create the required build files (usually the Makefile)
```sh ```sh
cmake . -DUSE_HELPERS=1 -DCMAKE_BUILD_TYPE=Release -DUIRC_IRCV3=1 cmake -H. -Bbuild/ -DBUILD_HELPERS=1 -DCMAKE_BUILD_TYPE=Release -DIRCV3=1
``` ```
Note: You can omit USE_HELPERS or/and UIRC_IRCV3 if you do not plan to use those features. | Option | Description | Type | Supported since |
|:-------------:|:---------------------------------------------------------------------:|:--------:|:---------------:|
| BUILD_HELPERS | Build simple assemblers and tokenizers that handle the heavy lifting | boolean | - |
| BUILD_TESTS | Build tests that check if the build results behave as they should | boolean | - |
| IRCV3 | Build IRCv3 support (WIP) | boolean | - |
Following that, just use your build system and compile it Following that, just use your build system and compile it
Example for **make**: Example for **make**:
```sh ```sh
cd build/
make make
``` ```

View File

@ -29,6 +29,8 @@ signed int Assm_mesg(char* buf, IRC_Message* in, size_t len)
pos += ret; pos += ret;
else else
return ret; return ret;
if (!safe_charcpy(&pos, ' ', len - (pos - buf)))
return ERR_UIRC_BUFFER_ERR;
#endif #endif
if (in->name.nick != NULL || in->name.host != NULL) { if (in->name.nick != NULL || in->name.host != NULL) {
if (!safe_charcpy(&pos, ':', len - (pos - buf))) if (!safe_charcpy(&pos, ':', len - (pos - buf)))

View File

@ -7,10 +7,11 @@ int main(void)
{ {
char mesg[513] = {0}; char mesg[513] = {0};
IRC_Message input = { IRC_Message input = {
.name = { #ifdef UIRC_IRCV3
.nick = "dad", .tags = {
.user = "dad-door", .msgid = {.value = "10"}},
.host = "home.localhost"}, #endif
.name = {.nick = "dad", .user = "dad-door", .host = "home.localhost"},
.cmd = PRIVMSG, .cmd = PRIVMSG,
.args = {"(You)"}, .args = {"(You)"},
.trailing = "are ya winning son?", .trailing = "are ya winning son?",
@ -20,7 +21,11 @@ int main(void)
printf("Failed to assemble message. (%i)\n", res); printf("Failed to assemble message. (%i)\n", res);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
char* expect = ":dad!dad-door@home.localhost PRIVMSG (You) :are ya winning son?\r\n"; char* expect =
#ifdef UIRC_IRCV3
"@msgid=10 "
#endif
":dad!dad-door@home.localhost PRIVMSG (You) :are ya winning son?\r\n";
if (strcmp(expect, mesg)) { if (strcmp(expect, mesg)) {
printf("Assembled message mismatch.\nGot:\n%s\nbut expected:\n%s\n", mesg, expect); printf("Assembled message mismatch.\nGot:\n%s\nbut expected:\n%s\n", mesg, expect);
return EXIT_FAILURE; return EXIT_FAILURE;