diff --git a/CMakeLists.txt b/CMakeLists.txt index 03754e0..f4f2db2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,6 @@ else() endif() - add_executable(treebird ${SRC_FILES}) # Useful @@ -29,11 +28,23 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) include(cmake/os_hacks.cmake) # List helper include(cmake/append_and_def.cmake) -#find_package(PkgConfig REQUIRED) +find_package(PkgConfig REQUIRED) # Link stuff find_package(CURL REQUIRED) # Required for mastodont-c (hack) + +# For some reason the arguments from Perl are stored as a full string +# Blame CMake(?), not me... find_package(PerlLibs REQUIRED) +# It returns in CMake terms, "the command", but we want ("the" "command"). +# `target_compile_options' wants this. +# I'm still learning CMake, don't know why it stores lists like this, but it's +# whatever +string(REPLACE " " ";" _PERL_EXTRA_C_FLAGS ${PERL_EXTRA_C_FLAGS}) +# We could also use this somehow: +# separate_arguments(_PERL_EXTRA_C_FLAGS UNIX_COMMAND +# "${PERL_EXTRA_C_FLAGS}") + # Useful for GNU Emacs or VS Code set(CMAKE_EXPORT_COMPILE_COMMANDS ON) @@ -41,12 +52,14 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) target_compile_options(treebird PUBLIC -Wall -Wextra -std=c99 -Wshadow -Wcast-align -Wstrict-prototypes - ${PERL_EXTRA_C_FLAGS} + ${_PERL_EXTRA_C_FLAGS} $<$:-Og> $<$:-g> $<$:-O2> ) + + # hack is on me target_link_options(treebird PUBLIC -lmastodont @@ -71,7 +84,7 @@ set(SRC_FILES ) # Pages -append_and_def(SRC_FILES +append_and_def(treebird PUBLIC SRC_FILES src/about.c src/account.c src/applications.c @@ -101,19 +114,18 @@ append_and_def(SRC_FILES src/status.c src/timeline.c ) +message("${COMPILE_DEFINITIONS}") target_sources(treebird PUBLIC ${SRC_FILES}) -message(${MASTODONT_INCLUDE_DIRS}) - target_include_directories(treebird PUBLIC - ${PERL_INCLUDE_PATH} + ${PERL_INCLUDE_DIRS} ${MASTODONT_INCLUDE_DIRS} ${CURL_INCLUDE_DIRS}) # Build! Note the mastodont hack, this _should_ change soon. target_link_libraries(treebird PUBLIC - ${PERL_LIBRARY} + ${PERL_LIBRARIES} ${CURL_LIBRARIES} ${MASTODONT_LIBRARIES} mastodont-c/libmastodont.a) diff --git a/Makefile b/Makefile index 567615c..a312343 100644 --- a/Makefile +++ b/Makefile @@ -34,7 +34,6 @@ CFLAGS += -DDEBUG endif all: - $(MAKE) dep_build $(MAKE) filec $(MAKE) make_tmpls $(MAKE) $(TARGET) @@ -70,9 +69,6 @@ test: all $(UNIT_TESTS) @echo " ... Tests ready" @./test/test.pl -dep_build: - make -C $(MASTODONT_DIR) - %.o: %.c %.h $(PAGES) $(CC) $(CFLAGS) -c $< -o $@ diff --git a/cmake/append_and_def.cmake b/cmake/append_and_def.cmake index 900e0e3..61490ee 100644 --- a/cmake/append_and_def.cmake +++ b/cmake/append_and_def.cmake @@ -2,8 +2,20 @@ # the code doesn't compile correctly, for which you can do an `#ifdef' with the # C Preprocessor -function(append_and_def NAME) - foreach(X IN ITEMS ARGV) - list(APPEND NAME X) +macro(append_and_def TARGET SCOPE NAME ...) + + foreach(X IN ITEMS ${ARGN}) + # Convert to uppercase for the definition + get_filename_component(TEMP ${X} NAME_WE) + string(TOUPPER _TEMP ${TEMP}) + + get_target_property( + targ_comp + ${TARGET} + INTERFACE_COMPILE_DEFINITIONS) + message(${_TEMP}) + target_compile_definitions(${TARGET} ${SCOPE} + ${targ_comp} -DCMP_ENABLE_${_TEMP}) + list(APPEND X ${_TEMP}) endforeach() -endfunction() +endmacro() diff --git a/src/global_perl.h b/src/global_perl.h index dc2fddd..6e446df 100644 --- a/src/global_perl.h +++ b/src/global_perl.h @@ -6,6 +6,8 @@ #ifndef GLOBAL_PERL_H #define GLOBAL_PERL_H + +// Hack on my system... if this breaks anything, plz dig deeper #include #include #include "memory.h" diff --git a/src/main.c b/src/main.c index 044e4f1..854dd49 100644 --- a/src/main.c +++ b/src/main.c @@ -52,12 +52,24 @@ static int exit_treebird(PATH_ARGS) * Path handling * ******************/ static struct path_info paths[] = { +#ifdef CMP_ENABLE_CONFIG { "/config/general", content_config_general }, { "/config/appearance", content_config_appearance }, - /* { "/config/account", content_config_account }, */ + //{ "/config/account", content_config_account }, { "/config", content_config }, +#endif + +#ifdef CMP_ENABLE_ATTACHMENTS + // API + { "/treebird_api/v1/attachment", api_attachment_create }, +#endif + +#ifdef CMP_ENABLE_LOGIN { "/login/oauth", content_login_oauth }, { "/login", content_login }, +#endif + +#ifdef CMP_ENABLE_ACCOUNT { "/user/:/action/:", content_account_action }, { "/user/:", content_account_statuses }, { "/@:/scrobbles", content_account_scrobbles }, @@ -67,6 +79,12 @@ static struct path_info paths[] = { { "/@:/followers", content_account_followers }, { "/@:/statuses", content_account_statuses }, { "/@:", content_account_statuses }, + { "/favourites", content_account_favourites }, + { "/blocked", content_account_blocked }, + { "/muted", content_account_muted }, +#endif + +#ifdef CMP_ENABLE_STATUS { "/status/:/react/:", content_status_react }, { "/status/:/react", status_emoji }, { "/status/create", content_status_create }, @@ -76,44 +94,64 @@ static struct path_info paths[] = { { "/status/:/boosted_by", status_view_reblogs }, { "/status/:/reblogged_by", status_view_reblogs }, { "/status/:", status_view }, -#if 0 { "/notice/:", notice_redirect }, + { "/treebird_api/v1/interact", api_status_interact }, +#endif + +#ifdef CMP_ENABLE_ABOUT { "/about/license", content_about_license }, { "/about", content_about }, +#endif + +#ifdef CMP_ENABLE_SEARCH { "/search/statuses", content_search_statuses }, { "/search/accounts", content_search_accounts }, { "/search/hashtags", content_search_hashtags }, { "/search", content_search_all }, +#endif + +#if defined(CMP_ENABLE_EMOJI) && defined(CMP_ENABLE_EMOJI_REACTION) { "/emoji_picker", content_emoji_picker }, +#endif + +#ifdef CMP_ENABLE_LISTS { "/lists/edit/:", list_edit }, { "/lists/for/:", content_tl_list }, { "/lists", content_lists }, +#endif + +#ifdef CMP_ENABLE_TIMELINE { "/local", content_tl_local }, { "/federated", content_tl_federated }, { "/direct", content_tl_direct }, { "/bookmarks", content_account_bookmarks }, - { "/favourites", content_account_favourites }, - { "/blocked", content_account_blocked }, - { "/muted", content_account_muted }, +#endif + +#ifdef CMP_ENABLE_NOTIFICATIONS { "/notifications_compact", content_notifications_compact }, { "/notification/:/read", content_notifications_read }, { "/notification/:/delete", content_notifications_clear }, { "/notifications/read", content_notifications_read }, { "/notifications/clear", content_notifications_clear }, { "/notifications", content_notifications }, + { "/treebird_api/v1/notifications", api_notifications }, +#endif + +#ifdef CMP_ENABLE_HASHTAG { "/tag/:", content_tl_tag }, +#endif + +#ifdef CMP_ENABLE_CONVERSATIONS { "/chats/:", content_chat_view }, { "/chats", content_chats }, +#endif + #ifdef DEBUG { "/quit", exit_treebird }, { "/exit", exit_treebird }, #endif // Debug, but cool to see { "/memory_stats", content_memory_stats }, - // API - { "/treebird_api/v1/notifications", api_notifications }, - { "/treebird_api/v1/interact", api_status_interact }, - { "/treebird_api/v1/attachment", api_attachment_create }, }; static int application(mastodont_t* api, REQUEST_T req)