diff --git a/.github/workflows/build-ubuntu.yml b/.github/workflows/build-ubuntu.yml index 789cc11..0cc6e4e 100644 --- a/.github/workflows/build-ubuntu.yml +++ b/.github/workflows/build-ubuntu.yml @@ -11,26 +11,87 @@ env: jobs: build-ubuntu: + + strategy: + matrix: + library_type: [static, shared] + os: [ubuntu-22.04, ubuntu-20.04, ubuntu-18.04] + # The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac. # You can convert this to a matrix build if you need cross-platform coverage. # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} steps: - + + - name: Set Variables + run: | + if [[ '${{ matrix.library_type }}' == 'static' ]]; then + echo "build_shared_libs=OFF" >> "$GITHUB_ENV" + echo "package_postfix=static" >> "$GITHUB_ENV" + else + echo "build_shared_libs=ON" >> "$GITHUB_ENV" + echo "package_postfix=shared" >> "$GITHUB_ENV" + fi + - name: Checkout uses: actions/checkout@v2 with: submodules: 'true' fetch-depth: 0 + ############################################ + # Test-compile the project + ############################################ - name: Configure CMake # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type - run: cmake -B ${{github.workspace}}/_build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + run: | + cmake -B ${{github.workspace}}/_build \ + -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \ + -DBUILD_SHARED_LIBS=${{ env.build_shared_libs }} - name: Build # Build your program with the given configuration run: cmake --build ${{github.workspace}}/_build --config ${{env.BUILD_TYPE}} - + + - name: CPack + run: cpack -G DEB + working-directory: ${{ github.workspace }}/_build + + - name: Upload binaries + uses: actions/upload-artifact@v2 + with: + name: fineftp-server-${{ matrix.os }}-${{ env.package_postfix }} + path: ${{github.workspace}}/_build/_package/*.deb + + + ############################################ + # Test if our binary can be linked against + ############################################ + + - name: Install binaries + shell: bash + run: sudo dpkg -i ${{ github.workspace }}/_build/_package/*.deb + + - name: Compile integration test (Release) + run: | + cmake -B ${{github.workspace}}/samples/integration_test/_build/release -DCMAKE_BUILD_TYPE=Release + cmake --build ${{github.workspace}}/samples/integration_test/_build/release + working-directory: ${{ github.workspace }}/samples/integration_test + + - name: Run integration test (Release) + run: ./integration_test + working-directory: ${{ github.workspace }}/samples/integration_test/_build/release + + - name: Compile integration test (Debug) + run: | + cmake -B ${{github.workspace}}/samples/integration_test/_build/debug -DCMAKE_BUILD_TYPE=Debug + cmake --build ${{github.workspace}}/samples/integration_test/_build/debug + working-directory: ${{ github.workspace }}/samples/integration_test + + - name: Run integration test (Debug) + run: ./integration_test + working-directory: ${{ github.workspace }}/samples/integration_test/_build/debug + diff --git a/.github/workflows/build-windows.yml b/.github/workflows/build-windows.yml index 231d6e0..bc3b672 100644 --- a/.github/workflows/build-windows.yml +++ b/.github/workflows/build-windows.yml @@ -7,30 +7,112 @@ on: env: # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) - BUILD_TYPE: Release + INSTALL_PREFIX: _install jobs: build-windows: + + strategy: + matrix: + library_type: [static, shared] + # The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac. # You can convert this to a matrix build if you need cross-platform coverage. # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix - runs-on: windows-latest + runs-on: windows-2019 steps: - + + - name: Set Variables + run: | + if ( '${{ matrix.library_type }}' -eq 'static' ) + { + echo "build_shared_libs=OFF" >> "$Env:GITHUB_ENV" + echo "package_postfix=static" >> "$Env:GITHUB_ENV" + } + else + { + echo "build_shared_libs=ON" >> "$Env:GITHUB_ENV" + echo "package_postfix=shared" >> "$Env:GITHUB_ENV" + } + - name: Checkout uses: actions/checkout@v2 with: submodules: 'true' fetch-depth: 0 + ############################################ + # Test-compile the project + ############################################ - name: Configure CMake # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type - run: cmake -B ${{github.workspace}}/_build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + shell: cmd + run: | + cmake -B ${{github.workspace}}/_build ^ + -G "Visual Studio 16 2019" ^ + -A x64 ^ + -T v140 ^ + -DCMAKE_INSTALL_PREFIX=${{env.INSTALL_PREFIX}} ^ + -DBUILD_SHARED_LIBS=${{ env.build_shared_libs }} - - name: Build + - name: Build (Release) # Build your program with the given configuration - run: cmake --build ${{github.workspace}}/_build --config ${{env.BUILD_TYPE}} + shell: cmd + run: | + cmake --build ${{github.workspace}}/_build --config Release --parallel + cmake --build ${{github.workspace}}/_build --config Release --target INSTALL + - name: Build (Debug) + # Build your program with the given configuration + shell: cmd + run: | + cmake --build ${{github.workspace}}/_build --config Debug --parallel + cmake --build ${{github.workspace}}/_build --config Debug --target INSTALL + - name: Upload binaries + uses: actions/upload-artifact@v2 + with: + name: fineftp-server-win64-${{ matrix.library_type }} + path: ${{github.workspace}}/${{env.INSTALL_PREFIX}} + + ############################################ + # Test if our binary can be linked against + ############################################ + + - name: CMake integration test + shell: cmd + run: | + cmake -B ${{github.workspace}}/samples/integration_test/_build ^ + -A x64 ^ + -DCMAKE_PREFIX_PATH=${{github.workspace}}/${{env.INSTALL_PREFIX}} + working-directory: ${{ github.workspace }}/samples/integration_test + + - name: Compile integration test (Release) + shell: cmd + run: cmake --build ${{github.workspace}}/samples/integration_test/_build --config Release + working-directory: ${{ github.workspace }}/samples/integration_test + + - name: Run integration test (Release) + run: | + if ( '${{ matrix.library_type }}' -eq 'shared' ) + { + $Env:Path = '${{github.workspace}}/${{env.INSTALL_PREFIX}}/bin;' + $Env:Path + } + .\integration_test.exe + working-directory: ${{ github.workspace }}/samples/integration_test/_build/Release + + - name: Compile integration test (Debug) + shell: cmd + run: cmake --build ${{github.workspace}}/samples/integration_test/_build --config Debug + working-directory: ${{ github.workspace }}/samples/integration_test + + - name: Run integration test (Debug) + run: | + if ( '${{ matrix.library_type }}' -eq 'shared' ) + { + $Env:Path = '${{github.workspace}}/${{env.INSTALL_PREFIX}}/bin;' + $Env:Path + } + .\integration_test.exe + working-directory: ${{ github.workspace }}/samples/integration_test/_build/Debug diff --git a/.gitignore b/.gitignore index 49c4420..2ab4278 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ ipch *.opendb *.db /_build +/samples/integration_test/_build /_install /.vs /CMakeLists.txt.user diff --git a/CMakeLists.txt b/CMakeLists.txt index 107b066..65b54fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,8 @@ cmake_minimum_required(VERSION 3.5.1) -set(CMAKE_CXX_STANDARD 14) +# Project call +include("${CMAKE_CURRENT_LIST_DIR}/fineftp-server/version.cmake") +project(fineftp VERSION ${FINEFTP_SERVER_VERSION_MAJOR}.${FINEFTP_SERVER_VERSION_MINOR}.${FINEFTP_SERVER_VERSION_PATCH}) # Normalize backslashes from Windows paths file(TO_CMAKE_PATH "${CMAKE_MODULE_PATH}" CMAKE_MODULE_PATH) @@ -8,20 +10,25 @@ file(TO_CMAKE_PATH "${CMAKE_PREFIX_PATH}" CMAKE_PREFIX_PATH) message(STATUS "Module Path: ${CMAKE_MODULE_PATH}") message(STATUS "Prefix Path: ${CMAKE_PREFIX_PATH}") +# CMake Options +option(FINEFTP_SERVER_BUILD_SAMPLES + "Build project samples" + ON) + +# Module path for finding asio list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) -project(fineftp) +# Set Debug postfix +set(CMAKE_DEBUG_POSTFIX d) +set(CMAKE_MINSIZEREL_POSTFIX minsize) +set(CMAKE_RELWITHDEBINFO_POSTFIX reldbg) -set(as_subproject fineftp) +# Add main fineftp::server library +add_subdirectory(fineftp-server) -string(COMPARE EQUAL "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}" _cmp) -if (_cmp) - macro(find_package) - if(NOT "${ARGV0}" IN_LIST as_subproject) - _find_package(${ARGV}) - endif() - endmacro() +if (FINEFTP_SERVER_BUILD_SAMPLES) + add_subdirectory(samples/fineftp_example) endif() -add_subdirectory(fineftp-server) -add_subdirectory(example) +# Make this package available for packing with CPack +include("${CMAKE_CURRENT_LIST_DIR}/cpack_config.cmake") \ No newline at end of file diff --git a/README.md b/README.md index 733d252..1efc03a 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ There is an example project provided that will create an FTP Server at `C:\` (Wi - Linux: `make` - Windows: Open `_build\fineftp.sln` with Visual Studio and build the example project -5. Start `example` / `example.exe` and connect with your favorite FTP Client (e.g. FileZilla) on port 2121 *(This port is used so you don't need root privileges to start the FTP server)* +5. Start `fineftp_example` / `fineftp_example.exe` and connect with your favorite FTP Client (e.g. FileZilla) on port 2121 *(This port is used so you don't need root privileges to start the FTP server)* ## Contribute diff --git a/cmake/Findfineftp.cmake b/cmake/Findfineftp.cmake new file mode 100644 index 0000000..cfa2ccd --- /dev/null +++ b/cmake/Findfineftp.cmake @@ -0,0 +1,2 @@ +# Stub find script for in-source build of samples +set(fineftp_FOUND True) diff --git a/cpack_config.cmake b/cpack_config.cmake new file mode 100644 index 0000000..147329c --- /dev/null +++ b/cpack_config.cmake @@ -0,0 +1,20 @@ +set(CPACK_PACKAGE_NAME ${PROJECT_NAME}) +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "An FTP Server library for creating embedded FTP Servers") +set(CPACK_PACKAGE_VENDOR "Eclipse eCAL") +set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION}) +set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR}) +set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR}) +set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH}) +set(CPACK_PACKAGE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/_package") + +set(CPACK_PACKAGE_CONTACT "florian.reimold@continental-corporation.com") + +set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Florian Reimold ") +set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/eclipse-ecal/fineftp-server") +set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON) +set(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS ON) + +set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_LIST_DIR}/LICENSE") +set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_LIST_DIR}/README.md") + +include(CPack) \ No newline at end of file diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt deleted file mode 100644 index 37ca13b..0000000 --- a/example/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -cmake_minimum_required(VERSION 3.5.1) - -project(example) - -set(CMAKE_CXX_STANDARD 14) - -find_package(fineftp REQUIRED CONFIG) - -set(sources - src/main.cpp -) - -add_executable (example - ${sources} -) - -target_link_libraries (example - fineftp::server -) diff --git a/fineftp-server/CMakeLists.txt b/fineftp-server/CMakeLists.txt index c70aaf5..4456484 100644 --- a/fineftp-server/CMakeLists.txt +++ b/fineftp-server/CMakeLists.txt @@ -1,15 +1,18 @@ cmake_minimum_required(VERSION 3.5.1) -project(server VERSION 1.3.1) +include("${CMAKE_CURRENT_LIST_DIR}/version.cmake") +project(server VERSION ${FINEFTP_SERVER_VERSION_MAJOR}.${FINEFTP_SERVER_VERSION_MINOR}.${FINEFTP_SERVER_VERSION_PATCH}) set(CMAKE_POSITION_INDEPENDENT_CODE ON) +# Disable default export of symbols set(CMAKE_CXX_VISIBILITY_PRESET hidden) set(CMAKE_VISIBILITY_INLINES_HIDDEN 1) find_package(Threads REQUIRED) find_package(asio REQUIRED) +# Include GenerateExportHeader that will create export macros for us include(GenerateExportHeader) # Public API include directory @@ -57,10 +60,11 @@ target_link_libraries(${PROJECT_NAME} Threads::Threads $<$:ws2_32> $<$:wsock32> -) -# Link asio as described in this workaround: https://gitlab.kitware.com/cmake/cmake/-/issues/15415#note_633938 -target_link_libraries (${PROJECT_NAME} PRIVATE $) + # Link header-only libs (asio & recycle) as described in this workaround: + # https://gitlab.kitware.com/cmake/cmake/-/issues/15415#note_633938 + $ +) target_compile_definitions(${PROJECT_NAME} PRIVATE @@ -70,6 +74,8 @@ target_compile_definitions(${PROJECT_NAME} _WIN32_WINNT=0x0601 ) +target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_14) + target_compile_options(${PROJECT_NAME} PRIVATE $<$,$,$>: -Wall -Wextra> @@ -83,10 +89,10 @@ target_include_directories(${PROJECT_NAME} $ $ # To find the export file generated by generate_export_header $ + PRIVATE + src/ ) -target_include_directories(${PROJECT_NAME} PRIVATE src) - set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR} @@ -99,27 +105,55 @@ set_target_properties(${PROJECT_NAME} PROPERTIES include(sourcetree.cmake) create_source_tree(${includes} ${sources}) -################################## +################################################################################ +### Installation rules +################################################################################ set(FINEFTP_INSTALL_CMAKE_DIR "lib/cmake/fineftp") +# Install Runtime install( TARGETS ${PROJECT_NAME} - EXPORT fineftpTargets - LIBRARY DESTINATION "lib" - ARCHIVE DESTINATION "lib" + EXPORT fineftpRuntime + RUNTIME DESTINATION "bin" + COMPONENT fineftp_server_runtime ) -install(DIRECTORY "include/fineftp" DESTINATION "include" FILES_MATCHING PATTERN "*.h") -install(DIRECTORY "${PROJECT_BINARY_DIR}/include/fineftp" DESTINATION "include" FILES_MATCHING PATTERN "*.h") +# Install libs (-> dev package) +install( + TARGETS ${PROJECT_NAME} + EXPORT fineftpTargets + LIBRARY DESTINATION "lib" + ARCHIVE DESTINATION "lib" + COMPONENT fineftp_server_dev +) + +# Install public header files (-> dev package) +install( + DIRECTORY "include/fineftp" + DESTINATION "include" + COMPONENT fineftp_server_dev + FILES_MATCHING PATTERN "*.h" +) + +# Install the auto-generated header with the export macros (-> dev package) +install( + DIRECTORY "${PROJECT_BINARY_DIR}/include/fineftp" + DESTINATION "include" + COMPONENT fineftp_server_dev + FILES_MATCHING PATTERN "*.h" +) install( EXPORT fineftpTargets FILE fineftpTargets.cmake DESTINATION ${FINEFTP_INSTALL_CMAKE_DIR} NAMESPACE fineftp:: + COMPONENT fineftp_server_dev ) +# Create and install Config.cmake file (-> dev package) + include(CMakePackageConfigHelpers) configure_package_config_file( @@ -128,5 +162,9 @@ configure_package_config_file( INSTALL_DESTINATION ${FINEFTP_INSTALL_CMAKE_DIR} PATH_VARS FINEFTP_INSTALL_CMAKE_DIR ) -install(FILES "${CMAKE_CURRENT_BINARY_DIR}/cmake/fineftpConfig.cmake" DESTINATION ${FINEFTP_INSTALL_CMAKE_DIR}) +install( + FILES "${CMAKE_CURRENT_BINARY_DIR}/cmake/fineftpConfig.cmake" + DESTINATION ${FINEFTP_INSTALL_CMAKE_DIR} + COMPONENT fineftp_server_dev +) diff --git a/fineftp-server/version.cmake b/fineftp-server/version.cmake new file mode 100644 index 0000000..0a659f3 --- /dev/null +++ b/fineftp-server/version.cmake @@ -0,0 +1,3 @@ +set(FINEFTP_SERVER_VERSION_MAJOR 1) +set(FINEFTP_SERVER_VERSION_MINOR 3) +set(FINEFTP_SERVER_VERSION_PATCH 2) \ No newline at end of file diff --git a/samples/fineftp_example/CMakeLists.txt b/samples/fineftp_example/CMakeLists.txt new file mode 100644 index 0000000..7ff90b7 --- /dev/null +++ b/samples/fineftp_example/CMakeLists.txt @@ -0,0 +1,20 @@ +cmake_minimum_required(VERSION 3.5.1) + +project(fineftp_example) + +set(CMAKE_CXX_STANDARD 14) + +set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE) +find_package(fineftp REQUIRED) + +set(sources + src/main.cpp +) + +add_executable (${PROJECT_NAME} + ${sources} +) + +target_link_libraries (${PROJECT_NAME} + fineftp::server +) diff --git a/example/src/main.cpp b/samples/fineftp_example/src/main.cpp similarity index 100% rename from example/src/main.cpp rename to samples/fineftp_example/src/main.cpp diff --git a/samples/integration_test/CMakeLists.txt b/samples/integration_test/CMakeLists.txt new file mode 100644 index 0000000..e511433 --- /dev/null +++ b/samples/integration_test/CMakeLists.txt @@ -0,0 +1,20 @@ +cmake_minimum_required(VERSION 3.5.1) + +project(integration_test) + +set(CMAKE_CXX_STANDARD 14) + +set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE) +find_package(fineftp REQUIRED) + +set(sources + src/main.cpp +) + +add_executable (${PROJECT_NAME} + ${sources} +) + +target_link_libraries (${PROJECT_NAME} + fineftp::server +) diff --git a/samples/integration_test/src/main.cpp b/samples/integration_test/src/main.cpp new file mode 100644 index 0000000..a890691 --- /dev/null +++ b/samples/integration_test/src/main.cpp @@ -0,0 +1,9 @@ +#include + +int main() { + + fineftp::FtpServer server(2121); + server.start(4); + + return 0; +}