Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make SSH backend optional #14

Merged
merged 6 commits into from
Sep 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 26 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

#
#
# CMake options
#
#

# CMake version
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
Expand Down Expand Up @@ -29,9 +29,9 @@ set_policy(CMP0042 NEW) # ENABLE CMP0042: MACOSX_RPATH is enabled by default.
set_policy(CMP0063 NEW) # ENABLE CMP0063: Honor visibility properties for all target types.


#
#
# Project description and (meta) information
#
#

# Get git revision
get_git_head_revision(GIT_REFSPEC GIT_SHA1)
Expand All @@ -58,22 +58,23 @@ string(MAKE_C_IDENTIFIER ${META_PROJECT_NAME} META_PROJECT_ID)
string(TOUPPER ${META_PROJECT_ID} META_PROJECT_ID)


#
#
# Project configuration options
#
#

# Project options
option(BUILD_SHARED_LIBS "Build shared instead of static libraries." ON)
option(OPTION_SELF_CONTAINED "Create a self-contained install with all dependencies." OFF)
option(OPTION_BUILD_TESTS "Build tests." ON)
option(OPTION_BUILD_DOCS "Build documentation." OFF)
option(OPTION_BUILD_EXAMPLES "Build examples." OFF)
option(OPTION_FORCE_SYSTEM_DIR_INSTALL "Force system dir install" OFF)
option(BUILD_SHARED_LIBS "Build shared instead of static libraries." ON)
option(OPTION_SELF_CONTAINED "Create a self-contained install with all dependencies." OFF)
option(OPTION_BUILD_TESTS "Build tests." ON)
option(OPTION_BUILD_DOCS "Build documentation." OFF)
option(OPTION_BUILD_EXAMPLES "Build examples." OFF)
option(OPTION_BUILD_SSH_BACKEND "Build SSH backend" OFF)
option(OPTION_FORCE_SYSTEM_DIR_INSTALL "Force system dir install" OFF)


#
#
# Declare project
#
#

# Generate folders for IDE targets (e.g., VisualStudio solutions)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
Expand All @@ -91,24 +92,24 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
file(WRITE "${PROJECT_BINARY_DIR}/VERSION" "${META_NAME_VERSION}")


#
#
# Compiler settings and options
#
#

include(cmake/CompileOptions.cmake)


#
#
# Project Health Check Setup
#
#

enable_cppcheck(On)
enable_clang_tidy(On)


#
#
# Deployment/installation setup
#
#

# Get project name
set(project ${META_PROJECT_NAME})
Expand Down Expand Up @@ -160,23 +161,23 @@ if(NOT SYSTEM_DIR_INSTALL)
if(APPLE)
set(CMAKE_INSTALL_RPATH "@loader_path/../../../${INSTALL_LIB}")
else()
set(CMAKE_INSTALL_RPATH "$ORIGIN/${INSTALL_LIB}")
set(CMAKE_INSTALL_RPATH "$ORIGIN/${INSTALL_LIB}")
endif()
endif()


#
#
# Project modules
#
#

add_subdirectory(source)
add_subdirectory(docs)
add_subdirectory(deploy)


#
#
# Deployment (global project files)
#
#

# Install version file
install(FILES "${PROJECT_BINARY_DIR}/VERSION" DESTINATION ${INSTALL_ROOT} COMPONENT runtime)
Expand Down
152 changes: 85 additions & 67 deletions source/cppfs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@

#
#
# External dependencies
#
#

find_package(LibSSH2 REQUIRED)
find_package(LibSSH2)
find_package(LibCrypto)
find_package(ZLIB)
find_package(OpenSSL)

if (LibSSH2_FOUND AND LibCrypto_FOUND AND ZLIB_FOUND AND OpenSSL_FOUND)
set(SSH_DEPS_MET TRUE)
else()
set(SSH_DEPS_MET FALSE)
endif()

if (OPTION_BUILD_SSH_BACKEND AND NOT SSH_DEPS_MET)
message(FATAL_ERROR "Requested to build ssh module but not all dependencies are found! LibSSH2: ${LibSSH2_FOUND}, LibCrypto: ${LibCrypto_FOUND}, ZLIB: ${ZLIB_FOUND}, OpenSSL: ${OpenSSL_FOUND}")
endif()


#
#
# Library name and options
#
#

# Target name
set(target cppfs)
Expand All @@ -25,9 +35,9 @@ set(export_file "include/${target}/${target}_api.h")
set(export_macro "${target_id}_API")


#
#
# Sources
#
#

set(include_path "${CMAKE_CURRENT_SOURCE_DIR}/include/${target}")
set(source_path "${CMAKE_CURRENT_SOURCE_DIR}/source")
Expand Down Expand Up @@ -62,12 +72,6 @@ set(headers
${include_path}/${localfs}/LocalFileSystem.h
${include_path}/${localfs}/LocalFileHandle.h
${include_path}/${localfs}/LocalFileIterator.h

${include_path}/ssh/SshFileSystem.h
${include_path}/ssh/SshFileHandle.h
${include_path}/ssh/SshFileIterator.h
${include_path}/ssh/SshInputStreamBuffer.h
${include_path}/ssh/SshOutputStreamBuffer.h
)

set(sources
Expand All @@ -92,26 +96,38 @@ set(sources
${source_path}/${localfs}/LocalFileSystem.cpp
${source_path}/${localfs}/LocalFileHandle.cpp
${source_path}/${localfs}/LocalFileIterator.cpp

${source_path}/ssh/SshFileSystem.cpp
${source_path}/ssh/SshFileHandle.cpp
${source_path}/ssh/SshFileIterator.cpp
${source_path}/ssh/SshInputStreamBuffer.cpp
${source_path}/ssh/SshOutputStreamBuffer.cpp
)

if (OPTION_BUILD_SSH_BACKEND)
set(headers ${headers}
${include_path}/ssh/SshFileSystem.h
${include_path}/ssh/SshFileHandle.h
${include_path}/ssh/SshFileIterator.h
${include_path}/ssh/SshInputStreamBuffer.h
${include_path}/ssh/SshOutputStreamBuffer.h
)

set(sources ${sources}
${source_path}/ssh/SshFileSystem.cpp
${source_path}/ssh/SshFileHandle.cpp
${source_path}/ssh/SshFileIterator.cpp
${source_path}/ssh/SshInputStreamBuffer.cpp
${source_path}/ssh/SshOutputStreamBuffer.cpp
)
endif ()

# Group source files
set(header_group "Header Files (API)")
set(source_group "Source Files")
source_group_by_path(${include_path} "\\\\.h$|\\\\.hpp$"
source_group_by_path(${include_path} "\\\\.h$|\\\\.hpp$"
${header_group} ${headers})
source_group_by_path(${source_path} "\\\\.cpp$|\\\\.c$|\\\\.h$|\\\\.hpp$"
source_group_by_path(${source_path} "\\\\.cpp$|\\\\.c$|\\\\.h$|\\\\.hpp$"
${source_group} ${sources})


#
#
# Create library
#
#

# Build library
add_library(${target}
Expand All @@ -132,9 +148,9 @@ generate_export_header(${target}
)


#
#
# Project options
#
#

set_target_properties(${target}
PROPERTIES
Expand All @@ -145,18 +161,17 @@ set_target_properties(${target}
)


#
#
# Include directories
#
#

target_include_directories(${target}
PRIVATE
${PROJECT_BINARY_DIR}/source/include
${CMAKE_CURRENT_SOURCE_DIR}/3rdparty
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_BINARY_DIR}/include
${OPENSSL_INCLUDE_DIR}
${LIBSSH2_INCLUDE_DIR}


PUBLIC
${DEFAULT_INCLUDE_DIRECTORIES}
Expand All @@ -167,47 +182,50 @@ target_include_directories(${target}
$<INSTALL_INTERFACE:include>
)

if (OPTION_BUILD_SSH_BACKEND)
target_include_directories(${target}
PRIVATE
${OPENSSL_INCLUDE_DIR}
${LIBSSH2_INCLUDE_DIR}
)
endif()

#

#
# Libraries
#
#

target_link_libraries(${target}
PRIVATE
${OPENSSL_LIBRARIES}
${LIBSSH2_LIBRARY}

PUBLIC
${DEFAULT_LIBRARIES}

INTERFACE
)

if("${CMAKE_SYSTEM_NAME}" MATCHES "Windows")
target_link_libraries(${target}
PRIVATE
wsock32.lib
ws2_32.lib
)
endif()

if(LibCrypto_FOUND)
if (OPTION_BUILD_SSH_BACKEND)
target_link_libraries(${target}
PRIVATE
${OPENSSL_LIBRARIES}
${LIBSSH2_LIBRARY}
${LIBCRYPTO_LIBRARY}
)
endif()

if(ZLIB_FOUND)
target_link_libraries(${target}
PRIVATE
${ZLIB_LIBRARY}
)

if("${CMAKE_SYSTEM_NAME}" MATCHES "Windows")
target_link_libraries(${target}
PRIVATE
wsock32.lib
ws2_32.lib
)
endif()
endif()

#

#
# Compile definitions
#
#

target_compile_definitions(${target}
PRIVATE
Expand All @@ -219,24 +237,24 @@ target_compile_definitions(${target}
INTERFACE
)

if (OPTION_BUILD_SSH_BACKEND)
target_compile_definitions(${target}
PRIVATE

#
# Compile options
#

target_compile_options(${target}
PRIVATE

PUBLIC
${DEFAULT_COMPILE_OPTIONS}
PUBLIC
${META_PROJECT_ID}_USE_LibSSH2
${META_PROJECT_ID}_USE_LibCrypto
${META_PROJECT_ID}_USE_OpenSSL
${META_PROJECT_ID}_USE_ZLIB

INTERFACE
)
INTERFACE
)
endif()


#
#
# Linker options
#
#

target_link_libraries(${target}
PRIVATE
Expand All @@ -248,9 +266,9 @@ target_link_libraries(${target}
)


#
#
# Target Health
#
#

perform_health_checks(
${target}
Expand All @@ -259,9 +277,9 @@ perform_health_checks(
)


#
#
# Deployment
#
#

# Library
install(TARGETS ${target}
Expand Down
Loading