bama4 / simple-http-server

A simple lightweight HTTP server in C
0 stars 0 forks source link

Lays out the project skeleton and basic build tooling. #2

Closed garfr closed 3 years ago

garfr commented 3 years ago

Problem

The server lacks any structure for organizing source files, and has no planned build tooling. (#1)

Solution

Summary

Directories and Stubs

The project is organized as several sub-directories that function as libraries without dependencies on each other. There is one sub-directory that does depend on the other libraries that generates an executable file (currently the simple_http_server folder). Each sub-directory has an include, src, and test directory that contains its corresponding files. In addition to these folders there is a scripts folder and a man folder containing helpful scripts and the manpage for the project.

Building with CMake

The sub-directories each contain a CMakeLists.txt file that builds an object file out of the source files in the directory, which outside of testing shouldn't be called individually. Rather, the sub-directories are built by one CMakeLists.txt at the root of the project. Generally the person building the project should create a build directory in the project root and call cmake from within it, preventing CMake from filling the project root with cruft.

Because the project contains no outside dependencies the CMake configuration is quite simple, and besides enabling warnings, compiling sub-directories, and linking them against an executable, little configuration is done. This will be expanded as the project's requirements grow.

Existing Problems

bama4 commented 3 years ago

I see that the libraries created as static .a libraries. We want .so libraries, correct?

Also final executable can be placed into a bin folder

bama4 commented 3 years ago

I get build failed:

ubuntu:~/REPOS/simple-http-server$ cmake --build .
Scanning dependencies of target socket_tcp_manager
[ 16%] Building C object socket_tcp_manager/CMakeFiles/socket_tcp_manager.dir/src/socket_tcp_manager.c.o
[ 33%] Linking C static library libsocket_tcp_manager.a
[ 33%] Built target socket_tcp_manager
Scanning dependencies of target http
[ 50%] Building C object http/CMakeFiles/http.dir/src/http.c.o
[ 66%] Linking C static library libhttp.a
[ 66%] Built target http
Scanning dependencies of target simple_http_server
[ 83%] Building C object CMakeFiles/simple_http_server.dir/simple_http_server/src/simple_http_server.c.o
[100%] Linking C executable simple_http_server
/usr/bin/ld: cannot open output file simple_http_server: Is a directory
collect2: error: ld returned 1 exit status
CMakeFiles/simple_http_server.dir/build.make:96: recipe for target 'simple_http_server' failed
make[2]: *** [simple_http_server] Error 1
CMakeFiles/Makefile2:68: recipe for target 'CMakeFiles/simple_http_server.dir/all' failed
make[1]: *** [CMakeFiles/simple_http_server.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
garfr commented 3 years ago

I figured out the build failure quickly, and the problem is that the executable is named the same thing as the simple_http_server folder. This is solved by just making a bin directory as you said. I'm working on shared libraries right now.