From 1c13b77ad48182b6b7897e376f7709f3f253e618 Mon Sep 17 00:00:00 2001 From: Ronald Ligteringen Date: Wed, 6 Mar 2024 11:06:11 +0100 Subject: [PATCH] add cmake --- .gitignore | 3 +- CMakeLists.txt | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++ config.h.in | 3 ++ 3 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 CMakeLists.txt create mode 100644 config.h.in diff --git a/.gitignore b/.gitignore index ffb115b3..17c24ace 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ *.lo *.la *.gz +*.swp \#*# *.orig *~ @@ -17,7 +18,7 @@ Makefile.in Makefile *.m4 stamp-h* -config.* +config.h sshfs.1 /sshfs /ltmain.sh diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..93c4fca7 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,83 @@ +cmake_minimum_required(VERSION 3.10) +project(sshfs VERSION 3.7.3 LANGUAGES C) + +# Build type +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE) + # Set the possible values of build type for cmake-gui + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") +endif() + +# Compiler flags +add_compile_options(-D_REENTRANT -DHAVE_CONFIG_H -Wall -Wextra -Wno-sign-compare -Wmissing-declarations -Wwrite-strings -Wno-unused-parameter) + +# Compiler check +include(CheckCSourceCompiles) + +check_c_source_compiles(" +__attribute__((warn_unused_result)) int get_4() { return 4; } +int main(void) { (void)get_4(); return 0; } +" COMPILER_GIVES_UNUSED_RESULT_WARNING) + +if(COMPILER_GIVES_UNUSED_RESULT_WARNING) + add_compile_options(-Wno-unused-result) +endif() + +# Dependencies +find_package(PkgConfig REQUIRED) +pkg_search_module(FUSE3 REQUIRED fuse3>=3.1.0) +pkg_search_module(GLIB REQUIRED glib-2.0) +pkg_search_module(GTHREAD REQUIRED gthread-2.0) + +# Sources and platform-specific adjustments +set(PACKAGE_VERSION ${PROJECT_VERSION}) +set(SOURCES sshfs.c cache.c) +if(APPLE) + list(APPEND SOURCES compat/fuse_opt.c compat/darwin_compat.c) + include_directories(compat) + set(IDMAP_DEFAULT use') +else() + set(IDMAP_DEFAULT none) +endif() +configure_file(config.h.in config.h) + +# Executable target +add_executable(sshfs ${SOURCES}) +target_include_directories(sshfs PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${FUSE3_INCLUDE_DIRS} ${GLIB_INCLUDE_DIRS} ${GTHREAD_INCLUDE_DIRS}) +target_compile_definitions(sshfs PRIVATE -DFUSE_USE_VERSION=31) +target_link_libraries(sshfs ${FUSE3_LIBRARIES} ${GLIB_LIBRARIES} ${GTHREAD_LIBRARIES}) +install(TARGETS sshfs DESTINATION bin) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/config.h DESTINATION include) + +# Creating links +# Assuming `sbindir` and `bindir` are determined or set previously in your CMakeLists.txt +set(sbindir "${CMAKE_INSTALL_PREFIX}/sbin") +set(bindir "${CMAKE_INSTALL_PREFIX}/bin") + +# Then, use the install(CODE ...) command to execute your script with these arguments +install(CODE "execute_process(COMMAND bash \"${CMAKE_CURRENT_SOURCE_DIR}/utils/install_helper.sh\" \"${sbindir}\" \"${bindir}\")") + +# Optional manual page generation (requires conditional checks in CMake) +find_program(RST2MAN rst2man) + +if(NOT RST2MAN) + message(WARNING "rst2man not found. Man pages will not be generated.") +else() + # Define the input and output files + set(MAN_PAGE_INPUT "${CMAKE_CURRENT_SOURCE_DIR}/sshfs.rst") + set(MAN_PAGE_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/sshfs.1") + + # Add a custom command to generate the man page + add_custom_command( + OUTPUT ${MAN_PAGE_OUTPUT} + COMMAND ${RST2MAN} ${MAN_PAGE_INPUT} ${MAN_PAGE_OUTPUT} + DEPENDS ${MAN_PAGE_INPUT} + COMMENT "Generating man page: sshfs.1" + ) + + # Add a custom target to trigger the custom command + add_custom_target(manpages ALL DEPENDS ${MAN_PAGE_OUTPUT}) + + # Install the man page + install(FILES ${MAN_PAGE_OUTPUT} DESTINATION share/man/man1) +endif() diff --git a/config.h.in b/config.h.in new file mode 100644 index 00000000..f4f58c8b --- /dev/null +++ b/config.h.in @@ -0,0 +1,3 @@ +// config.h.in +#define PACKAGE_VERSION "@PACKAGE_VERSION@" +#define IDMAP_DEFAULT "@IDMAP_DEFAULT@" \ No newline at end of file