diff --git a/CMakeLists.txt b/CMakeLists.txt index 2be69d4..2dc66d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,13 @@ set(CMAKE_C_STANDARD 99) project(tiny_thread_pool LANGUAGES C) -add_library(tiny_pool STATIC tiny_pool.c) +option(BUILD_DYN "build shared library" OFF) +if (BUILD_DYN) + add_compile_options(-fPIC) + add_library(tiny_pool SHARED tiny_pool.c) +else() + add_library(tiny_pool STATIC tiny_pool.c) +endif() target_link_libraries(tiny_pool pthread) add_subdirectory(demo/c) diff --git a/READMD.md b/README.md similarity index 75% rename from READMD.md rename to README.md index ae3708b..47e2d81 100644 --- a/READMD.md +++ b/README.md @@ -30,4 +30,45 @@ In addition, there is a `tiny_pool_kill`, this command will directly clear all t ### Compile +This project uses `CMake` to build and compile, you can use it to get started quickly, or manually call the compiler. + +**CMake** + +> This will build `libtiny_pool.a` static library and demo executable. + +```bash +cmake -B cmake-build +cmake --build cmake-build +``` + +> This will build `libtiny_pool.so` dynamic library and demo executable. + +```bash +cmake -B cmake-build -DBUILD_DYN=ON +cmake --build cmake-build +``` + +**GCC** + +> Manually build the static library. + +```bash +gcc -std=gnu99 -c tiny_pool.c -o libtiny_pool.a +``` + +> Build the demo and link the static library. + +```bash +gcc demo/c/demo.c -o demo_c -I. -L. -ltiny_pool -lpthread +g++ demo/cpp/demo.cc -o demo_cpp -I. -L. -ltiny_pool -lpthread +``` + +> Manually build the dynamic library. + +```bash +gcc -std=gnu99 -shared -fPIC -c tiny_pool.c -o libtiny_pool.so +``` + ### License + +MIT ©2023 [@dnomd343](https://github.com/dnomd343)