diff --git a/cmake/mastodont-config.cmake b/cmake/mastodont-config.cmake index 73b6176..5600324 100644 --- a/cmake/mastodont-config.cmake +++ b/cmake/mastodont-config.cmake @@ -4,11 +4,18 @@ set(MASTODONT_VERSION 0.1) # Get parent directory of this config file find_package(CURL REQUIRED) +find_package(PkgConfig REQUIRED) +# TODO account for built-in cjson lib +pkg_check_modules(MSTDNT_CJSON libcjson) set(MASTODONT_INCLUDE_DIRS - "${CMAKE_CURRENT_LIST_DIR}/../include" - "${CMAKE_CURRENT_LIST_DIR}/../libs" + ../include + ../libs ) -set(MASTODONT_LIBRARIES ${CMAKE_CURRENT_LIST_DIR}) +set(MASTODONT_LIBRARIES + mastodont + ${MSTDNT_CJSON_LIBRARIES} + ${CURL_LIBRARIES} +) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5b1215d..3e44030 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,6 +1,10 @@ +include(../cmake/mastodont-config.cmake) add_executable(get_feed get_feed.c) target_compile_options(get_feed PUBLIC -std=c99 -Wall) +target_link_libraries(get_feed PUBLIC + ${MASTODONT_LIBRARIES} +) target_include_directories(get_feed PUBLIC - ../include - ${CURL_INCLUDE_DIRS} - ../libs) \ No newline at end of file + ${MASTODONT_INCLUDE_DIRS} +) + \ No newline at end of file diff --git a/tests/get_feed.c b/tests/get_feed.c index bf24df0..7f07859 100644 --- a/tests/get_feed.c +++ b/tests/get_feed.c @@ -1,11 +1,12 @@ #include +#include +#include #include -char* get_line(char const* prompt, size_t* res_size) +char* get_line(char const* prompt) { char* result = NULL; -#define GL_BUF_SIZE 25 - size_t _res_size; +#define GL_BUF_SIZE 255 char buffer[GL_BUF_SIZE]; if (prompt) @@ -14,21 +15,15 @@ char* get_line(char const* prompt, size_t* res_size) fputs(": ", stdout); } - while (fgets(buffer, GL_BUF_SIZE, stdin) != NULL) - { - _res_size += GL_BUF_SIZE; - result = realloc(result, _res_size); - memcpy(result, buffer, GL_BUF_SIZE); - } + fgets(buffer, GL_BUF_SIZE, stdin); + result = realloc(result, strlen(buffer)+1); + strcpy(result, buffer); - if (res_size) - *res_size = _res_size; - return result; } int -main() +main(int argc, char** argv) { mstdnt_global_curl_init(); @@ -39,7 +34,7 @@ main() fputs("Couldn't initialize Mastodont-c!", stderr); } - char* instance = get_line("Instance: ", NULL); + char* instance = get_line("Instance"); puts(instance); @@ -47,4 +42,6 @@ main() mstdnt_cleanup(&data); mstdnt_global_curl_cleanup(); + + return 1; } \ No newline at end of file