From 7fb23ee207404e7754f21518507040515784f368 Mon Sep 17 00:00:00 2001 From: tastytea Date: Fri, 26 Jul 2019 07:08:13 +0200 Subject: [PATCH] Split code into library and cli. --- CMakeLists.txt | 35 +++++---------------------------- src/cli/CMakeLists.txt | 5 +++++ src/{ => cli}/main.cpp | 0 src/{ => cli}/parse_options.cpp | 0 src/{ => cli}/parse_options.hpp | 0 src/lib/CMakeLists.txt | 31 +++++++++++++++++++++++++++++ src/{ => lib}/adoc.cpp | 0 src/{ => lib}/adoc.hpp | 0 src/{ => lib}/bookmarks.cpp | 0 src/{ => lib}/bookmarks.hpp | 0 src/{ => lib}/csv.cpp | 0 src/{ => lib}/csv.hpp | 0 src/{ => lib}/export.cpp | 0 src/{ => lib}/export.hpp | 0 src/{ => lib}/search.cpp | 0 src/{ => lib}/search.hpp | 0 src/{ => lib}/simple.cpp | 0 src/{ => lib}/simple.hpp | 0 src/{ => lib}/sqlite.cpp | 0 src/{ => lib}/sqlite.hpp | 0 src/{ => lib}/time.cpp | 0 src/{ => lib}/time.hpp | 0 src/{ => lib}/types.hpp | 0 src/{ => lib}/uri.cpp | 0 src/{ => lib}/uri.hpp | 0 tests/CMakeLists.txt | 5 +++-- 26 files changed, 44 insertions(+), 32 deletions(-) create mode 100644 src/cli/CMakeLists.txt rename src/{ => cli}/main.cpp (100%) rename src/{ => cli}/parse_options.cpp (100%) rename src/{ => cli}/parse_options.hpp (100%) create mode 100644 src/lib/CMakeLists.txt rename src/{ => lib}/adoc.cpp (100%) rename src/{ => lib}/adoc.hpp (100%) rename src/{ => lib}/bookmarks.cpp (100%) rename src/{ => lib}/bookmarks.hpp (100%) rename src/{ => lib}/csv.cpp (100%) rename src/{ => lib}/csv.hpp (100%) rename src/{ => lib}/export.cpp (100%) rename src/{ => lib}/export.hpp (100%) rename src/{ => lib}/search.cpp (100%) rename src/{ => lib}/search.hpp (100%) rename src/{ => lib}/simple.cpp (100%) rename src/{ => lib}/simple.hpp (100%) rename src/{ => lib}/sqlite.cpp (100%) rename src/{ => lib}/sqlite.hpp (100%) rename src/{ => lib}/time.cpp (100%) rename src/{ => lib}/time.hpp (100%) rename src/{ => lib}/types.hpp (100%) rename src/{ => lib}/uri.cpp (100%) rename src/{ => lib}/uri.hpp (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 203171d..84f0e1f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,15 +9,6 @@ set(WITH_TESTS "NO" CACHE STRING "WITH_TESTS defaults to \"NO\"") set(WITH_MOZILLA "NO" CACHE STRING "WITH_MOZILLA defaults to \"NO\"") include(GNUInstallDirs) -find_package(PkgConfig REQUIRED) -pkg_check_modules(LIBXDG_BASEDIR REQUIRED libxdg-basedir) -# sqlite3 is not a direct dependency, but vsqlite++ has no cmake- or pkg-config -# module. Since it installs in the same directories as sqlite3, I am adding the -# module here to add the include- and link directories below. It is not REQUIRED -# because the sqlite3 in Debian jessie doesn't come with a pkg-config module. -pkg_check_modules(SQLITE3 sqlite3) -pkg_check_modules(CURLPP REQUIRED curlpp) -find_package(ICU COMPONENTS uc i18n REQUIRED) set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -27,33 +18,17 @@ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wextra -Wpedantic -ftrapv \ -fsanitize=undefined -g -Og -fno-omit-frame-pointer") -include_directories(${PROJECT_SOURCE_DIR}/src) +include_directories(${PROJECT_SOURCE_DIR}/src/lib) Include_directories(${PROJECT_BINARY_DIR}) -include_directories(${LIBXDG_BASEDIR_INCLUDE_DIRS}) -include_directories(${SQLITE3_INCLUDE_DIRS}) -include_directories(${CURLPP_INCLUDE_DIRS}) -include_directories(${ICU_INCLUDE_DIRS}) - -link_directories(${LIBXDG_BASEDIR_LIBRARY_DIRS}) -link_directories(${SQLITE3_LIBRARY_DIRS}) -link_directories(${CURLPP_LIBRARY_DIRS}) -link_directories(${ICU_LIBRARY_DIRS}) - -set(COMMON_LIBRARIES - ${LIBXDG_BASEDIR_LIBRARIES} vsqlitepp stdc++fs ${CURLPP_LIBRARIES} - ${ICU_LIBRARIES}) - # Write version in header configure_file( "${PROJECT_SOURCE_DIR}/src/version.hpp.in" "${PROJECT_BINARY_DIR}/version.hpp" ) -file(GLOB sources src/*.cpp) -add_executable(${PROJECT_NAME} "${sources}") -target_link_libraries(${PROJECT_NAME} ${COMMON_LIBRARIES}) -install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR}) +add_subdirectory(src/lib) +add_subdirectory(src/cli) if (WITH_MAN) add_custom_command( @@ -73,8 +48,8 @@ if (WITH_MOZILLA) endif() if(WITH_TESTS) - add_library(${PROJECT_NAME}_testlib SHARED ${sources}) - target_link_libraries(${PROJECT_NAME}_testlib ${COMMON_LIBRARIES}) + include_directories(${PROJECT_SOURCE_DIR}/src/cli) + add_library(${PROJECT_NAME}_testlib SHARED src/cli/parse_options.cpp) add_subdirectory(tests) endif() diff --git a/src/cli/CMakeLists.txt b/src/cli/CMakeLists.txt new file mode 100644 index 0000000..02e5547 --- /dev/null +++ b/src/cli/CMakeLists.txt @@ -0,0 +1,5 @@ +file(GLOB sources_cli *.cpp) +add_executable(${PROJECT_NAME}-cli ${sources_cli}) +target_link_libraries(${PROJECT_NAME}-cli ${PROJECT_NAME}) +set_target_properties(${PROJECT_NAME}-cli PROPERTIES OUTPUT_NAME ${PROJECT_NAME}) +install(TARGETS ${PROJECT_NAME}-cli DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/src/main.cpp b/src/cli/main.cpp similarity index 100% rename from src/main.cpp rename to src/cli/main.cpp diff --git a/src/parse_options.cpp b/src/cli/parse_options.cpp similarity index 100% rename from src/parse_options.cpp rename to src/cli/parse_options.cpp diff --git a/src/parse_options.hpp b/src/cli/parse_options.hpp similarity index 100% rename from src/parse_options.hpp rename to src/cli/parse_options.hpp diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt new file mode 100644 index 0000000..42a9687 --- /dev/null +++ b/src/lib/CMakeLists.txt @@ -0,0 +1,31 @@ +find_package(PkgConfig REQUIRED) +pkg_check_modules(LIBXDG_BASEDIR REQUIRED libxdg-basedir) +# sqlite3 is not a direct dependency, but vsqlite++ has no cmake- or pkg-config +# module. Since it installs in the same directories as sqlite3, I am adding the +# module here to add the include- and link directories below. It is not REQUIRED +# because the sqlite3 in Debian jessie doesn't come with a pkg-config module. +pkg_check_modules(SQLITE3 sqlite3) +pkg_check_modules(CURLPP REQUIRED curlpp) +find_package(ICU COMPONENTS uc i18n REQUIRED) + +include_directories(${LIBXDG_BASEDIR_INCLUDE_DIRS}) +include_directories(${SQLITE3_INCLUDE_DIRS}) +include_directories(${CURLPP_INCLUDE_DIRS}) +include_directories(${ICU_INCLUDE_DIRS}) + +link_directories(${LIBXDG_BASEDIR_LIBRARY_DIRS}) +link_directories(${SQLITE3_LIBRARY_DIRS}) +link_directories(${CURLPP_LIBRARY_DIRS}) +link_directories(${ICU_LIBRARY_DIRS}) + +file(GLOB sources_lib *.cpp) +add_library(${PROJECT_NAME} SHARED ${sources_lib}) +target_link_libraries(${PROJECT_NAME} ${LIBXDG_BASEDIR_LIBRARIES} + vsqlitepp stdc++fs ${CURLPP_LIBRARIES} ${ICU_LIBRARIES}) +set_target_properties(${PROJECT_NAME} PROPERTIES + VERSION ${PROJECT_VERSION} + SOVERSION ${${PROJECT_NAME}_VERSION_MAJOR} + ) +install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) +# install(FILES ??? +# DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}) diff --git a/src/adoc.cpp b/src/lib/adoc.cpp similarity index 100% rename from src/adoc.cpp rename to src/lib/adoc.cpp diff --git a/src/adoc.hpp b/src/lib/adoc.hpp similarity index 100% rename from src/adoc.hpp rename to src/lib/adoc.hpp diff --git a/src/bookmarks.cpp b/src/lib/bookmarks.cpp similarity index 100% rename from src/bookmarks.cpp rename to src/lib/bookmarks.cpp diff --git a/src/bookmarks.hpp b/src/lib/bookmarks.hpp similarity index 100% rename from src/bookmarks.hpp rename to src/lib/bookmarks.hpp diff --git a/src/csv.cpp b/src/lib/csv.cpp similarity index 100% rename from src/csv.cpp rename to src/lib/csv.cpp diff --git a/src/csv.hpp b/src/lib/csv.hpp similarity index 100% rename from src/csv.hpp rename to src/lib/csv.hpp diff --git a/src/export.cpp b/src/lib/export.cpp similarity index 100% rename from src/export.cpp rename to src/lib/export.cpp diff --git a/src/export.hpp b/src/lib/export.hpp similarity index 100% rename from src/export.hpp rename to src/lib/export.hpp diff --git a/src/search.cpp b/src/lib/search.cpp similarity index 100% rename from src/search.cpp rename to src/lib/search.cpp diff --git a/src/search.hpp b/src/lib/search.hpp similarity index 100% rename from src/search.hpp rename to src/lib/search.hpp diff --git a/src/simple.cpp b/src/lib/simple.cpp similarity index 100% rename from src/simple.cpp rename to src/lib/simple.cpp diff --git a/src/simple.hpp b/src/lib/simple.hpp similarity index 100% rename from src/simple.hpp rename to src/lib/simple.hpp diff --git a/src/sqlite.cpp b/src/lib/sqlite.cpp similarity index 100% rename from src/sqlite.cpp rename to src/lib/sqlite.cpp diff --git a/src/sqlite.hpp b/src/lib/sqlite.hpp similarity index 100% rename from src/sqlite.hpp rename to src/lib/sqlite.hpp diff --git a/src/time.cpp b/src/lib/time.cpp similarity index 100% rename from src/time.cpp rename to src/lib/time.cpp diff --git a/src/time.hpp b/src/lib/time.hpp similarity index 100% rename from src/time.hpp rename to src/lib/time.hpp diff --git a/src/types.hpp b/src/lib/types.hpp similarity index 100% rename from src/types.hpp rename to src/lib/types.hpp diff --git a/src/uri.cpp b/src/lib/uri.cpp similarity index 100% rename from src/uri.cpp rename to src/lib/uri.cpp diff --git a/src/uri.hpp b/src/lib/uri.hpp similarity index 100% rename from src/uri.hpp rename to src/lib/uri.hpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index cd11df0..f730478 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -5,7 +5,8 @@ find_package(Catch2) if(Catch2_FOUND) # Catch 2.x include(Catch) add_executable(all_tests main.cpp ${sources_tests}) - target_link_libraries(all_tests Catch2::Catch2 ${PROJECT_NAME}_testlib) + target_link_libraries(all_tests + Catch2::Catch2 ${PROJECT_NAME} ${PROJECT_NAME}_testlib) target_include_directories(all_tests PRIVATE "/usr/include/catch2") catch_discover_tests(all_tests EXTRA_ARGS "${EXTRA_TEST_ARGS}") else() # Catch 1.x @@ -14,7 +15,7 @@ else() # Catch 1.x foreach(src ${sources_tests}) get_filename_component(bin ${src} NAME_WE) add_executable(${bin} main.cpp ${src}) - target_link_libraries(${bin} ${PROJECT_NAME}_testlib) + target_link_libraries(${bin} ${PROJECT_NAME} ${PROJECT_NAME}_testlib) add_test(${bin} ${bin} "${EXTRA_TEST_ARGS}") endforeach() else()