Skip to content

Commit

Permalink
Improved CMake install and CPack behaviour (#35)
Browse files Browse the repository at this point in the history
- FineFTP Sever now properly installs dll/so files when BUILD_SHARED_LIBS is ON
- FineFTP can now be packed with CPack
- Added CMake option to disable building the example Project
- Added integration_test project that can be build against an install to perform a very simple automated link and runtime test
- Created GH Actions that properly compile and package binaries for windows and Linux
  • Loading branch information
FlorianReimold authored Sep 12, 2022
1 parent 5713cfd commit 78efc7f
Show file tree
Hide file tree
Showing 14 changed files with 299 additions and 55 deletions.
69 changes: 65 additions & 4 deletions .github/workflows/build-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

94 changes: 88 additions & 6 deletions .github/workflows/build-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ ipch
*.opendb
*.db
/_build
/samples/integration_test/_build
/_install
/.vs
/CMakeLists.txt.user
Expand Down
31 changes: 19 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
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)
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")
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions cmake/Findfineftp.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Stub find script for in-source build of samples
set(fineftp_FOUND True)
20 changes: 20 additions & 0 deletions cpack_config.cmake
Original file line number Diff line number Diff line change
@@ -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 "[email protected]")

set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Florian Reimold <[email protected]>")
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)
19 changes: 0 additions & 19 deletions example/CMakeLists.txt

This file was deleted.

Loading

0 comments on commit 78efc7f

Please sign in to comment.