Skip to content

Commit

Permalink
Merge branch 'feature/RUNTIME_DEPENDENCY_SET' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ClausKlein committed Feb 15, 2024
2 parents 7b5d8a1 + 2c4c4f7 commit 04f0b34
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .cmake-format
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
format:
tab_size: 4
line_width: 80
line_width: 97
dangle_parens: true

markup:
Expand Down
1 change: 0 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ default:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'


stages: # List of stages for jobs, and their order of execution
- build
- test
Expand Down
56 changes: 34 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
cmake_minimum_required(VERSION 3.21...3.27)
cmake_minimum_required(VERSION 3.21...3.28)

# Not ideal to use this global variable, but necessary to make sure that tooling and projects use
# the same version
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD 17)

# strongly encouraged to enable this globally to avoid conflicts between -Wpedantic being enabled
# and -std=c++20 and -std=gnu++20 for example when compiling with PCH enabled
Expand All @@ -26,28 +26,30 @@ include(GNUInstallDirs)
# search required packages and libs
#---------------------------------------------------------------------------------------

find_package(
Boost 1.71 CONFIG
COMPONENTS filesystem
REQUIRED
)

find_package(Threads REQUIRED)
# find_package(
# Boost 1.81 CONFIG
# COMPONENTS filesystem asio headers
# REQUIRED
# )

# ---- Add other dependencies via CPM ----
# see https://github.com/cpm-cmake/CPM.cmake for more info

include(cmake/CPM.cmake)

option(BUILD_SHARED_LIBS "Build shared libraries" YES)
set(BOOST_INCLUDE_LIBRARIES filesystem asio headers)
CPMAddPackage("gh:ClausKlein/[email protected]")

# PackageProject.cmake will be used to make our target installable
CPMAddPackage("gh:TheLartians/[email protected]")
# XXX done with boost-cmake! CPMAddPackage("gh:TheLartians/[email protected]")

# see https://github.com/aminya/project_options for more info
CPMAddPackage("gh:aminya/[email protected]")
# XXX list(APPEND CMAKE_MODULE_PATH ${project_options_SOURCE_DIR})

add_library(
tftpd STATIC
tftpd # FIXME(CK) STATIC
async_tftpd_server.cpp
async_tftpd_server.hpp
tftpd.hpp
Expand All @@ -56,9 +58,8 @@ add_library(
tftp_subs.cpp
tftp/tftpsubs.h
)
target_link_libraries(
${PROJECT_NAME} PUBLIC Boost::filesystem Boost::headers Threads::Threads
)
list(TRANSFORM BOOST_INCLUDE_LIBRARIES PREPEND Boost:: OUTPUT_VARIABLE BOOST_TARGETS)
target_link_libraries(${PROJECT_NAME} PUBLIC ${BOOST_TARGETS})
target_compile_definitions(${PROJECT_NAME} PUBLIC BOOST_ASIO_NO_DEPRECATED)
target_include_directories(
${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
Expand All @@ -81,11 +82,9 @@ if(PROJECT_IS_TOP_LEVEL AND CMAKE_BUILD_TYPE STREQUAL "Debug")
# ENABLE_INCLUDE_WHAT_YOU_USE
)

# FIXME: should be PRIVATE! CK
target_link_libraries(
${PROJECT_NAME}
PUBLIC $<BUILD_INTERFACE:${PROJECT_NAME}_project_warnings>
$<BUILD_INTERFACE:${PROJECT_NAME}_project_options>
${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${PROJECT_NAME}_project_warnings>
$<BUILD_INTERFACE:${PROJECT_NAME}_project_options>
)
else()
include(cmake/WarningsAsErrors.cmake)
Expand All @@ -106,12 +105,25 @@ if(NOT CMAKE_SKIP_INSTALL_RULES)
# EXPORT_HEADER ${EXPORT_HEADER_LOCATION}
COMPATIBILITY SameMajorVersion
DISABLE_VERSION_SUFFIX YES
DEPENDENCIES "boost 1.71"
DEPENDENCIES "Boost 1.81"
)
# NOTE: implicit done! add_library(tftpd::tftpd ALIAS tftpd)
install(FILES async_tftpd_server.hpp
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(FILES async_tftpd_server.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

if(BUILD_SHARED_LIBS)
install(IMPORTED_RUNTIME_ARTIFACTS ${PROJECT_NAME} RUNTIME_DEPENDENCY_SET
_dependency_set
)
install(
RUNTIME_DEPENDENCY_SET
_dependency_set
POST_EXCLUDE_REGEXES
"${CMAKE_INSTALL_PREFIX}/lib"
RUNTIME
DESTINATION
lib
)
endif()

include(CPack)
endif()
Expand Down
4 changes: 2 additions & 2 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
"value": "${sourceDir}/stagedir"
},
"CMAKE_CXX_STANDARD": "20",
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_DEBUG_POSTFIX": "D",
"BUILD_SHARED_LIBS": "NO"
"BUILD_SHARED_LIBS": true
},
"environment": {
"CMAKE_EXPORT_COMPILE_COMMANDS": "YES",
Expand Down
14 changes: 4 additions & 10 deletions cmake/CPM.cmake
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
set(CPM_DOWNLOAD_VERSION 0.37.0)
set(CPM_DOWNLOAD_VERSION 0.38.7)

if(CPM_SOURCE_CACHE)
set(_CPM_DOWNLOAD_LOCATION
"${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake"
)
set(_CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
set(_CPM_DOWNLOAD_LOCATION
"$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake"
)
set(_CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
else()
set(_CPM_DOWNLOAD_LOCATION
"${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake"
)
set(_CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
endif()

set(CPM_DOWNLOAD_LOCATION
Expand Down
16 changes: 4 additions & 12 deletions cmake/WarningsAsErrors.cmake
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_SIMULATE_ID MATCHES
"MSVC"
)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_SIMULATE_ID MATCHES "MSVC")
target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
target_compile_options(
${PROJECT_NAME} PRIVATE -Wall -Wextra -Wpedantic -Werror -Wshadow
)
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Wpedantic -Werror -Wshadow)

if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION
GREATER_EQUAL 10.0
)
target_compile_options(
${PROJECT_NAME} PRIVATE -Wdeprecated-copy-dtor -Wnewline-eof
)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION GREATER_EQUAL 10.0)
target_compile_options(${PROJECT_NAME} PRIVATE -Wdeprecated-copy-dtor -Wnewline-eof)
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
string(REGEX REPLACE " /W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
Expand Down
2 changes: 1 addition & 1 deletion option_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ int main()
"tsize\0"s
"12345678910\0"s};
std::vector<char> msg(test1.begin(), test1.end());
msg.resize(PKTSIZE);
// TODO(CK): why? msg.resize(PKTSIZE);
err = tftpd::tftp(msg, fp, path, ackbuf);
std::cout << path << " segsize:" << tftpd::g_segsize << " tsize:" << tftpd::g_tsize
<< " timeout: " << tftpd::g_timeout << std::endl;
Expand Down
8 changes: 4 additions & 4 deletions test.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash -uex

# NOTE: not loger used: tftp-hpa 5.2
# NOTE: not longer used: tftp-hpa 5.2
# Usage: tftp [-4][-6][-v][-V][-l][-m mode][-w size][-B blocksize] [-R port:port] [host [port]] [-c command]
#XXX TFTP="/usr/bin/tftp -v -4 127.0.0.1 1234 -m binary"

Expand Down Expand Up @@ -148,7 +148,7 @@ fi
##############################################
# NOTE we start our an own client
##############################################
# normal binary upload with dublicate ack's
# normal binary upload with duplicate ack's
# TODO: should not fail
## bin/tftpd_test 1234 &
## sleep 1
Expand All @@ -168,7 +168,7 @@ if test "${UNAME}" == "Linux"; then
wait
fi
##############################################
echo "NOTE: absolut path upload must fail!"
echo "NOTE: absolute path upload must fail!"
dd if=bin/tftpd_test of=test32k.dat bs=1024 count=32
bin/tftpd_test 1234 &
sleep 1
Expand All @@ -194,7 +194,7 @@ sleep 1
${TFTP} --input=build.ninja --upload=./../build.ninja && exit 1
wait

# invalid absolut path upload must fail
# invalid absolute path upload must fail
bin/tftpd_test 1234 &
sleep 1
${TFTP} --input=build.ninja --upload=//srv///tftp/build.ninja && exit 1
Expand Down
2 changes: 1 addition & 1 deletion tftp/tftp.1
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Note that the
protocol, unlike the
.Tn FTP
protocol,
does not maintain connections betwen transfers; thus, the
does not maintain connections between transfers; thus, the
.Cm connect
command does not actually create a connection,
but merely remembers what host is to be used for transfers.
Expand Down
2 changes: 1 addition & 1 deletion tftpd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ class receiver : public server
} while (false);

// ===============================
// write the current data segement
// write the current data segment
// ===============================
size_t const seg_length = rxlen - TFTP_HEADER;
ssize_t written = writeit(file_guard_.get(), &dp_, seg_length, false);
Expand Down
2 changes: 1 addition & 1 deletion tftpd_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ static bool set_tsize(uintmax_t *vp)
}

if (sz == 0) {
sz = g_tsize; // only usefull for RRQ
sz = g_tsize; // only useful for RRQ
} else {
g_tsize = sz; // in case of WRQ
}
Expand Down
22 changes: 20 additions & 2 deletions tftpd_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ char copyright[] = "@(#) Copyright (c) 1983 Regents of the University of Califor
#include <boost/algorithm/string/case_conv.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/current_function.hpp>
#include <boost/filesystem.hpp>

#include <arpa/inet.h>
#include <cstdlib>
Expand All @@ -57,9 +58,17 @@ char copyright[] = "@(#) Copyright (c) 1983 Regents of the University of Califor
#include <string>
#include <sys/stat.h>
#include <sys/types.h>
#include <syslog.h>
#include <vector>

#ifdef __APPLE__
# define syslog fprintf
# define LOG_NOTICE stdout
# define LOG_WARNING stdout
# define LOG_ERR stderr
#else
# include <syslog.h>
#endif

namespace tftpd {
extern const char *g_rootdir; // the only tftp root dir used!

Expand All @@ -80,7 +89,7 @@ constexpr bool suppress_error{false};
// Change root directory on startup. This means the remote host does not need to pass along the directory as part of the
// transfer, and may add security.
constexpr bool secure_tftp{true};
// Allow new files to be created. Normaly, tftpd will only allow upload of files that already exist.
// Allow new files to be created. Normally, tftpd will only allow upload of files that already exist.
constexpr bool allow_create{true};

struct formats
Expand All @@ -100,8 +109,17 @@ static struct formats formats[] = { // XXX {"netascii", /* validate_access, send
*/
int tftp(const std::vector<char> &rxbuffer, FILE *&file, std::string &file_path, std::vector<char> &optack)
{
// see too async_tftpd_server.cpp
boost::filesystem::path const dir(*dirs);
(void)boost::filesystem::create_directory(dir);

#ifndef __APPLE__
openlog("ftpd", LOG_PID | LOG_NDELAY, LOG_FTP);
#endif

syslog(LOG_NOTICE, "%s(%lu)\n", BOOST_CURRENT_FUNCTION, rxbuffer.size());
init_opt();
file = nullptr;

assert(rxbuffer.size() >= TFTP_HEADER);

Expand Down

0 comments on commit 04f0b34

Please sign in to comment.