Skip to content

Commit

Permalink
have cmake include version info and commit details.
Browse files Browse the repository at this point in the history
  • Loading branch information
ITotalJustice committed Dec 6, 2024
1 parent c221e18 commit 1e69648
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 36 deletions.
69 changes: 56 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
cmake_minimum_required(VERSION 3.13)

set(FTPSRV_VERSION_MAJOR 0)
set(FTPSRV_VERSION_MINOR 2)
set(FTPSRV_VERSION_PATCH 0)
set(FTPSRV_VERSION ${FTPSRV_VERSION_MAJOR}.${FTPSRV_VERSION_MINOR}.${FTPSRV_VERSION_PATCH})

project(ftpsrv
LANGUAGES C
VERSION 0.2.0
VERSION ${FTPSRV_VERSION}
DESCRIPTION "small and fast ftp server"
)

Expand Down Expand Up @@ -73,6 +78,35 @@ check_c_source_compiles("
int main(void) { strncasecmp(0, 0, 0); }"
HAVE_STRNCASECMP)

find_package(Git REQUIRED)

execute_process(
COMMAND "${GIT_EXECUTABLE}" rev-parse --short HEAD
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_COMMIT
OUTPUT_STRIP_TRAILING_WHITESPACE
)

execute_process(
COMMAND "${GIT_EXECUTABLE}" symbolic-ref --short HEAD
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)

execute_process(
COMMAND "${GIT_EXECUTABLE}" status --porcelain
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_DIRTY
OUTPUT_STRIP_TRAILING_WHITESPACE
)

if (GIT_DIRTY)
set(FTPSRV_VERSION_HASH "${FTPSRV_VERSION} ${GIT_COMMIT}-dirty")
else()
set(FTPSRV_VERSION_HASH "${FTPSRV_VERSION} ${GIT_COMMIT}-dirty")
endif()

function(fetch_minini)
FetchContent_Declare(minIni
GIT_REPOSITORY https://github.com/ITotalJustice/minIni-nx.git
Expand All @@ -87,17 +121,24 @@ function(fetch_minini)
endfunction(fetch_minini)

function(ftp_set_compile_definitions target)
target_compile_definitions(${target} PRIVATE
HAVE_READLINK=$<BOOL:${HAVE_READLINK}>
HAVE_GETPWUID=$<BOOL:${HAVE_GETPWUID}>
HAVE_GETGRGID=$<BOOL:${HAVE_GETGRGID}>
HAVE_STRNCASECMP=$<BOOL:${HAVE_STRNCASECMP}>
HAVE_POLL=$<BOOL:${HAVE_POLL}>
HAVE_IPTOS_THROUGHPUT=$<BOOL:${HAVE_IPTOS_THROUGHPUT}>
HAVE_TCP_NODELAY=$<BOOL:${HAVE_TCP_NODELAY}>
HAVE_SO_KEEPALIVE=$<BOOL:${HAVE_SO_KEEPALIVE}>
HAVE_SO_REUSEADDR=$<BOOL:${HAVE_SO_REUSEADDR}>
)
target_compile_definitions(${target}
PRIVATE
HAVE_READLINK=$<BOOL:${HAVE_READLINK}>
HAVE_GETPWUID=$<BOOL:${HAVE_GETPWUID}>
HAVE_GETGRGID=$<BOOL:${HAVE_GETGRGID}>
HAVE_STRNCASECMP=$<BOOL:${HAVE_STRNCASECMP}>
HAVE_POLL=$<BOOL:${HAVE_POLL}>
HAVE_IPTOS_THROUGHPUT=$<BOOL:${HAVE_IPTOS_THROUGHPUT}>
HAVE_TCP_NODELAY=$<BOOL:${HAVE_TCP_NODELAY}>
HAVE_SO_KEEPALIVE=$<BOOL:${HAVE_SO_KEEPALIVE}>
HAVE_SO_REUSEADDR=$<BOOL:${HAVE_SO_REUSEADDR}>
PUBLIC
FTPSRV_VERSION_MAJOR=${FTPSRV_VERSION_MAJOR}
FTPSRV_VERSION_MINOR=${FTPSRV_VERSION_MINOR}
FTPSRV_VERSION_PATCH=${FTPSRV_VERSION_PATCH}
FTPSRV_VERSION_STR="${FTPSRV_VERSION}"
FTPSRV_VERSION_HASH="${FTPSRV_VERSION_HASH}"
)
endfunction(ftp_set_compile_definitions)

function(ftp_set_options target path_size sessions buf_size)
Expand Down Expand Up @@ -202,6 +243,8 @@ if (NINTENDO_SWITCH)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/420000000000011B)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/420000000000011B/flags)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/platform/nx/sysftp.json ${CMAKE_CURRENT_BINARY_DIR}/sysftp.json)

add_custom_command(
TARGET ftpexe POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
Expand All @@ -214,7 +257,7 @@ if (NINTENDO_SWITCH)

nx_create_exefs(sysftp
OUTPUT 420000000000011B/exefs.nsp
CONFIG ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/nx/sysftp.json
CONFIG ${CMAKE_CURRENT_BINARY_DIR}/sysftp.json
)
elseif(NINTENDO_DS)
ftp_set_options(ftpsrv 769 16 1024*64)
Expand Down
2 changes: 1 addition & 1 deletion src/ftpsrv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ static void ftp_cmd_STAT(struct FtpSession* session, const char* data) {

// HELP <CRLF> | 211, 214, 500, 501, 502, 421
static void ftp_cmd_HELP(struct FtpSession* session, const char* data) {
ftp_client_msg(session, 214, "ftpsrv 0.2.0 By TotalJustice.");
ftp_client_msg(session, 214, "ftpsrv " FTPSRV_VERSION_STR " By TotalJustice.");
}

// NOOP <CRLF> | 200, 500, 421
Expand Down
10 changes: 0 additions & 10 deletions src/ftpsrv.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,6 @@ int ftpsrv_init(const struct FtpSrvConfig* cfg);
int ftpsrv_loop(int timeout_ms);
void ftpsrv_exit(void);

#if 0
int ftpsrv_config_init(struct FtpSrvConfig* cfg);
int ftpsrv_config_set_user(struct FtpSrvConfig* cfg, const char* user);
int ftpsrv_config_set_pass(struct FtpSrvConfig* cfg, const char* pass);
int ftpsrv_config_set_port(struct FtpSrvConfig* cfg, int port);
int ftpsrv_config_set_anon(struct FtpSrvConfig* cfg, int anon);
int ftpsrv_config_set_devices(struct FtpSrvConfig* cfg, const struct FtpSrvDevice* devices, unsigned count);
int ftpsrv_config_set_log_callback(struct FtpSrvConfig* cfg, FtpSrvLogCallback log_callback);
#endif

#ifdef __cplusplus
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/platform/3ds/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ int main(void) {
gfxInitDefault();
consoleInit(GFX_TOP, &topScreen);
consoleInit(GFX_BOTTOM, &bottomScreen);
consolePrint("\n[ftpsrv 0.2.0 By TotalJustice]\n\n");
consolePrint("\n[ftpsrv " FTPSRV_VERSION_STR " By TotalJustice]\n\n");

g_ftpsrv_config.log_callback = ftp_log_callback;
g_ftpsrv_config.anon = ini_getbool("Login", "anon", 0, INI_PATH);
Expand All @@ -142,7 +142,7 @@ int main(void) {
const bool log_enabled = ini_getbool("Log", "log", 0, INI_PATH);

if (log_enabled) {
log_file_init(LOG_PATH, "ftpsrv - 0.2.0 - 3DS");
log_file_init(LOG_PATH, "ftpsrv - " FTPSRV_VERSION_HASH " - 3DS");
}

if (!user_len && !pass_len) {
Expand Down
4 changes: 2 additions & 2 deletions src/platform/nds/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ int main(void) {
consoleInit(&topScreen, 3,BgType_Text4bpp, BgSize_T_256x256, 31, 0, true, true);
consoleInit(&bottomScreen, 3,BgType_Text4bpp, BgSize_T_256x256, 31, 0, false, true);

consolePrint("\n[ftpsrv 0.2.0 By TotalJustice]\n\n");
consolePrint("\n[ftpsrv " FTPSRV_VERSION_STR " By TotalJustice]\n\n");

// init sd card.
if (!fatInitDefault()) {
Expand All @@ -120,7 +120,7 @@ int main(void) {
const bool log_enabled = ini_getbool("Log", "log", 0, INI_PATH);

if (log_enabled) {
log_file_init(LOG_PATH, "ftpsrv - 0.2.0 - NDS");
log_file_init(LOG_PATH, "ftpsrv - " FTPSRV_VERSION_HASH " - NDS");
}

if (!user_len && !pass_len) {
Expand Down
4 changes: 2 additions & 2 deletions src/platform/nx/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ static int error_loop(const char* msg) {
}

int main(int argc, char** argv) {
consolePrint("\n[ftpsrv 0.2.0-v1 By TotalJustice]\n\n");
consolePrint("\n[ftpsrv " FTPSRV_VERSION_STR " By TotalJustice]\n\n");

padConfigureInput(8, HidNpadStyleSet_NpadStandard);
padInitializeDefault(&g_pad);
Expand All @@ -150,7 +150,7 @@ int main(int argc, char** argv) {
g_ftpsrv_config.port = ini_getl("Nx", "app_port", g_ftpsrv_config.port, INI_PATH);

if (log_enabled) {
log_file_init(LOG_PATH, "ftpsrv - 0.2.0 - NX-app");
log_file_init(LOG_PATH, "ftpsrv - " FTPSRV_VERSION_HASH " - NX-app");
}

vfs_nx_init(mount_devices, save_writable);
Expand Down
2 changes: 1 addition & 1 deletion src/platform/nx/main_sysmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ int main(void) {
g_ftpsrv_config.port = ini_getl("Nx", "sys_port", g_ftpsrv_config.port, INI_PATH);

if (log_enabled) {
log_file_init(LOG_PATH, "ftpsrv - 0.2.0 - NX-sys");
log_file_init(LOG_PATH, "ftpsrv - " FTPSRV_VERSION_HASH " - NX-sys");
}

vfs_nx_init(mount_devices, save_writable);
Expand Down
2 changes: 1 addition & 1 deletion src/platform/nx/sysftp.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sys-ftp",
"version": "0.2.0",
"version": "${FTPSRV_VERSION}",
"program_id": "0x420000000000011B",
"program_id_range_min": "0x420000000000011B",
"program_id_range_max": "0x420000000000011B",
Expand Down
2 changes: 1 addition & 1 deletion src/platform/unistd/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static void ftp_log_callback(enum FTP_API_LOG_TYPE type, const char* msg) {

static int print_usage(int code) {
printf("\
[ftpsrv 0.2.0 By TotalJustice] \n\n\
[ftpsrv " FTPSRV_VERSION_STR " By TotalJustice] \n\n\
Usage\n\n\
-h, --help = Display help.\n\
-v, --version = Display version.\n\
Expand Down
4 changes: 2 additions & 2 deletions src/platform/wii/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ int main(void) {
VIDEO_WaitVSync();
if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();

consolePrint("\n[ftpsrv 0.2.0 By TotalJustice]\n\n");
consolePrint("\n[ftpsrv " FTPSRV_VERSION_STR " By TotalJustice]\n\n");

if (!fatInitDefault()) {
return error_loop("failed to init fat device\n");
Expand All @@ -176,7 +176,7 @@ int main(void) {
const bool log_enabled = ini_getbool("Log", "log", 0, INI_PATH);

if (log_enabled) {
log_file_init(LOG_PATH, "ftpsrv - 0.2.0 - WII");
log_file_init(LOG_PATH, "ftpsrv - " FTPSRV_VERSION_HASH " - WII");
}

if (!user_len && !pass_len) {
Expand Down
2 changes: 1 addition & 1 deletion src/platform/wii/meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<app version="1">
<name>Ftpsrv</name>
<coder>TotalJustice</coder>
<version>0.2.0</version>
<version>${FTPSRV_VERSION}</version>
<short_description>FTP server</short_description>
</app>

0 comments on commit 1e69648

Please sign in to comment.