diff --git a/.github/workflows/windows-tests.yml b/.github/workflows/windows-tests.yml index a449de7e..8fed2240 100644 --- a/.github/workflows/windows-tests.yml +++ b/.github/workflows/windows-tests.yml @@ -31,7 +31,7 @@ jobs: cmake --version mkdir build cd build - cmake .. "-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake" -DVCPKG_TARGET_TRIPLET=x64-windows-static + cmake .. -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static -DBUILD_ONLY_TESTS=ON cmake --build . --config Release -j 2 - name: Test diff --git a/.gitignore b/.gitignore index a5d1eec1..f10cec75 100644 --- a/.gitignore +++ b/.gitignore @@ -26,7 +26,6 @@ # GNU Autotools .deps/ config.h -config.h.in config.h.in~ configure configure~ diff --git a/CMakeLists.txt b/CMakeLists.txt index 57f48788..556ff66c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,57 +1,112 @@ -cmake_minimum_required(VERSION 3.22) +cmake_minimum_required(VERSION 3.13) + +if (PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR) + message(FATAL_ERROR "In-source builds are not allowed. You should create separate directory for build files.") +endif() + +set_property(GLOBAL PROPERTY PACKAGE) +set_property(GLOBAL PROPERTY LIBS) +set_property(GLOBAL PROPERTY INCLUDES) set(VERSION "23.1") +set(PACKAGE "nzbget") +set(PACKAGE_BUGREPORT "https://github.com/nzbgetcom/nzbget/issues") +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_C_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_C_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) +set(CMAKE_C_EXTENSIONS OFF) +set(CMAKE_CONFIGURATION_TYPES "Release" "Debug") + +add_compile_definitions(HAVE_CONFIG_H=1) + +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Release" CACHE STRING "") +endif() + +option(BUILD_ONLY_TESTS "Build only tests (for CI)") project( - nzbget - VERSION ${VERSION} - DESCRIPTION "NZBGet is a binary downloader, which downloads files from Usenet" - LANGUAGES C CXX + nzbget + VERSION ${VERSION} + DESCRIPTION "NZBGet is a binary downloader, which downloads files from Usenet" + LANGUAGES C CXX ) -option(ENABLE_TESTS "Enable tests" ON) +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang") + set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g0 -pthread -g -Weverything -Wno-c++98-compat" CACHE STRING "" FORCE) + elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + set(CMAKE_CXX_FLAGS "-O0 -g0 -pthread -g -Wall -Wextra" CACHE STRING "" FORCE) + elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + set(CMAKE_CXX_FLAGS "/Od /Zi /MP /W4 /EHs /DDEBUG /D_DEBUG /DWIN32 /wd4800 /wd4267" CACHE STRING "" FORCE) + set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES} winmm.lib Dbghelp.lib libcpmtd.lib" CACHE STRING "" FORCE) + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDebug" CACHE STRING "" FORCE) + endif() +elseif(CMAKE_BUILD_TYPE STREQUAL "Release") + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang") + set(CMAKE_CXX_FLAGS "-O2 -g0 -pthread -DNDEBUG -Weverything -Wno-c++98-compat" CACHE STRING "" FORCE) + set(CMAKE_EXE_LINKER_FLAGS_RELEASE "-s" CACHE STRING "" FORCE) + elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + set(CMAKE_CXX_FLAGS "-O2 -g0 -pthread -DNDEBUG -Wall -Wextra" CACHE STRING "" FORCE) + set(CMAKE_EXE_LINKER_FLAGS_RELEASE "-s" CACHE STRING "" FORCE) + elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + set(CMAKE_CXX_FLAGS "/O2 /MP /W4 /EHs /DNDEBUG /DWIN32 /wd4800 /wd4267" CACHE STRING "" FORCE) + set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES} winmm.lib" CACHE STRING "" FORCE) + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded" CACHE STRING "" FORCE) + endif() +endif() + +set(CMAKE_C_FLAGS_DEBUG ${CMAKE_CXX_FLAGS} CACHE STRING "" FORCE) +set(CMAKE_C_FLAGS_RELEASE ${CMAKE_CXX_FLAGS} CACHE STRING "" FORCE) +set(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS} CACHE STRING "" FORCE) +set(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS} CACHE STRING "" FORCE) -set(PACKAGE "nzbget") -add_compile_definitions(HAVE_CONFIG_H=1) +include_directories(${CMAKE_BINARY_DIR}) +include_directories(${CMAKE_SOURCE_DIR}) + +if(NOT BUILD_ONLY_TESTS) + include(daemon/sources.cmake) + add_executable(${PACKAGE} ${SRC}) +endif() + +if(WIN32) + include(cmake/windows.cmake) + if(NOT BUILD_ONLY_TESTS) + target_sources(${PACKAGE} PRIVATE ${CMAKE_SOURCE_DIR}/windows/resources/nzbget.rc) + endif() +else() + include(cmake/posix.cmake) + if(NOT BUILD_ONLY_TESTS) + include(${CMAKE_SOURCE_DIR}/cmake/install.cmake) + endif() +endif() configure_file( - ${CMAKE_SOURCE_DIR}/cmake_config.h.in - ${CMAKE_BINARY_DIR}/config.h + ${CMAKE_SOURCE_DIR}/cmake/config.h.in + ${CMAKE_BINARY_DIR}/config.h ) -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_C_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_C_STANDARD_REQUIRED ON) -set(CMAKE_CXX_EXTENSIONS OFF) -set(CMAKE_C_EXTENSIONS OFF) -set(BUILD_SHARED_LIBS OFF) -set(OPENSSL_USE_STATIC_LIBS ON) -set(ZLIB_USE_STATIC_LIBS ON) -set(Boost_USE_STATIC_LIBS ON) -set(Boost_USE_MULTITHREADED ON) -set(Boost_USE_STATIC_RUNTIME OFF) -set(CMAKE_BUILD_TYPE "Release" CACHE STRING "") - -find_package(OpenSSL REQUIRED) -find_package(ZLIB REQUIRED) -find_package(LibXml2 REQUIRED) -find_package(Boost REQUIRED COMPONENTS json) - -if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -Weverything") -elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -Wall") -elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2 /W4") - set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} winmm.lib /NODEFAULTLIB:msvcrt.lib;libcmt.lib;msvcrtd.lib") +if(NOT BUILD_ONLY_TESTS) + target_link_libraries(${PACKAGE} PRIVATE ${LIBS}) + target_include_directories(${PACKAGE} PRIVATE + ${CMAKE_SOURCE_DIR}/daemon/connect + ${CMAKE_SOURCE_DIR}/daemon/extension + ${CMAKE_SOURCE_DIR}/daemon/feed + ${CMAKE_SOURCE_DIR}/daemon/frontend + ${CMAKE_SOURCE_DIR}/daemon/main + ${CMAKE_SOURCE_DIR}/daemon/nntp + ${CMAKE_SOURCE_DIR}/daemon/nserv + ${CMAKE_SOURCE_DIR}/daemon/postprocess + ${CMAKE_SOURCE_DIR}/daemon/queue + ${CMAKE_SOURCE_DIR}/daemon/remote + ${CMAKE_SOURCE_DIR}/daemon/util + ${INCLUDES} + ) endif() -include_directories(lib/regex) -include_directories(${CMAKE_BINARY_DIR}) -add_subdirectory(lib) - -if(ENABLE_TESTS) - include(CTest) - add_subdirectory(tests) +if(ENABLE_TESTS OR BUILD_ONLY_TESTS) + include(CTest) + add_subdirectory(tests) endif() diff --git a/INSTALLATION.md b/INSTALLATION.md index 2dd0fdef..1ffac7b1 100644 --- a/INSTALLATION.md +++ b/INSTALLATION.md @@ -58,19 +58,24 @@ If you have downloaded binaries you can just jump to section NZBGet is developed on a linux-system, but it runs on other POSIX platforms. -NZBGet absolutely needs the following libraries: +To build NZBGet you will need: - - libstdc++ (usually part of compiler) +For configuring and building: + - [CMake](https://cmake.org/) + - [GCC](https://gcc.gnu.org/) + + or + - [CLang](https://clang.llvm.org/) + +Libraries: - [libxml2](https://gitlab.gnome.org/GNOME/libxml2/-/wikis/home) - [Boost.JSON](https://www.boost.org/doc/libs/1_84_0/libs/json/doc/html/index.html) - - [Boost.Optional](https://www.boost.org/doc/libs/1_84_0/libs/optional/doc/html/index.html) +> If you face issues with Boost.JSON on your system, you can skip it - CMake will take care of it. And the following libraries are optional: For curses-output-mode (enabled by default): - - libcurses (usually part of commercial systems) - or (better) - - [libncurses](https://invisible-island.net/ncurses) + - [ncurses](https://invisible-island.net/ncurses) For encrypted connections (TLS/SSL): - [OpenSSL](https://www.openssl.org) @@ -80,60 +85,159 @@ And the following libraries are optional: For gzip support in web-server and web-client (enabled by default): - [zlib](https://www.zlib.net/) - - For configuration: - - [autotools](https://www.gnu.org/software/automake/manual/html_node/Autotools-Introduction.html) - - [autoconf](https://www.gnu.org/software/autoconf/) - - For managing package dependencies: - - [pkg-config](https://www.freedesktop.org/wiki/Software/pkg-config/) For tests: - [Boost.Test](https://www.boost.org/doc/libs/1_84_0/libs/test/doc/html/index.html) -All these libraries are included in modern POSIX distributions and -should be available as installable packages. Please note that you also + For static code analysis: + - [Clang-Tidy](https://clang.llvm.org/extra/clang-tidy/) + +Please note that you also need the developer packages for these libraries too, they package names have often suffix "dev" or "devel". On other systems you may need to download the libraries at the given URLs and compile them (see hints below). +### Debian: +``` + apt install cmake build-essential libncurses-dev libssl-dev libxml2-dev zlib1g-dev libboost-json1.81-dev +``` + - For tests: +``` + apt install libboost-test1.81-dev +``` + - For static code analysis: +``` + apt install clang-tidy +``` +### FreeBSD: +``` + pkg install cmake ncurses openssl libxml2 zlib boost-libs +``` +### macOS: +``` + xcode-select --install + brew install cmake ncurses openssl libxml2 zlib boost +``` + ## 4. Installation on POSIX Installation from the source distribution archive (nzbget-VERSION.tar.gz): - - untar the nzbget-source via - tar -zxf nzbget-VERSION.tar.gz - - - change into nzbget-directory via - cd nzbget-VERSION - - - configure it via - - autoreconf --install - - ./configure + - Untar the nzbget-source: +``` + tar -zxf nzbget-VERSION.tar.gz +``` + - Change into nzbget-directory: +``` + cd nzbget-VERSION +``` + - Configure: +``` + mkdir build + cd build + cmake .. +``` + - In a case you don't have root access or want to install the program + in your home directory use the configure parameter -DCMAKE_INSTALL_PREFIX: +``` + cmake .. -DCMAKE_INSTALL_PREFIX=~/usr +``` + - Build, specifying (-j 8) how many CPU cores to use to speed up compilation: +``` + cmake --build . -j 8 +``` + - Install: +``` + cmake --install . +``` + - Uninstall: +``` + cmake --build . --target uninstall +``` - (maybe you have to tell configure, where to find some libraries. - ./configure --help is your friend! - also see "Configure-options" later) +### Configure-options +--------------------- +You may run configure with additional arguments: + - Enable tests: +``` + cmake .. -DENABLE_TESTS=ON +``` + - Enable Clang-Tidy static code analizer: +``` + cmake .. -DENABLE_CLANG_TIDY=ON +``` + - Disable ncurses. Use this option if you can not use ncurses. +``` + cmake .. -DDISABLE_CURSES=ON +``` + - Disable parcheck. Use this option if you have troubles when compiling par2-module. +``` + cmake .. -DDISABLE_PARCHECK=ON +``` + - Use GnuTLS. Use this option if you want to use GnuTLS instead of OpenSSL. +``` + cmake .. -DUSE_GNUTLS=ON +``` + - Disable TLS. Use this option if you can not neither OpenSSL nor GnuTLS. +``` + cmake .. -DDISABLE_TLS=ON +``` + - Disable gzip. Use this option if you can not use zlib. +``` + cmake .. -DDISABLE_GZIP=ON +``` + - Disable sigchld-handler. The disabling may be neccessary on 32-Bit BSD. +``` + cmake .. -DDISABLE_SIGCHLD_HANDLER=ON +``` + - For debug build. +``` + cmake .. -DCMAKE_BUILD_TYPE=Debug +``` + - To get a static binary, +``` + cmake .. -DENABLE_STATIC=ON +``` + `LIBS` and `INCLUDES` env variables can be useful for static linking, since CMake looks for shared libraries by default +``` + export LIBS="-lncurses -ltinfo -lboost_json -lxml2 -lz -lm -lssl -lcrypto -Wl,--whole-archive -lpthread -Wl,--no-whole-archive" + export INCLUDES="/usr/include/;/usr/include/libxml2/" + cmake .. -DENABLE_STATIC=ON +``` +## Building using autotools (deprecated) + + - configure it via +``` + autoreconf --install + ./configure +``` + (maybe you have to tell configure, where to find some libraries then is your friend! +``` + ./configure --help +``` + also see "Configure-options" later) - in a case you don't have root access or want to install the program in your home directory use the configure parameter --prefix, e. g.: - +``` ./configure --prefix ~/usr - +``` - compile it via - make - +``` + make +``` - to install system wide become root via: - su - +``` + su +``` - install it via: - make install - +``` + make install +``` - install configuration files into /etc via: - make install-conf - +``` + make install-conf +``` (you can skip this step if you intend to store configuration files in a non-standard location) @@ -143,22 +247,22 @@ You may run configure with additional arguments: --disable-curses - to make without curses-support. Use this option if you can not use curses/ncurses. - + --disable-parcheck - to make without parcheck-support. Use this option if you have troubles when compiling par2-module. --with-tlslib=(OpenSSL, GnuTLS) - to select which TLS/SSL library should be used for encrypted server connections. - + --disable-tls - to make without TLS/SSL support. Use this option if you can not neither OpenSSL nor GnuTLS. --disable-gzip - to make without gzip support. Use this option if you can not use zlib. - + --enable-debug - to build in debug-mode, if you want to see and log debug-messages. - + ### Optional package: par-check ------------------------------- NZBGet can check and repair downloaded files for you. For this purpose @@ -169,8 +273,9 @@ NZBGet’s source tree and is compiled automatically when you make NZBGet. In a case errors occur during this process the inclusion of par2-module can be disabled using configure option "--disable-parcheck": - +``` ./configure --disable-parcheck +``` ### Optional package: curses ---------------------------- @@ -183,8 +288,9 @@ Following configure-parameters may be useful: If you are not able to use curses or ncurses or do not want them you can make the program without support for curses using option "--disable-curses": - +``` ./configure --disable-curses +``` ### Optional package: TLS ------------------------- @@ -193,9 +299,10 @@ with TLS/SSL support. NZBGet can use two libraries: OpenSSL or GnuTLS. Configure-script checks which library is installed and use it. If both are available it gives the precedence to OpenSSL. You may override that with the option --with-tlslib=(OpenSSL, GnuTLS). For example to build with GnuTLS: - +``` ./configure --with-tlslib= GnuTLS - +``` + Following configure-parameters may be useful: --with-libtls-includess=/path/to/gnutls/includes @@ -208,29 +315,65 @@ If none of these libraries is available you can make the program without TLS/SSL support using option "--disable-tls": ./configure --disable-tls - + ## 5. Compiling on Windows -NZBGet is developed using MS Visual Studio 2015 (Community Edition). The project -file is provided. +For configuring and building: + - [CMake](https://cmake.org/) + - [MS C++ Build tools](https://visualstudio.microsoft.com/downloads/?q=build+tools) -To compile the program with TLS/SSL support you need either OpenSSL or GnuTLS: +To compile the program with TLS/SSL support you need OpenSSL: - [OpenSSL](https://www.openssl.org) - or - - [GnuTLS](https://gnutls.org/) - Also required are: - - [Regex](https://regexlib.com/) - [Zlib](https://gnuwin32.sourceforge.net/packages/zlib.htm) - [libxml2](https://gitlab.gnome.org/GNOME/libxml2/-/wikis/home) - [Boost.JSON](https://www.boost.org/doc/libs/1_84_0/libs/json/doc/html/index.html) - [Boost.Optional](https://www.boost.org/doc/libs/1_84_0/libs/optional/doc/html/index.html) - For tests: - [Boost.Test](https://www.boost.org/doc/libs/1_84_0/libs/test/doc/html/index.html) -We recommend using [vcpkg](https://vcpkg.io/) to install dependencies. +We recommend using [vcpkg](https://vcpkg.io/) to install dependencies: + +``` + vcpkg install openssl:-windows-static + vcpkg install libxml2:-windows-static + vcpkg install zlib:-windows-static + vcpkg install boost-json:-windows-static + vcpkg install boost-optional:-windows-static +``` + - For tests: +``` + vcpkg install boost-test:-windows-static +``` + - Configure: +``` + mkdir build + cd build + cmake .. -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static -A x64 +``` + - For Win32: +``` + cmake .. -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x86-windows-static -A Win32 +``` + - For debug build: +``` + cmake .. -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static -DCMAKE_BUILD_TYPE=Debug +``` + - If Debug: +``` + cmake --build . --config Debug +``` + +You may run configure with additional arguments: + - Enable tests: +``` + cmake .. -DENABLE_TESTS=ON -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static +``` + - Disable TLS. Use this option if you can not neither OpenSSL nor GnuTLS. +``` + cmake .. -DDISABLE_TLS=ON -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static +``` ## 6. Configuration diff --git a/cmake/boost.cmake b/cmake/boost.cmake new file mode 100644 index 00000000..7d517368 --- /dev/null +++ b/cmake/boost.cmake @@ -0,0 +1,19 @@ +set(ROOT ${CMAKE_BINARY_DIR}/boost/) + +ExternalProject_add( + boost + PREFIX boost + URL https://github.com/boostorg/boost/releases/download/boost-1.84.0/boost-1.84.0.tar.xz + TLS_VERIFY TRUE + BUILD_IN_SOURCE TRUE + GIT_SHALLOW TRUE + DOWNLOAD_EXTRACT_TIMESTAMP TRUE + CONFIGURE_COMMAND ${ROOT}src/boost/bootstrap.sh + --with-libraries=json + --prefix=${ROOT}build + BUILD_COMMAND ${ROOT}src/boost/b2 link=static + INSTALL_COMMAND ${ROOT}src/boost/b2 install +) + +set(LIBS ${LIBS} ${ROOT}build/lib/libboost_json.a) +set(INCLUDES ${INCLUDES} ${ROOT}build/include/) diff --git a/cmake/config.h.in b/cmake/config.h.in new file mode 100644 index 00000000..0e8e0cfe --- /dev/null +++ b/cmake/config.h.in @@ -0,0 +1,168 @@ +/* Name of package */ +#cmakedefine PACKAGE "@PACKAGE@" + +/* Version number of package */ +#cmakedefine VERSION "@VERSION@" + +/* Define to the address where bug reports for this package should be sent. */ +#cmakedefine PACKAGE_BUGREPORT "@PACKAGE_BUGREPORT@" + +/* Define to 1 to not use curses */ +#cmakedefine DISABLE_CURSES + +/* Define to 1 to disable gzip-support */ +#cmakedefine DISABLE_GZIP + +/* Define to 1 to not use libxml2, only for development purposes */ +#cmakedefine DISABLE_LIBXML2 + +/* Define to 1 to disable par-verification and repair */ +#cmakedefine DISABLE_PARCHECK + +/* Define to 1 to not use TLS/SSL */ +#cmakedefine DISABLE_TLS + +/* Define to 1 to install an empty signal handler for SIGCHLD */ +#cmakedefine SIGCHLD_HANDLER @SIGCHLD_HANDLER@ + +/* Define to the name of macro which returns the name of function being + compiled */ +#cmakedefine FUNCTION_MACRO_NAME @FUNCTION_MACRO_NAME@ + +/* Define to 1 to create stacktrace on segmentation faults */ +#cmakedefine HAVE_BACKTRACE @HAVE_BACKTRACE@ + +/* Define to 1 if ctime_r takes 2 arguments */ +#cmakedefine HAVE_CTIME_R_2 @HAVE_CTIME_R_2@ + +/* Define to 1 if ctime_r takes 3 arguments */ +#cmakedefine HAVE_CTIME_R_3 @HAVE_CTIME_R_3@ + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_CURSES_H @HAVE_CURSES_H@ + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_ENDIAN_H @HAVE_ENDIAN_H@ + +/* Define to 1 if fdatasync is supported */ +#cmakedefine HAVE_FDATASYNC @HAVE_FDATASYNC@ + +/* Define to 1 if fseeko (and presumably ftello) exists and is declared. */ +#cmakedefine HAVE_FSEEKO @HAVE_FSEEKO@ + +/* Define to 1 if F_FULLFSYNC is supported */ +#cmakedefine HAVE_FULLFSYNC @HAVE_FULLFSYNC@ + +/* Define to 1 if getaddrinfo is supported */ +#cmakedefine HAVE_GETADDRINFO @HAVE_GETADDRINFO@ + +/* Define to 1 if gethostbyname_r is supported */ +#cmakedefine HAVE_GETHOSTBYNAME_R @HAVE_GETHOSTBYNAME_R@ + +/* Define to 1 if gethostbyname_r takes 3 arguments */ +#cmakedefine HAVE_GETHOSTBYNAME_R_3 @HAVE_GETHOSTBYNAME_R_3@ + +/* Define to 1 if gethostbyname_r takes 5 arguments */ +#cmakedefine HAVE_GETHOSTBYNAME_R_5 @HAVE_GETHOSTBYNAME_R_5@ + +/* Define to 1 if gethostbyname_r takes 6 arguments */ +#cmakedefine HAVE_GETHOSTBYNAME_R_6 @HAVE_GETHOSTBYNAME_R_6@ + +/* Define to 1 if you have the `getopt' function. */ +#cmakedefine HAVE_GETOPT @HAVE_GETOPT@ + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_GETOPT_H @HAVE_GETOPT_H@ + +/* Define to 1 if getopt_long is supported */ +#cmakedefine HAVE_GETOPT_LONG @HAVE_GETOPT_LONG@ + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_INTTYPES_H @HAVE_INTTYPES_H@ + +/* Define to 1 to use GnuTLS library for TLS/SSL-support. */ +#cmakedefine HAVE_LIBGNUTLS @HAVE_LIBGNUTLS@ + +/* Define to 1 if lockf is supported */ +#cmakedefine HAVE_LOCKF @HAVE_LOCKF@ + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_NCURSES_H @HAVE_NCURSES_H@ + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_NCURSES_NCURSES_H @HAVE_NCURSES_NCURSES_H@ + +/* Define to 1 to use Nettle library for decryption. */ +#cmakedefine HAVE_NETTLE @HAVE_NETTLE@ + +/* Define to 1 to use OpenSSL library for TLS/SSL-support and decryption. */ +#cmakedefine HAVE_OPENSSL @HAVE_OPENSSL@ + +/* Define to 1 if pthread_cancel is supported */ +#cmakedefine HAVE_PTHREAD_CANCEL @HAVE_PTHREAD_CANCEL@ + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_REGEX_H @HAVE_REGEX_H@ + +/* Define to 1 if _SC_NPROCESSORS_ONLN is present in unistd.h */ +#cmakedefine HAVE_SC_NPROCESSORS_ONLN @HAVE_SC_NPROCESSORS_ONLN@ + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STDINT_H @HAVE_STDINT_H@ + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STDIO_H @HAVE_STDIO_H@ + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STDLIB_H @HAVE_STDLIB_H@ + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STRINGS_H @HAVE_STRINGS_H@ + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_STRING_H @HAVE_STRING_H@ + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_PRCTL_H @HAVE_SYS_PRCTL_H@ + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_STAT_H @HAVE_SYS_STAT_H@ + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_TYPES_H @HAVE_SYS_TYPES_H@ + +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_UNISTD_H @HAVE_UNISTD_H@ + +/* Define to 1 if variadic macros are supported */ +#cmakedefine HAVE_VARIADIC_MACROS @HAVE_VARIADIC_MACROS@ + +/* Define to 1 if OpenSSL supports function "X509_check_host" */ +#cmakedefine HAVE_X509_CHECK_HOST @HAVE_X509_CHECK_HOST@ + +/* Determine what socket length (socklen_t) data type is */ +#cmakedefine SOCKLEN_T @SOCKLEN_T@ + +/* Number of bits in a file offset, on hosts where this is settable. */ +#cmakedefine _FILE_OFFSET_BITS @_FILE_OFFSET_BITS@ + +/* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */ +#cmakedefine _LARGEFILE_SOURCE @_LARGEFILE_SOURCE@ + +/* Define for large files, on AIX-style hosts. */ +#cmakedefine _LARGE_FILES @_LARGE_FILES@ + +/* Define to `unsigned int' if does not define. */ +#cmakedefine size_t @size_t@ + +/* Define if AMD64 */ +#cmakedefine __amd64__ + +/* Define if i686 */ +#cmakedefine __i686__ + +/* Use 32BIT TIME_T */ +#cmakedefine _USE_32BIT_TIME_T + +/* detection of memory leaks */ +#cmakedefine _CRTDBG_MAP_ALLOC diff --git a/cmake/install.cmake b/cmake/install.cmake new file mode 100644 index 00000000..3175b3be --- /dev/null +++ b/cmake/install.cmake @@ -0,0 +1,43 @@ +set(DOC_FILES + ${CMAKE_SOURCE_DIR}/ChangeLog + ${CMAKE_SOURCE_DIR}/COPYING +) +set(SHARE_DIR ${CMAKE_INSTALL_PREFIX}/share/${PACKAGE}) +set(CONF_FILE ${CMAKE_SOURCE_DIR}/nzbget.conf) +set(WEBUI_DIR ${CMAKE_SOURCE_DIR}/webui) +set(DOC_FILES_DEST ${SHARE_DIR}/doc) +set(CONF_FILE_DEST ${SHARE_DIR}) +set(WEBUI_DIR_DEST ${SHARE_DIR}) +set(BIN_FILE_DEST ${CMAKE_INSTALL_PREFIX}/bin) + +install(TARGETS ${PACKAGE} PERMISSIONS + OWNER_EXECUTE + OWNER_WRITE + OWNER_READ + GROUP_READ + GROUP_EXECUTE + WORLD_READ + WORLD_EXECUTE + DESTINATION ${BIN_FILE_DEST}) +install(FILES ${DOC_FILES} DESTINATION ${DOC_FILES_DEST}) +install(DIRECTORY ${WEBUI_DIR} DESTINATION ${WEBUI_DIR_DEST}) + +file(READ ${CONF_FILE} CONFIG_CONTENT) +string(REPLACE "WebDir=" "WebDir=${WEBUI_DIR_DEST}/webui" MODIFIED_CONFIG_CONTENT "${CONFIG_CONTENT}") +string(REPLACE "ConfigTemplate=" "ConfigTemplate=${CONF_FILE_DEST}/nzbget.conf" MODIFIED_CONFIG_CONTENT "${MODIFIED_CONFIG_CONTENT}") +file(WRITE ${CMAKE_BINARY_DIR}/nzbget.conf "${MODIFIED_CONFIG_CONTENT}") +install(FILES ${CMAKE_BINARY_DIR}/nzbget.conf DESTINATION ${CONF_FILE_DEST}) + +if(NOT EXISTS ${CMAKE_INSTALL_PREFIX}/etc/nzbget.conf) + install(FILES ${CMAKE_BINARY_DIR}/nzbget.conf DESTINATION ${CMAKE_INSTALL_PREFIX}/etc) +else() + message(STATUS "nzbget.conf is already installed in ${CMAKE_INSTALL_PREFIX}/etc") + message(STATUS "If you want to overwrite it, then do it manually with caution") +endif() + +add_custom_target(uninstall + COMMAND ${CMAKE_COMMAND} -E remove_directory ${DOC_FILES_DEST} + COMMAND ${CMAKE_COMMAND} -E remove_directory ${SHARE_DIR} + COMMAND ${CMAKE_COMMAND} -E remove ${BIN_FILE_DEST}/${PACKAGE} + COMMENT "Uninstalling" ${PACKAGE} +) diff --git a/cmake/posix.cmake b/cmake/posix.cmake new file mode 100644 index 00000000..376d92ea --- /dev/null +++ b/cmake/posix.cmake @@ -0,0 +1,337 @@ +option(ENABLE_STATIC "Build static executable") +option(ENABLE_TESTS "Build tests") +option(ENABLE_CLANG_TIDY "Enable Clang-Tidy static analizer") +option(DISABLE_TLS "Disable TLS") +option(DISABLE_CURSES "Disable curses") +option(DISABLE_GZIP "Disable gzip") +option(DISABLE_PARCHECK "Disable parcheck") +option(USE_OPENSSL "Use OpenSSL" ON) +option(USE_GNUTLS "Use GnuTLS" OFF) + +if(NOT DISABLE_TLS AND USE_GNUTLS) + set(USE_OPENSSL OFF) +endif() + +if(DISABLE_TLS) + set(USE_GNUTLS OFF) + set(USE_OPENSSL OFF) +endif() + +message(STATUS "TOOLCHAIN OPTIONS:") +message(STATUS " SYSTEM NAME ${CMAKE_SYSTEM_NAME}") +message(STATUS " SYSTEM PROCESSOR ${CMAKE_SYSTEM_PROCESSOR}") +message(STATUS "BUILD OPTIONS:") +message(STATUS " BUILD TYPE: ${CMAKE_BUILD_TYPE}") +message(STATUS " ENABLE STATIC: ${ENABLE_STATIC}") +message(STATUS " ENABLE TESTS: ${ENABLE_TESTS}") +message(STATUS " DISABLE TLS: ${DISABLE_TLS}") +message(STATUS " - OPENSSL: ${USE_OPENSSL}") +message(STATUS " - GNUTLS: ${USE_GNUTLS}") +message(STATUS " DISABLE CURSES: ${DISABLE_CURSES}") +message(STATUS " DISABLE GZIP: ${DISABLE_GZIP}") +message(STATUS " DISABLE PARCHECK: ${DISABLE_PARCHECK}") + +if(ENABLE_CLANG_TIDY) + set(CMAKE_CXX_CLANG_TIDY clang-tidy -checks=-*,readability-*) +endif() + +if(ENABLE_STATIC) + # due to the error "ld: library not found for -crt0.o" when using Apple Clang with "-static" + if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") + set(CMAKE_EXE_LINKER_FLAGS_DEBUG "-static" CACHE STRING "" FORCE) + set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -static" CACHE STRING "" FORCE) + endif() + set(BUILD_SHARED_LIBS OFF) + set(LIBS $ENV{LIBS}) + set(INCLUDES $ENV{INCLUDES}) + include(${CMAKE_SOURCE_DIR}/lib/sources.cmake) +else() + find_package(Threads REQUIRED) + find_package(LibXml2 REQUIRED) + + set(LIBS ${LIBS} Threads::Threads LibXml2::LibXml2) + set(INCLUDES ${INCLUDES} ${LIBXML2_INCLUDE_DIR}) + + if(NOT DISABLE_TLS) + if(USE_OPENSSL AND NOT USE_GNUTLS) + find_package(OpenSSL REQUIRED) + set(LIBS ${LIBS} OpenSSL::SSL OpenSSL::Crypto) + set(INCLUDES ${INCLUDES} ${OPENSSL_INCLUDE_DIR}) + elseif(USE_GNUTLS) + find_package(GnuTLS REQUIRED) + find_library(NETTLE_LIBRARY NAMES nettle libnettle) + set(INCLUDES ${INCLUDES} ${GNUTLS_INCLUDE_DIRS}) + set(LIBS ${LIBS} GnuTLS::GnuTLS ${NETTLE_LIBRARY}) + endif() + endif() + + if(NOT DISABLE_CURSES) + set(CURSES_NEED_NCURSES TRUE) + find_package(Curses REQUIRED) + set(INCLUDES ${INCLUDES} ${CURSES_INCLUDE_DIRS}) + set(LIBS ${LIBS} ${CURSES_LIBRARIES}) + endif() + + if(NOT DISABLE_GZIP) + find_package(ZLIB REQUIRED) + set(INCLUDES ${INCLUDES} ${ZLIB_INCLUDE_DIRS}) + set(LIBS ${LIBS} ZLIB::ZLIB) + endif() + + find_package(Boost COMPONENTS json) + + if(NOT Boost_JSON_FOUND) + message(STATUS "The Boost library will be installed from github") + include(ExternalProject) + + include(${CMAKE_SOURCE_DIR}/cmake/boost.cmake) + + include(${CMAKE_SOURCE_DIR}/lib/sources.cmake) + + add_dependencies(${PACKAGE} boost) + add_dependencies(yencode boost) + add_dependencies(par2 boost) + add_dependencies(regex boost) + else() + set(LIBS ${LIBS} Boost::json) + set(INCLUDES ${INCLUDES} ${Boost_INCLUDE_DIR}) + + include(${CMAKE_SOURCE_DIR}/lib/sources.cmake) + endif() +endif() + +include(CheckIncludeFiles) +include(CheckLibraryExists) +include(CheckSymbolExists) +include(CheckFunctionExists) +include(CheckTypeSize) +include(CheckCSourceCompiles) +include(CheckCXXSourceCompiles) + +check_include_files(sys/prctl.h HAVE_SYS_PRCTL_H) +check_include_files(regex.h HAVE_REGEX_H) +check_include_files(endian.h HAVE_ENDIAN_H) +check_include_files(getopt.h HAVE_GETOPT_H) +check_include_file(inttypes.h HAVE_INTTYPES_H) +check_include_file(stdint.h HAVE_STDINT_H) +check_include_file(stdio.h HAVE_STDIO_H) +check_include_file(stdlib.h HAVE_STDLIB_H) +check_include_file(strings.h HAVE_STRINGS_H) +check_include_file(string.h HAVE_STRING_H) +check_include_file(sys/stat.h HAVE_SYS_STAT_H) +check_include_file(unistd.h HAVE_UNISTD_H) + +check_library_exists(pthread pthread_create "" HAVE_PTHREAD_CREATE) +check_library_exists(socket socket "" HAVE_SOCKET) +check_library_exists(nsl inet_addr "" HAVE_INET_ADDR) +check_library_exists(resolv hstrerror "" HAVE_HSTRERROR) + +check_symbol_exists(lockf unistd.h HAVE_LOCKF) +check_symbol_exists(pthread_cancel pthread.h HAVE_PTHREAD_CANCEL) +check_symbol_exists(F_FULLFSYNC fcntl.h HAVE_FULLFSYNC) + +check_function_exists(getopt_long HAVE_GETOPT_LONG) +check_function_exists(fdatasync HAVE_FDATASYNC) + +set(SIGCHLD_HANDLER 1) + +if(USE_OPENSSL) + set(HAVE_OPENSSL 1) +endif() + +if(USE_GNUTLS) + set(HAVE_LIBGNUTLS 1) + set(HAVE_NETTLE 1) +endif() + +if(NOT DISABLE_CURSES) + set(HAVE_NCURSES_H 1) +endif() + +if(NOT DISABLED_PARCHECK) + check_type_size(size_t SIZE_T) + check_symbol_exists(fseeko "stdio.h" HAVE_FSEEKO) + check_function_exists(getopt HAVE_GETOPT) +else() + set(DISABLED_PARCHECK 1) +endif() + +# check ctime_r +check_cxx_source_compiles(" + #include + int main() + { + time_t clock; + char buf[26]; + ctime_r(&clock, buf, 26); + return 0; + }" HAVE_CTIME_R_3) + +if(NOT HAVE_CTIME_R_3) + check_cxx_source_compiles(" + #include + int main() + { + time_t clock; + char buf[26]; + ctime_r(&clock, buf); + return 0; + }" HAVE_CTIME_R_2) +endif() +if(NOT HAVE_CTIME_R_2) + message(FATAL_ERROR "ctime_r function not found") +endif() + +check_function_exists(getaddrinfo HAVE_GETADDRINFO) +if(NOT HAVE_GETADDRINFO) + check_library_exists(nsl getaddrinfo "" HAVE_GETADDRINFO) +endif() + +# check gethostbyname_r, if getaddrinfo is not available +if(NOT HAVE_GETADDRINFO) + check_cxx_source_compiles(" + #include + int main() + { + char* szHost; + struct hostent hinfobuf; + char* strbuf; + int h_errnop; + struct hostent* hinfo = gethostbyname_r(szHost, &hinfobuf, strbuf, 1024, &h_errnop); + return 0; + }" HAVE_GETHOSTBYNAME_R_5) +if(NOT HAVE_GETHOSTBYNAME_R_5) + check_cxx_source_compiles(" + #include + int main() + { + char* szHost; + struct hostent* hinfo; + struct hostent hinfobuf; + char* strbuf; + int h_errnop; + int err = gethostbyname_r(szHost, &hinfobuf, strbuf, 1024, &hinfo, &h_errnop); + return 0; + }" HAVE_GETHOSTBYNAME_R_6) +if(NOT HAVE_GETHOSTBYNAME_R_6) + check_cxx_source_compiles(" + #include + int main() + { + char* szHost; + struct hostent hinfo; + struct hostent_data hinfobuf; + int err = gethostbyname_r(szHost, &hinfo, &hinfobuf); + return 0; + }" HAVE_GETHOSTBYNAME_R_3) +if(NOT HAVE_GETHOSTBYNAME_R_3) + message(FATAL_ERROR "gethostbyname_r function not found") +endif() +endif() +endif() +if (NOT HAVE_GETHOSTBYNAME_R_3) + set(HAVE_GETHOSTBYNAME_R 1) + check_library_exists(nsl gethostbyname_r "" HAVE_GETHOSTBYNAME_R) +endif() +endif() + +# Determine what socket length (socklen_t) data type is +check_cxx_source_compiles(" + #include + #include + #include + int main() + { + (void)getsockopt (1, 1, 1, NULL, (socklen_t*)NULL); + }" SOCKLEN) +if(SOCKLEN) + set(SOCKLEN_T socklen_t) +else() + check_cxx_source_compiles(" + #include + #include + #include + int main() + { + (void)getsockopt (1, 1, 1, NULL, (size_t*)NULL); + }" SOCKLEN) +if(SOCKLEN) + set(SOCKLEN_T size_t) +else() + check_cxx_source_compiles(" + #include + #include + #include + int main() + { + (void)getsockopt (1, 1, 1, NULL, (int*)NULL); + }" SOCKLEN) +if(SOCKLEN) + set(SOCKLEN_T int) +else() + set(SOCKLEN_T int) +endif() +endif() +endif() + +# Check CPU cores via sysconf +check_cxx_source_compiles(" + #include + int main() + { + int a = _SC_NPROCESSORS_ONLN; + }" HAVE_SC_NPROCESSORS_ONLN) + +# Check TLS/SSL +if(USE_OPENSSL AND NOT ENABLE_STATIC) + check_library_exists(OpenSSL::Crypto X509_check_host "" HAVE_X509_CHECK_HOST) +endif() + +check_cxx_source_compiles(" + #include + int main() + { + printf(\"%s\", __FUNCTION__); + return 0; + }" FUNCTION_MACRO_NAME_ONE) + +check_cxx_source_compiles(" + #include + int main() + { + printf(\"%s\", __func__); + return 0; + }" FUNCTION_MACRO_NAME_TWO) + +if(FUNCTION_MACRO_NAME_ONE) + set(FUNCTION_MACRO_NAME __FUNCTION__) +elseif (FUNCTION_MACRO_NAME_TWO) + set(FUNCTION_MACRO_NAME __func__) +endif() + +check_cxx_source_compiles(" + #define macro(...) macrofunc(__VA_ARGS__) + int macrofunc(int a, int b) { return a + b; } + int main() + { + int a = macro(1, 2); + return 0; + }" HAVE_VARIADIC_MACROS) + +if(HAVE_VARIADIC_MACROS) + set(DHAVE_VARIADIC_MACROS 1) +endif() + +check_cxx_source_compiles(" + #include + #include + #include + int main() + { + void* array[100]; + size_t size; + char** strings; + size = backtrace(array, 100); + strings = backtrace_symbols(array, size); + return 0; + }" HAVE_BACKTRACE) diff --git a/cmake/toolchain.cmake b/cmake/toolchain.cmake new file mode 100644 index 00000000..32978688 --- /dev/null +++ b/cmake/toolchain.cmake @@ -0,0 +1,19 @@ +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR ${ARCH}) + +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) + +set(CMAKE_AR ${TOOLCHAIN_PREFIX}-ar) +set(CMAKE_ASM_COMPILER ${TOOLCHAIN_PREFIX}-as) +set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc) +set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++) +set(CMAKE_LINKER ${TOOLCHAIN_PREFIX}-ld) +set(CMAKE_OBJCOPY ${TOOLCHAIN_PREFIX}-objcopy) +set(CMAKE_RANLIB ${TOOLCHAIN_PREFIX}-ranlib) +set(CMAKE_SIZE ${TOOLCHAIN_PREFIX}-size) +set(CMAKE_STRIP ${TOOLCHAIN_PREFIX}-strip) + +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) diff --git a/cmake/windows.cmake b/cmake/windows.cmake new file mode 100644 index 00000000..bfc265bd --- /dev/null +++ b/cmake/windows.cmake @@ -0,0 +1,57 @@ +option(ENABLE_TESTS "Enable tests") +option(DISABLE_TLS "Disable TLS") + +message(STATUS "TOOLCHAIN OPTIONS:") +message(STATUS " SYSTEM NAME ${CMAKE_SYSTEM_NAME}") +message(STATUS " SYSTEM PROCESSOR ${CMAKE_SYSTEM_PROCESSOR}") +message(STATUS " TARGET TRIPLET ${VCPKG_TARGET_TRIPLET}") +message(STATUS "BUILD OPTIONS:") +message(STATUS " BUILD TYPE: ${CMAKE_BUILD_TYPE}") +message(STATUS " ENABLE TESTS: ${ENABLE_TESTS}") +message(STATUS " DISABLE TLS: ${DISABLE_TLS}") + +set(Boost_USE_STATIC_LIBS ON) + +find_package(Threads REQUIRED) +find_package(LibXml2 REQUIRED) +find_package(Boost REQUIRED COMPONENTS json) + +set(LIBS Threads::Threads Boost::json LibXml2::LibXml2) +set(INCLUDES ${Boost_INCLUDE_DIR} ${LIBXML2_INCLUDE_DIR}) + +if(NOT DISABLE_TLS) + find_package(OpenSSL REQUIRED) + set(HAVE_OPENSSL 1) + set(HAVE_X509_CHECK_HOST 1) + set(LIBS ${LIBS} OpenSSL::SSL OpenSSL::Crypto) + set(INCLUDES ${INCLUDES} ${OPENSSL_INCLUDE_DIR}) +endif() + +find_package(ZLIB REQUIRED) +set(LIBS ${LIBS} ZLIB::ZLIB) +set(INCLUDES ${INCLUDES} ${ZLIB_INCLUDE_DIRS}) + +include(${CMAKE_SOURCE_DIR}/lib/sources.cmake) +set(INCLUDES ${INCLUDES} + ${CMAKE_SOURCE_DIR}/daemon/windows + ${CMAKE_SOURCE_DIR}/windows/resources +) + +set(FUNCTION_MACRO_NAME __FUNCTION__) +set(HAVE_CTIME_R_3 1) +set(HAVE_VARIADIC_MACROS 1) +set(HAVE_GETADDRINFO 1) +set(SOCKLEN_T socklen_t) +set(HAVE_REGEX_H 1) +set(HAVE_STDINT_H 1) + +if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(__amd64__ 1) +else() + set(__i686__ 1) + set(_USE_32BIT_TIME_T 1) +endif() + +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + set(_CRTDBG_MAP_ALLOC 1) +endif() diff --git a/cmake_config.h.in b/cmake_config.h.in deleted file mode 100644 index aa35cd47..00000000 --- a/cmake_config.h.in +++ /dev/null @@ -1,5 +0,0 @@ -/* Name of package */ -#cmakedefine PACKAGE "@PACKAGE@" - -/* Version number of package */ -#cmakedefine VERSION "@VERSION@" diff --git a/daemon/main/Options.cpp b/daemon/main/Options.cpp index b10b6bda..ead51f06 100644 --- a/daemon/main/Options.cpp +++ b/daemon/main/Options.cpp @@ -187,6 +187,7 @@ const char* PossibleConfigLocations[] = "/usr/etc/nzbget.conf", "/usr/local/etc/nzbget.conf", "/opt/etc/nzbget.conf", + "~/usr/etc/nzbget.conf", nullptr }; #endif diff --git a/daemon/main/nzbget.h b/daemon/main/nzbget.h index 98bd04fa..2ec287b6 100644 --- a/daemon/main/nzbget.h +++ b/daemon/main/nzbget.h @@ -112,11 +112,9 @@ compiled */ #endif - /***************** GLOBAL INCLUDES *****************/ #ifdef WIN32 - // WINDOWS INCLUDES // Using "WIN32_LEAN_AND_MEAN" to disable including of many unneeded headers @@ -138,14 +136,8 @@ compiled */ #include #include #include - #include -#if _MSC_VER >= 1600 -#include -#define HAVE_STDINT_H -#endif - #ifdef _DEBUG #include #endif @@ -159,9 +151,7 @@ compiled */ #include #include #include -#include #include -#include #include #include #include @@ -172,8 +162,6 @@ compiled */ #include #include #include -#include -#include #include #ifdef HAVE_SYS_PRCTL_H @@ -200,6 +188,7 @@ compiled */ #include #include #include +#include #include #include #include diff --git a/daemon/sources.cmake b/daemon/sources.cmake new file mode 100644 index 00000000..8f764e46 --- /dev/null +++ b/daemon/sources.cmake @@ -0,0 +1,105 @@ +set(SRC + ${CMAKE_SOURCE_DIR}/daemon/connect/Connection.cpp + ${CMAKE_SOURCE_DIR}/daemon/connect/TlsSocket.cpp + ${CMAKE_SOURCE_DIR}/daemon/connect/WebDownloader.cpp + + ${CMAKE_SOURCE_DIR}/daemon/extension/CommandScript.cpp + ${CMAKE_SOURCE_DIR}/daemon/extension/FeedScript.cpp + ${CMAKE_SOURCE_DIR}/daemon/extension/NzbScript.cpp + ${CMAKE_SOURCE_DIR}/daemon/extension/PostScript.cpp + ${CMAKE_SOURCE_DIR}/daemon/extension/PostScript.cpp + ${CMAKE_SOURCE_DIR}/daemon/extension/QueueScript.cpp + ${CMAKE_SOURCE_DIR}/daemon/extension/ScanScript.cpp + ${CMAKE_SOURCE_DIR}/daemon/extension/SchedulerScript.cpp + ${CMAKE_SOURCE_DIR}/daemon/extension/ScriptConfig.cpp + ${CMAKE_SOURCE_DIR}/daemon/extension/ScriptConfig.cpp + ${CMAKE_SOURCE_DIR}/daemon/extension/Extension.cpp + ${CMAKE_SOURCE_DIR}/daemon/extension/ExtensionLoader.cpp + ${CMAKE_SOURCE_DIR}/daemon/extension/ExtensionManager.cpp + ${CMAKE_SOURCE_DIR}/daemon/extension/ManifestFile.cpp + + ${CMAKE_SOURCE_DIR}/daemon/feed/FeedCoordinator.cpp + ${CMAKE_SOURCE_DIR}/daemon/feed/FeedFile.cpp + ${CMAKE_SOURCE_DIR}/daemon/feed/FeedFilter.cpp + ${CMAKE_SOURCE_DIR}/daemon/feed/FeedInfo.cpp + + ${CMAKE_SOURCE_DIR}/daemon/frontend/ColoredFrontend.cpp + ${CMAKE_SOURCE_DIR}/daemon/frontend/Frontend.cpp + ${CMAKE_SOURCE_DIR}/daemon/frontend/LoggableFrontend.cpp + ${CMAKE_SOURCE_DIR}/daemon/frontend/NCursesFrontend.cpp + + ${CMAKE_SOURCE_DIR}/daemon/main/CommandLineParser.cpp + ${CMAKE_SOURCE_DIR}/daemon/main/DiskService.cpp + ${CMAKE_SOURCE_DIR}/daemon/main/Maintenance.cpp + ${CMAKE_SOURCE_DIR}/daemon/main/nzbget.cpp + ${CMAKE_SOURCE_DIR}/daemon/main/Options.cpp + ${CMAKE_SOURCE_DIR}/daemon/main/Scheduler.cpp + ${CMAKE_SOURCE_DIR}/daemon/main/StackTrace.cpp + ${CMAKE_SOURCE_DIR}/daemon/main/WorkState.cpp + + ${CMAKE_SOURCE_DIR}/daemon/nntp/ArticleDownloader.cpp + ${CMAKE_SOURCE_DIR}/daemon/nntp/ArticleWriter.cpp + ${CMAKE_SOURCE_DIR}/daemon/nntp/Decoder.cpp + ${CMAKE_SOURCE_DIR}/daemon/nntp/NewsServer.cpp + ${CMAKE_SOURCE_DIR}/daemon/nntp/NntpConnection.cpp + ${CMAKE_SOURCE_DIR}/daemon/nntp/ServerPool.cpp + ${CMAKE_SOURCE_DIR}/daemon/nntp/StatMeter.cpp + + ${CMAKE_SOURCE_DIR}/daemon/nserv/NntpServer.cpp + ${CMAKE_SOURCE_DIR}/daemon/nserv/NServFrontend.cpp + ${CMAKE_SOURCE_DIR}/daemon/nserv/NServMain.cpp + ${CMAKE_SOURCE_DIR}/daemon/nserv/NzbGenerator.cpp + ${CMAKE_SOURCE_DIR}/daemon/nserv/YEncoder.cpp + + ${CMAKE_SOURCE_DIR}/daemon/postprocess/Cleanup.cpp + ${CMAKE_SOURCE_DIR}/daemon/postprocess/DirectUnpack.cpp + ${CMAKE_SOURCE_DIR}/daemon/postprocess/DupeMatcher.cpp + ${CMAKE_SOURCE_DIR}/daemon/postprocess/ParChecker.cpp + ${CMAKE_SOURCE_DIR}/daemon/postprocess/ParParser.cpp + ${CMAKE_SOURCE_DIR}/daemon/postprocess/ParRenamer.cpp + ${CMAKE_SOURCE_DIR}/daemon/postprocess/PrePostProcessor.cpp + ${CMAKE_SOURCE_DIR}/daemon/postprocess/RarReader.cpp + ${CMAKE_SOURCE_DIR}/daemon/postprocess/RarRenamer.cpp + ${CMAKE_SOURCE_DIR}/daemon/postprocess/Rename.cpp + ${CMAKE_SOURCE_DIR}/daemon/postprocess/Repair.cpp + ${CMAKE_SOURCE_DIR}/daemon/postprocess/Unpack.cpp + + ${CMAKE_SOURCE_DIR}/daemon/queue/DirectRenamer.cpp + ${CMAKE_SOURCE_DIR}/daemon/queue/DiskState.cpp + ${CMAKE_SOURCE_DIR}/daemon/queue/DownloadInfo.cpp + ${CMAKE_SOURCE_DIR}/daemon/queue/DupeCoordinator.cpp + ${CMAKE_SOURCE_DIR}/daemon/queue/HistoryCoordinator.cpp + ${CMAKE_SOURCE_DIR}/daemon/queue/NzbFile.cpp + ${CMAKE_SOURCE_DIR}/daemon/queue/QueueCoordinator.cpp + ${CMAKE_SOURCE_DIR}/daemon/queue/QueueEditor.cpp + ${CMAKE_SOURCE_DIR}/daemon/queue/Scanner.cpp + ${CMAKE_SOURCE_DIR}/daemon/queue/UrlCoordinator.cpp + + ${CMAKE_SOURCE_DIR}/daemon/remote/BinRpc.cpp + ${CMAKE_SOURCE_DIR}/daemon/remote/RemoteClient.cpp + ${CMAKE_SOURCE_DIR}/daemon/remote/RemoteServer.cpp + ${CMAKE_SOURCE_DIR}/daemon/remote/WebServer.cpp + ${CMAKE_SOURCE_DIR}/daemon/remote/XmlRpc.cpp + ${CMAKE_SOURCE_DIR}/daemon/remote/MessageBase.h + + ${CMAKE_SOURCE_DIR}/daemon/util/FileSystem.cpp + ${CMAKE_SOURCE_DIR}/daemon/util/Log.cpp + ${CMAKE_SOURCE_DIR}/daemon/util/NString.cpp + ${CMAKE_SOURCE_DIR}/daemon/util/Observer.cpp + ${CMAKE_SOURCE_DIR}/daemon/util/ScriptController.cpp + ${CMAKE_SOURCE_DIR}/daemon/util/Service.cpp + ${CMAKE_SOURCE_DIR}/daemon/util/Thread.cpp + ${CMAKE_SOURCE_DIR}/daemon/util/Util.cpp + ${CMAKE_SOURCE_DIR}/daemon/util/Json.cpp + ${CMAKE_SOURCE_DIR}/daemon/util/Xml.cpp +) + +set(WIN32_SRC + ${CMAKE_SOURCE_DIR}/daemon/windows/StdAfx.cpp + ${CMAKE_SOURCE_DIR}/daemon/windows/WinConsole.cpp + ${CMAKE_SOURCE_DIR}/daemon/windows/WinService.cpp +) + +if(WIN32) + set(SRC ${SRC} ${WIN32_SRC}) +endif() diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt deleted file mode 100644 index c879cc88..00000000 --- a/lib/CMakeLists.txt +++ /dev/null @@ -1,45 +0,0 @@ -add_library(Yencode STATIC - ${CMAKE_CURRENT_SOURCE_DIR}/yencode/SimdInit.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/yencode/SimdDecoder.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/yencode/ScalarDecoder.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/yencode/Sse2Decoder.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/yencode/Ssse3Decoder.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/yencode/PclmulCrc.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/yencode/NeonDecoder.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/yencode/AcleCrc.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/yencode/SliceCrc.cpp -) -target_include_directories(Yencode PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/yencode - ${CMAKE_SOURCE_DIR}/daemon/main - ${ZLIB_INCLUDE_DIR} - ${OPENSSL_INCLUDE_DIR} -) - -add_library(Par2 STATIC - ${CMAKE_CURRENT_SOURCE_DIR}/par2/commandline.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/par2/crc.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/par2/creatorpacket.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/par2/criticalpacket.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/par2/datablock.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/par2/descriptionpacket.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/par2/diskfile.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/par2/filechecksummer.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/par2/galois.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/par2/mainpacket.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/par2/md5.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/par2/par2fileformat.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/par2/par2repairer.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/par2/par2repairersourcefile.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/par2/parheaders.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/par2/recoverypacket.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/par2/reedsolomon.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/par2/verificationhashtable.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/par2/verificationpacket.cpp -) -target_include_directories(Par2 PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/par2 - ${CMAKE_SOURCE_DIR}/daemon/main - ${CMAKE_SOURCE_DIR}/daemon/util - ${OPENSSL_INCLUDE_DIR} -) diff --git a/lib/regex/regex.c b/lib/regex/regex.c index f30a6aec..0242bea3 100644 --- a/lib/regex/regex.c +++ b/lib/regex/regex.c @@ -17,7 +17,7 @@ License along with the GNU C Library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -//#include "nzbget.h" + #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -52,15 +52,17 @@ # include "../locale/localeinfo.h" #endif -#define strncasecmp strnicmp -#define strcasecmp stricmp +#define strncasecmp strncmp +#define strcasecmp strcmp /* On some systems, limits.h sets RE_DUP_MAX to a lower value than GNU regex allows. Include it before , which correctly #undefs RE_DUP_MAX and sets it to the right value. */ #include -#include #include +#ifdef WIN32 +#include +#endif //#ifdef __cplusplus //extern "C" { diff --git a/lib/regex/regex.h b/lib/regex/regex.h index 38e7d031..f1e08572 100644 --- a/lib/regex/regex.h +++ b/lib/regex/regex.h @@ -19,12 +19,10 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -//#ifndef _REGEX_H -//#define _REGEX_H 1 + #pragma once #include - /* Allow the use in C++ code. */ #ifdef __cplusplus extern "C" { diff --git a/lib/sources.cmake b/lib/sources.cmake new file mode 100644 index 00000000..45cc45fa --- /dev/null +++ b/lib/sources.cmake @@ -0,0 +1,98 @@ +if(CMAKE_SYSTEM_PROCESSOR MATCHES "i?86|x86_64") + set(SSE2_CXXFLAGS "-msse2") + set(SSSE3_CXXFLAGS "-mssse3") + set(PCLMUL_CXXFLAGS "-msse4.1 -mpclmul") +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm.*") + set(NEON_CXXFLAGS "-mfpu=neon") + set(ACLECRC_CXXFLAGS "-march=armv8-a+crc -fpermissive") +elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64") + set(ACLECRC_CXXFLAGS "-march=armv8-a+crc -fpermissive") +endif() + +add_library(regex STATIC + ${CMAKE_SOURCE_DIR}/lib/regex/regex.c +) +target_include_directories(regex PUBLIC + ${CMAKE_SOURCE_DIR}/lib/regex +) + +add_library(yencode STATIC + ${CMAKE_SOURCE_DIR}/lib/yencode/SimdInit.cpp + ${CMAKE_SOURCE_DIR}/lib/yencode/SimdDecoder.cpp + ${CMAKE_SOURCE_DIR}/lib/yencode/ScalarDecoder.cpp + ${CMAKE_SOURCE_DIR}/lib/yencode/Sse2Decoder.cpp + ${CMAKE_SOURCE_DIR}/lib/yencode/Ssse3Decoder.cpp + ${CMAKE_SOURCE_DIR}/lib/yencode/PclmulCrc.cpp + ${CMAKE_SOURCE_DIR}/lib/yencode/NeonDecoder.cpp + ${CMAKE_SOURCE_DIR}/lib/yencode/AcleCrc.cpp + ${CMAKE_SOURCE_DIR}/lib/yencode/SliceCrc.cpp +) +target_include_directories(yencode PUBLIC + ${CMAKE_SOURCE_DIR}/lib/yencode + ${CMAKE_SOURCE_DIR}/lib/regex + ${CMAKE_SOURCE_DIR}/daemon/main + ${INCLUDES} +) + +set_source_files_properties( + ${CMAKE_SOURCE_DIR}/lib/yencode/Sse2Decoder.cpp + PROPERTIES COMPILE_FLAGS "${CMAKE_CXX_FLAGS} ${SSE2_CXXFLAGS}" +) + +set_source_files_properties( + ${CMAKE_SOURCE_DIR}/lib/yencode/Ssse3Decoder.cpp + PROPERTIES COMPILE_FLAGS "${CMAKE_CXX_FLAGS} ${SSSE3_CXXFLAGS}" +) + +set_source_files_properties( + ${CMAKE_SOURCE_DIR}/lib/yencode/PclmulCrc.cpp + PROPERTIES COMPILE_FLAGS "${CMAKE_CXX_FLAGS} ${PCLMUL_CXXFLAGS}" +) + +set_source_files_properties( + ${CMAKE_SOURCE_DIR}/lib/yencode/NeonDecoder.cpp + PROPERTIES COMPILE_FLAGS "${CMAKE_CXX_FLAGS_RELEASE} ${NEON_CXXFLAGS}" +) + +set_source_files_properties( + ${CMAKE_SOURCE_DIR}/lib/yencode/AcleCrc.cpp + PROPERTIES COMPILE_FLAGS "${CMAKE_CXX_FLAGS} ${ACLECRC_CXXFLAGS}" +) + +if(NOT DISABLE_PARCHECK) + add_library(par2 STATIC + ${CMAKE_SOURCE_DIR}/lib/par2/commandline.cpp + ${CMAKE_SOURCE_DIR}/lib/par2/crc.cpp + ${CMAKE_SOURCE_DIR}/lib/par2/creatorpacket.cpp + ${CMAKE_SOURCE_DIR}/lib/par2/criticalpacket.cpp + ${CMAKE_SOURCE_DIR}/lib/par2/datablock.cpp + ${CMAKE_SOURCE_DIR}/lib/par2/descriptionpacket.cpp + ${CMAKE_SOURCE_DIR}/lib/par2/diskfile.cpp + ${CMAKE_SOURCE_DIR}/lib/par2/filechecksummer.cpp + ${CMAKE_SOURCE_DIR}/lib/par2/galois.cpp + ${CMAKE_SOURCE_DIR}/lib/par2/mainpacket.cpp + ${CMAKE_SOURCE_DIR}/lib/par2/md5.cpp + ${CMAKE_SOURCE_DIR}/lib/par2/par2fileformat.cpp + ${CMAKE_SOURCE_DIR}/lib/par2/par2repairer.cpp + ${CMAKE_SOURCE_DIR}/lib/par2/par2repairersourcefile.cpp + ${CMAKE_SOURCE_DIR}/lib/par2/parheaders.cpp + ${CMAKE_SOURCE_DIR}/lib/par2/recoverypacket.cpp + ${CMAKE_SOURCE_DIR}/lib/par2/reedsolomon.cpp + ${CMAKE_SOURCE_DIR}/lib/par2/verificationhashtable.cpp + ${CMAKE_SOURCE_DIR}/lib/par2/verificationpacket.cpp + ) + target_include_directories(par2 PUBLIC + ${CMAKE_SOURCE_DIR}/lib/par2 + ${CMAKE_SOURCE_DIR}/lib/regex + ${CMAKE_SOURCE_DIR}/daemon/main + ${CMAKE_SOURCE_DIR}/daemon/util + ${INCLUDES} + ) +endif() + +set(LIBS ${LIBS} regex yencode) +set(INCLUDES ${INCLUDES} ${CMAKE_SOURCE_DIR}/lib/regex ${CMAKE_SOURCE_DIR}/lib/yencode) +if(NOT DISABLE_PARCHECK) + set(LIBS ${LIBS} par2) + set(INCLUDES ${INCLUDES} ${CMAKE_SOURCE_DIR}/lib/par2) +endif() diff --git a/tests/extension/CMakeLists.txt b/tests/extension/CMakeLists.txt index fa52c78f..447c151c 100644 --- a/tests/extension/CMakeLists.txt +++ b/tests/extension/CMakeLists.txt @@ -29,16 +29,10 @@ file(GLOB ExtensionSrc ${CMAKE_SOURCE_DIR}/daemon/connect/WebDownloader.cpp ${CMAKE_SOURCE_DIR}/daemon/connect/Connection.cpp ${CMAKE_SOURCE_DIR}/daemon/connect/TlsSocket.cpp - ${CMAKE_SOURCE_DIR}/lib/regex/regex.c ) add_executable(ExtensionTests ${ExtensionSrc}) -target_link_libraries(ExtensionTests PRIVATE - ZLIB::ZLIB - Yencode - OpenSSL::SSL - ${LIBXML2_LIBRARIES} -) +target_link_libraries(ExtensionTests PRIVATE ${LIBS}) target_include_directories(ExtensionTests PRIVATE ${CMAKE_SOURCE_DIR}/daemon/main @@ -52,9 +46,7 @@ target_include_directories(ExtensionTests PRIVATE ${CMAKE_SOURCE_DIR}/daemon/connect ${CMAKE_SOURCE_DIR}/lib/regex ${CMAKE_SOURCE_DIR}/lib/yencode - ${ZLIB_INCLUDE_DIR} - ${OPENSSL_INCLUDE_DIR} - ${Boost_INCLUDE_DIR} + ${INCLUDES} ) file(COPY ../testdata/extension/manifest DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/tests/feed/CMakeLists.txt b/tests/feed/CMakeLists.txt index 2620cf14..0fd38c94 100644 --- a/tests/feed/CMakeLists.txt +++ b/tests/feed/CMakeLists.txt @@ -13,13 +13,8 @@ add_executable(FeedTest ${CMAKE_SOURCE_DIR}/daemon/queue/DownloadInfo.cpp ${CMAKE_SOURCE_DIR}/daemon/queue/DiskState.cpp ${CMAKE_SOURCE_DIR}/daemon/nntp/NewsServer.cpp - ${CMAKE_SOURCE_DIR}/lib/regex/regex.c -) -target_link_libraries(FeedTest PRIVATE - ZLIB::ZLIB - Yencode - LibXml2::LibXml2 ) +target_link_libraries(FeedTest PRIVATE ${LIBS}) target_include_directories(FeedTest PRIVATE ${CMAKE_SOURCE_DIR}/daemon/feed ${CMAKE_SOURCE_DIR}/daemon/main @@ -28,8 +23,7 @@ target_include_directories(FeedTest PRIVATE ${CMAKE_SOURCE_DIR}/daemon/nntp ${CMAKE_SOURCE_DIR}/daemon/remote ${CMAKE_SOURCE_DIR}/lib/regex - ${Boost_INCLUDE_DIR} - ${LIBXML2_INCLUDE_DIR} + ${INCLUDES} ) file(COPY ../testdata/feed DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/tests/feed/FeedFileTest.cpp b/tests/feed/FeedFileTest.cpp index 5375f1fc..c5fce143 100644 --- a/tests/feed/FeedFileTest.cpp +++ b/tests/feed/FeedFileTest.cpp @@ -21,12 +21,12 @@ #include -#include +#include "FileSystem.h" #include "FeedFile.h" BOOST_AUTO_TEST_CASE(FeedFileTest) { - std::string path = std::filesystem::current_path().string(); + std::string path = FileSystem::GetCurrentDirectory().Str(); std::string testFile = path + "/feed/feed.xml"; FeedFile file(testFile.c_str(), "feedName"); diff --git a/tests/main/CMakeLists.txt b/tests/main/CMakeLists.txt index c38b58b7..4cab2dd5 100644 --- a/tests/main/CMakeLists.txt +++ b/tests/main/CMakeLists.txt @@ -12,13 +12,8 @@ add_executable(MainTests ${CMAKE_SOURCE_DIR}/daemon/queue/DownloadInfo.cpp ${CMAKE_SOURCE_DIR}/daemon/feed/FeedInfo.cpp ${CMAKE_SOURCE_DIR}/daemon/nntp/NewsServer.cpp - ${CMAKE_SOURCE_DIR}/lib/regex/regex.c -) -target_link_libraries(MainTests PRIVATE - ZLIB::ZLIB - Yencode - LibXml2::LibXml2 ) +target_link_libraries(MainTests PRIVATE ${LIBS}) target_include_directories(MainTests PRIVATE ${CMAKE_SOURCE_DIR}/daemon/main ${CMAKE_SOURCE_DIR}/daemon/util @@ -28,9 +23,7 @@ target_include_directories(MainTests PRIVATE ${CMAKE_SOURCE_DIR}/daemon/nntp ${CMAKE_SOURCE_DIR}/lib/yencode ${CMAKE_SOURCE_DIR}/lib/regex - ${OPENSSL_INCLUDE_DIR} - ${Boost_INCLUDE_DIR} - ${LIBXML2_INCLUDE_DIR} + ${INCLUDES} ) add_test(NAME MainTests COMMAND $ --log_level=message) diff --git a/tests/nntp/CMakeLists.txt b/tests/nntp/CMakeLists.txt index 5c06ecc5..9089edd3 100644 --- a/tests/nntp/CMakeLists.txt +++ b/tests/nntp/CMakeLists.txt @@ -13,15 +13,8 @@ add_executable(ServerPoolTest ${CMAKE_SOURCE_DIR}/daemon/feed/FeedInfo.cpp ${CMAKE_SOURCE_DIR}/daemon/connect/Connection.cpp ${CMAKE_SOURCE_DIR}/daemon/connect/TlsSocket.cpp - ${CMAKE_SOURCE_DIR}/lib/regex/regex.c -) -target_link_libraries(ServerPoolTest PRIVATE - OpenSSL::SSL - ZLIB::ZLIB - Par2 - Yencode - LibXml2::LibXml2 ) +target_link_libraries(ServerPoolTest PRIVATE ${LIBS}) target_include_directories(ServerPoolTest PRIVATE ${CMAKE_SOURCE_DIR}/daemon/main ${CMAKE_SOURCE_DIR}/daemon/nntp @@ -32,9 +25,7 @@ target_include_directories(ServerPoolTest PRIVATE ${CMAKE_SOURCE_DIR}/daemon/remote ${CMAKE_SOURCE_DIR}/lib/yencode ${CMAKE_SOURCE_DIR}/lib/par2 - ${OPENSSL_INCLUDE_DIR} - ${Boost_INCLUDE_DIR} - ${LIBXML2_INCLUDE_DIR} + ${INCLUDES} ) add_test(NAME ServerPoolTest COMMAND $ --log_level=message) diff --git a/tests/nntp/ServerPoolTest.cpp b/tests/nntp/ServerPoolTest.cpp index d7eb7ca5..d728472f 100644 --- a/tests/nntp/ServerPoolTest.cpp +++ b/tests/nntp/ServerPoolTest.cpp @@ -214,7 +214,7 @@ BOOST_AUTO_TEST_CASE(ActiveOnOffTest) BOOST_CHECK(con3 == nullptr); } -BOOST_AUTO_TEST_CASE(IgnoreServers) +BOOST_AUTO_TEST_CASE(IgnoreServersTest) { ServerPool pool; AddTestServer(&pool, 1, true, 0, false, 0, 2); @@ -236,7 +236,7 @@ BOOST_AUTO_TEST_CASE(IgnoreServers) BOOST_CHECK(con4 == nullptr); } -BOOST_AUTO_TEST_CASE(IgnoreServersGrouped) +BOOST_AUTO_TEST_CASE(IgnoreServersGroupedTest) { ServerPool pool; AddTestServer(&pool, 1, true, 0, false, 1, 2); @@ -267,17 +267,17 @@ BOOST_AUTO_TEST_CASE(IgnoreServersGrouped) BOOST_CHECK(con3 == nullptr); } -BOOST_AUTO_TEST_CASE(BlockServersUngrouped) +BOOST_AUTO_TEST_CASE(BlockServersUngroupedTest) { TestBlockServers(0); } -BOOST_AUTO_TEST_CASE(BlockServersGrouped) +BOOST_AUTO_TEST_CASE(BlockServersGroupedTest) { TestBlockServers(1); } -BOOST_AUTO_TEST_CASE(BlockOptionalServersUngrouped) +BOOST_AUTO_TEST_CASE(BlockOptionalServersUngroupedTest) { TestOptionalBlockServers(0); } @@ -287,12 +287,12 @@ BOOST_AUTO_TEST_CASE(BlockOptionalServersGrouped) TestOptionalBlockServers(1); } -BOOST_AUTO_TEST_CASE(BlockOptionalAndNonOptionalServersUngrouped) +BOOST_AUTO_TEST_CASE(BlockOptionalAndNonOptionalServersUngroupedTest) { TestBlockOptionalAndNonOptionalServers(0); } -BOOST_AUTO_TEST_CASE(BlockOptionalAndNonOptionalServersGrouped) +BOOST_AUTO_TEST_CASE(BlockOptionalAndNonOptionalServersGroupedTest) { TestBlockOptionalAndNonOptionalServers(1); } diff --git a/tests/postprocess/CMakeLists.txt b/tests/postprocess/CMakeLists.txt index 398b994f..5189f878 100644 --- a/tests/postprocess/CMakeLists.txt +++ b/tests/postprocess/CMakeLists.txt @@ -24,18 +24,10 @@ file(GLOB PostprocessTestsSrc ${CMAKE_SOURCE_DIR}/daemon/util/FileSystem.cpp ${CMAKE_SOURCE_DIR}/daemon/queue/DownloadInfo.cpp ${CMAKE_SOURCE_DIR}/daemon/queue/DiskState.cpp - ${CMAKE_SOURCE_DIR}/lib/regex/regex.c ) add_executable(PostprocessTests ${PostprocessTestsSrc}) -target_link_libraries(PostprocessTests PRIVATE - ZLIB::ZLIB - Yencode - Par2 - OpenSSL::SSL - OpenSSL::Crypto - LibXml2::LibXml2 -) +target_link_libraries(PostprocessTests PRIVATE ${LIBS}) target_include_directories(PostprocessTests PRIVATE ../suite ${CMAKE_SOURCE_DIR}/daemon/main @@ -48,8 +40,7 @@ target_include_directories(PostprocessTests PRIVATE ${CMAKE_SOURCE_DIR}/daemon/nntp ${CMAKE_SOURCE_DIR}/lib/yencode ${CMAKE_SOURCE_DIR}/lib/par2 - ${Boost_INCLUDE_DIR} - ${LIBXML2_INCLUDE_DIR} + ${INCLUDES} ) file(COPY ../testdata/rarrenamer DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/tests/postprocess/DirectUnpackTest.cpp b/tests/postprocess/DirectUnpackTest.cpp index 3e913fa0..b8234481 100644 --- a/tests/postprocess/DirectUnpackTest.cpp +++ b/tests/postprocess/DirectUnpackTest.cpp @@ -21,13 +21,21 @@ #include "nzbget.h" #include -#include +#include "FileSystem.h" #include "DirectUnpack.h" #include "Log.h" #include "Options.h" #include "DiskState.h" +Log* g_Log = new Log(); +Options* g_Options; +DiskState* g_DiskState; + +char* envVars[] = {"NZBXX_YYYY", 0}; +char* (*g_EnvironmentVariables)[2] = &envVars; +char* (*g_Arguments)[] = nullptr; + class DirectUnpackDownloadQueueMock : public DownloadQueue { public: @@ -51,24 +59,32 @@ BOOST_AUTO_TEST_CASE(DirectUnpackSimpleTest) BOOST_TEST_MESSAGE("This test requires working unrar 5 in search path"); - const std::string testDataDir = std::filesystem::current_path().string() + "/rarrenamer"; - const std::string workingDir = testDataDir + "/empty"; - std::filesystem::create_directory(workingDir); + std::string currDir = FileSystem::GetCurrentDirectory().Str(); + std::string testDataDir = currDir + "/rarrenamer"; + std::string workingDir = testDataDir + "/empty"; + + BOOST_REQUIRE(FileSystem::CreateDirectory(workingDir.c_str())); - std::filesystem::copy( - (testDataDir + "/testfile3.part01.rar").c_str(), - (workingDir + "/testfile3.part01.rar").c_str() + BOOST_REQUIRE( + FileSystem::CopyFile( + (testDataDir + "/testfile3.part01.rar").c_str(), + (workingDir + "/testfile3.part01.rar").c_str() + ) ); - std::filesystem::copy( - (testDataDir + "/testfile3.part02.rar").c_str(), - (workingDir + "/testfile3.part02.rar").c_str() + BOOST_REQUIRE( + FileSystem::CopyFile( + (testDataDir + "/testfile3.part02.rar").c_str(), + (workingDir + "/testfile3.part02.rar").c_str() + ) ); - std::filesystem::copy( - (testDataDir + "/testfile3.part03.rar").c_str(), - (workingDir + "/testfile3.part03.rar").c_str() + BOOST_REQUIRE( + FileSystem::CopyFile( + (testDataDir + "/testfile3.part03.rar").c_str(), + (workingDir + "/testfile3.part03.rar").c_str() + ) ); - + std::unique_ptr nzbInfo = std::make_unique(); NzbInfo* nzbPtr = nzbInfo.get(); nzbInfo->SetName("test"); @@ -94,8 +110,8 @@ BOOST_AUTO_TEST_CASE(DirectUnpackSimpleTest) } BOOST_CHECK(nzbPtr->GetDirectUnpackStatus() == NzbInfo::nsSuccess); - BOOST_CHECK(std::filesystem::exists((workingDir + "/_unpack/testfile3.dat").c_str())); - std::filesystem::remove_all(workingDir); + BOOST_CHECK(FileSystem::FileExists((workingDir + "/_unpack/testfile3.dat").c_str())); + BOOST_REQUIRE(FileSystem::RemoveDirectory(workingDir.c_str())); } BOOST_AUTO_TEST_CASE(DirectUnpackTwoArchives) @@ -109,32 +125,34 @@ BOOST_AUTO_TEST_CASE(DirectUnpackTwoArchives) BOOST_TEST_MESSAGE("This test requires working unrar 5 in search path"); - const std::string testDataDir = std::filesystem::current_path().string() + "/testdata"; - const std::string workingDir = testDataDir + "empty"; - std::filesystem::create_directory(workingDir); + std::string currDir = FileSystem::GetCurrentDirectory().Str(); + std::string testDataDir = currDir + "/rarrenamer"; + std::string workingDir = testDataDir + "/empty"; + + BOOST_REQUIRE(FileSystem::CreateDirectory(workingDir.c_str())); - std::filesystem::copy( + FileSystem::CopyFile( (testDataDir + "/testfile3.part01.rar").c_str(), (workingDir + "/testfile3.part01.rar").c_str() ); - std::filesystem::copy( + FileSystem::CopyFile( (testDataDir + "/testfile3.part02.rar").c_str(), (workingDir + "/testfile3.part02.rar").c_str() ); - std::filesystem::copy( + FileSystem::CopyFile( (testDataDir + "/testfile3.part03.rar").c_str(), (workingDir + "/testfile3.part03.rar").c_str() ); - std::filesystem::copy( + FileSystem::CopyFile( (testDataDir + "/testfile5.part01.rar").c_str(), (workingDir + "/testfile5.part01.rar").c_str() ); - std::filesystem::copy( + FileSystem::CopyFile( (testDataDir + "/testfile5.part02.rar").c_str(), (workingDir + "/testfile5.part02.rar").c_str() ); - std::filesystem::copy( + FileSystem::CopyFile( (testDataDir + "/testfile5.part03.rar").c_str(), (workingDir + "/testfile5.part03.rar").c_str() ); @@ -164,7 +182,7 @@ BOOST_AUTO_TEST_CASE(DirectUnpackTwoArchives) } BOOST_CHECK(nzbPtr->GetDirectUnpackStatus() == NzbInfo::nsSuccess); - BOOST_CHECK(std::filesystem::exists((workingDir + "/_unpack/testfile3.dat").c_str())); - BOOST_CHECK(std::filesystem::exists((workingDir + "/_unpack/testfile5.dat").c_str())); - std::filesystem::remove_all(workingDir); + BOOST_CHECK(FileSystem::FileExists((workingDir + "/_unpack/testfile3.dat").c_str())); + BOOST_CHECK(FileSystem::FileExists((workingDir + "/_unpack/testfile5.dat").c_str())); + BOOST_REQUIRE(FileSystem::RemoveDirectory(workingDir.c_str())); } diff --git a/tests/queue/CMakeLists.txt b/tests/queue/CMakeLists.txt index bb535efd..b1952ee0 100644 --- a/tests/queue/CMakeLists.txt +++ b/tests/queue/CMakeLists.txt @@ -11,13 +11,8 @@ add_executable(NzbFileTest ${CMAKE_SOURCE_DIR}/daemon/util/NString.cpp ${CMAKE_SOURCE_DIR}/daemon/util/Log.cpp ${CMAKE_SOURCE_DIR}/daemon/nntp/NewsServer.cpp - ${CMAKE_SOURCE_DIR}/lib/regex/regex.c -) -target_link_libraries(NzbFileTest PRIVATE - ZLIB::ZLIB - Yencode - LibXml2::LibXml2 ) +target_link_libraries(NzbFileTest PRIVATE ${LIBS}) target_include_directories(NzbFileTest PRIVATE ${CMAKE_SOURCE_DIR}/daemon/main ${CMAKE_SOURCE_DIR}/daemon/util @@ -26,9 +21,7 @@ target_include_directories(NzbFileTest PRIVATE ${CMAKE_SOURCE_DIR}/daemon/remote ${CMAKE_SOURCE_DIR}/daemon/nntp ${CMAKE_SOURCE_DIR}/lib/yencode - ${OPENSSL_INCLUDE_DIR} - ${Boost_INCLUDE_DIR} - ${LIBXML2_INCLUDE_DIR} + ${INCLUDES} ) file(COPY ../testdata/nzbfile DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/tests/queue/NzbFileTest.cpp b/tests/queue/NzbFileTest.cpp index b5a1771f..ce119f9f 100644 --- a/tests/queue/NzbFileTest.cpp +++ b/tests/queue/NzbFileTest.cpp @@ -23,12 +23,11 @@ #define BOOST_TEST_MODULE "NzbFileTest" #include -#include - #include "NzbFile.h" #include "Log.h" #include "Options.h" #include "DiskState.h" +#include "FileSystem.h" Log* g_Log; Options* g_Options; @@ -36,9 +35,7 @@ DiskState* g_DiskState; void TestNzb(std::string testFilename) { - BOOST_TEST_MESSAGE(std::string("Filename: ") + testFilename); - - std::string path = std::filesystem::current_path().string(); + std::string path = FileSystem::GetCurrentDirectory().Str(); std::string nzbFilename(path + "/nzbfile/" + testFilename + ".nzb"); std::string infoFilename(path + "/nzbfile/" + testFilename + ".txt"); @@ -73,7 +70,7 @@ void TestNzb(std::string testFilename) xmlCleanupParser(); } -BOOST_AUTO_TEST_CASE(NZBParser) +BOOST_AUTO_TEST_CASE(NZBParserTest) { Options::CmdOptList cmdOpts; Options options(&cmdOpts, nullptr); diff --git a/tests/util/CMakeLists.txt b/tests/util/CMakeLists.txt index 48071968..bff0dbd1 100644 --- a/tests/util/CMakeLists.txt +++ b/tests/util/CMakeLists.txt @@ -9,25 +9,11 @@ file(GLOB UtilTestSrc ${CMAKE_SOURCE_DIR}/daemon/util/Util.cpp ${CMAKE_SOURCE_DIR}/daemon/util/Json.cpp ${CMAKE_SOURCE_DIR}/daemon/util/Xml.cpp - ${CMAKE_SOURCE_DIR}/lib/regex/regex.c ) add_executable(UtilTests ${UtilTestSrc}) -target_link_libraries(UtilTests PRIVATE - ZLIB::ZLIB - Yencode - LibXml2::LibXml2 -) +target_link_libraries(UtilTests PRIVATE ${LIBS}) -target_include_directories(UtilTests PRIVATE - ${CMAKE_SOURCE_DIR}/daemon/main - ${CMAKE_SOURCE_DIR}/daemon/util - ${CMAKE_SOURCE_DIR}/lib/regex - ${CMAKE_SOURCE_DIR}/lib/yencode - ${ZLIB_INCLUDE_DIR} - ${OPENSSL_INCLUDE_DIR} - ${Boost_INCLUDE_DIR} - ${LIBXML2_INCLUDE_DIR} -) +target_include_directories(UtilTests PRIVATE ${INCLUDES}) add_test(NAME UtilTests COMMAND $ --log_level=message)