From 852887d38db3fd71c05fd955af42b0a69d1bf8f0 Mon Sep 17 00:00:00 2001 From: Valient Gough Date: Sat, 13 Jun 2015 22:08:13 -0700 Subject: [PATCH] add cmake config --- .gitignore | 1 + CMakeLists.txt | 147 +++++++++++++++++++++++++++++++++++++ cmake/CheckFuncs.cmake | 49 +++++++++++++ cmake/CheckFuncs_stub.c.in | 16 ++++ cmake/FindFUSE.cmake | 42 +++++++++++ cmake/FindRLog.cmake | 28 +++++++ config.h.cmake | 16 ++++ devmode | 4 + encfs/SSL_Cipher.cpp | 4 +- encfs/encfs.cpp | 4 +- encfs/encfsctl.cpp | 4 - encfs/test.cpp | 4 - 12 files changed, 307 insertions(+), 12 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 cmake/CheckFuncs.cmake create mode 100644 cmake/CheckFuncs_stub.c.in create mode 100644 cmake/FindFUSE.cmake create mode 100644 cmake/FindRLog.cmake create mode 100644 config.h.cmake create mode 100644 devmode diff --git a/.gitignore b/.gitignore index 1ffb583..2325f5e 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ Makefile.in /ABOUT-NLS /autom4te.cache/ +/build /build-aux/ /config.h /config.h.in diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..b107388 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,147 @@ +cmake_minimum_required(VERSION 3.0) +project(EncFS C CXX) + +set (ENCFS_MAJOR 1) +set (ENCFS_MINOR 9) +set (ENCFS_VERSION "${ENCFS_MAJOR}.${ENCFS_MINOR}") +set (ENCFS_SOVERSION 7) +set (ENCFS_NAME "Encrypted Filesystem") + +set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} + "${CMAKE_SOURCE_DIR}/cmake") + +# We need C++ 11 +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED on) + +# Check for FUSE. +find_package (FUSE REQUIRED) +include_directories (${FUSE_INCLUDE_DIR}) +add_definitions (-D_FILE_OFFSET_BITS=64 -DFUSE_USE_VERSION=26) + +# Check for OpenSSL. +find_package (OpenSSL REQUIRED) +include_directories (${OPENSSL_INCLUDE_DIR}) + +find_package(Boost + 1.34.0 + REQUIRED + COMPONENTS serialization) +include_directories (${Boost_INCLUDE_DIRS}) + +find_package (RLog REQUIRED) +add_definitions (-DRLOG_COMPONENT="encfs") +include_directories (${RLOG_INCLUDE_DIR}) + +find_program (POD2MAN pod2man) +include (FindGettext) + +# Check for include files and stdlib properties. +include (CheckIncludeFileCXX) +check_include_file_cxx (attr/xattr.h HAVE_ATTR_XATTR_H) +check_include_file_cxx (sys/xattr.h HAVE_SYS_XATTR_H) + +check_include_file_cxx (tr1/memory HAVE_TR1_MEMORY) +check_include_file_cxx (tr1/unordered_map HAVE_TR1_UNORDERED_MAP) +check_include_file_cxx (tr1/unordered_set HAVE_TR1_UNORDERED_SET) +check_include_file_cxx (tr1/tuple HAVE_TR1_TUPLE) + +# Check if xattr functions take extra arguments, as they do on OSX. +include (CheckCXXSourceCompiles) +check_cxx_source_compiles ("#include + #include + int main() { getxattr(0,0,0,0,0,0); return 1; } + " XATTR_ADD_OPT) + +# Check if we have lchmod. +include (CheckFuncs) +check_function_exists_glibc (lchmod HAVE_LCHMOD) + +set (CMAKE_THREAD_PREFER_PTHREAD) +find_package (Threads REQUIRED) + +# Packaging config. +set (CPACK_PACKAGE_NAME "encfs") +set (CPACK_PACKAGE_VERSION_MAJOR ${ENCFS_MAJOR}) +set (CPACK_PACKAGE_VERSION_MINOR ${ENCFS_MINOR}) +set (CPACK_SOURCE_GENERATOR TGZ) +set (CPACK_SOURCE_IGNORE_FILES + "/build/") +include (CPack) + +configure_file (${CMAKE_SOURCE_DIR}/config.h.cmake + ${CMAKE_BINARY_DIR}/config.h) + +include_directories (${CMAKE_BINARY_DIR}) +include_directories (${CMAKE_SOURCE_DIR}) + +set(SOURCE_FILES + encfs/autosprintf.cpp + encfs/base64.cpp + encfs/BlockFileIO.cpp + encfs/BlockNameIO.cpp + encfs/Cipher.cpp + encfs/CipherFileIO.cpp + encfs/CipherKey.cpp + encfs/ConfigReader.cpp + encfs/ConfigVar.cpp + encfs/Context.cpp + encfs/DirNode.cpp + encfs/encfs.cpp + encfs/FileIO.cpp + encfs/FileNode.cpp + encfs/FileUtils.cpp + encfs/Interface.cpp + encfs/MACFileIO.cpp + encfs/MemoryPool.cpp + encfs/NameIO.cpp + encfs/NullCipher.cpp + encfs/NullNameIO.cpp + encfs/openssl.cpp + encfs/RawFileIO.cpp + encfs/readpassphrase.cpp + encfs/SSL_Cipher.cpp + encfs/StreamNameIO.cpp +) +add_library(encfs1 SHARED ${SOURCE_FILES}) +set_property(TARGET encfs1 PROPERTY VERSION ${ENCFS_VERSION}) +set_property(TARGET encfs1 PROPERTY SOVERSION ${ENCFS_SOVERSION}) +target_link_libraries(encfs1 + ${FUSE_LIBRARIES} + ${OPENSSL_LIBRARIES} + ${Boost_LIBRARIES} + ${RLOG_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} +) + +add_executable (encfs encfs/main.cpp) +target_link_libraries (encfs encfs1) + +add_executable (encfsctl encfs/encfsctl.cpp) +target_link_libraries (encfsctl encfs1) + +add_executable (makekey encfs/makeKey.cpp) +target_link_libraries (makekey encfs1) + +add_executable (checkops encfs/test.cpp) +target_link_libraries (checkops encfs1) + +# Reference all headers, to make certain IDEs happy. +file (GLOB_RECURSE all_headers ${CMAKE_SOURCE_DIR}/*.h) +add_custom_target (all_placeholder SOURCES ${all_headers}) + +if (POD2MAN) + add_custom_target (encfs-man ALL + COMMAND ${POD2MAN} -u --section=1 --release=${ENCFS_VERSION} --center=${ENCFS_NAME} + ${CMAKE_SOURCE_DIR}/encfs/encfs.pod encfs.1) + + add_custom_target (encfsctl-man ALL + COMMAND ${POD2MAN} -u --section=1 --release=${ENCFS_VERSION} --center=${ENCFS_NAME} + ${CMAKE_SOURCE_DIR}/encfs/encfsctl.pod encfsctl.1) + + install (FILES ${CMAKE_BINARY_DIR}/encfs.1 ${CMAKE_BINARY_DIR}/encfsctl.1 + DESTINATION share/man/man1) +endif (POD2MAN) + +install (TARGETS encfs DESTINATION bin) +install (FILES ${CMAKE_SOURCE_DIR}/encfs/encssh DESTINATION bin) diff --git a/cmake/CheckFuncs.cmake b/cmake/CheckFuncs.cmake new file mode 100644 index 0000000..0670df9 --- /dev/null +++ b/cmake/CheckFuncs.cmake @@ -0,0 +1,49 @@ +# Check if the system has the specified function; treat glibc "stub" +# functions as nonexistent: +# CHECK_FUNCTION_EXISTS_GLIBC (FUNCTION FUNCVAR) +# +# FUNCTION - the function(s) where the prototype should be declared +# FUNCVAR - variable to define if the function does exist +# +# In particular, this understands the glibc convention of +# defining macros __stub_XXXX or __stub___XXXX if the function +# does appear in the library but is merely a stub that does nothing. +# By detecting this case, we can select alternate behavior on +# platforms that don't support this functionality. +# +# The following variables may be set before calling this macro to +# modify the way the check is run: +# +# CMAKE_REQUIRED_FLAGS = string of compile command line flags +# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar) +# CMAKE_REQUIRED_INCLUDES = list of include directories +# Copyright (c) 2009, Michihiro NAKAJIMA +# +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. + +INCLUDE(CheckFunctionExists) +GET_FILENAME_COMPONENT(_selfdir_CheckFunctionExistsGlibc + "${CMAKE_CURRENT_LIST_FILE}" PATH) + +MACRO (CHECK_FUNCTION_EXISTS_GLIBC _FUNC _FUNCVAR) + IF(NOT DEFINED ${_FUNCVAR}) + SET(CHECK_STUB_FUNC_1 "__stub_${_FUNC}") + SET(CHECK_STUB_FUNC_2 "__stub___${_FUNC}") + CONFIGURE_FILE( ${_selfdir_CheckFunctionExistsGlibc}/CheckFuncs_stub.c.in + ${CMAKE_CURRENT_BINARY_DIR}/cmake.tmp/CheckFuncs_stub.c IMMEDIATE) + TRY_COMPILE(__stub + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_BINARY_DIR}/cmake.tmp/CheckFuncs_stub.c + COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} + CMAKE_FLAGS + -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILE_FLAGS} + "${CHECK_INCLUDE_FILE_C_INCLUDE_DIRS}") + IF (__stub) + SET("${_FUNCVAR}" "" CACHE INTERNAL "Have function ${_FUNC}") + ELSE (__stub) + CHECK_FUNCTION_EXISTS("${_FUNC}" "${_FUNCVAR}") + ENDIF (__stub) + ENDIF(NOT DEFINED ${_FUNCVAR}) +ENDMACRO (CHECK_FUNCTION_EXISTS_GLIBC) + diff --git a/cmake/CheckFuncs_stub.c.in b/cmake/CheckFuncs_stub.c.in new file mode 100644 index 0000000..50da414 --- /dev/null +++ b/cmake/CheckFuncs_stub.c.in @@ -0,0 +1,16 @@ +#ifdef __STDC__ +#include +#else +#include +#endif + +int +main() +{ +#if defined ${CHECK_STUB_FUNC_1} || defined ${CHECK_STUB_FUNC_2} + return 0; +#else +this system have stub + return 0; +#endif +} diff --git a/cmake/FindFUSE.cmake b/cmake/FindFUSE.cmake new file mode 100644 index 0000000..22952e6 --- /dev/null +++ b/cmake/FindFUSE.cmake @@ -0,0 +1,42 @@ +# Find the FUSE includes and library +# +# FUSE_INCLUDE_DIR - where to find fuse.h, etc. +# FUSE_LIBRARIES - List of libraries when using FUSE. +# FUSE_FOUND - True if FUSE lib is found. + +# check if already in cache, be silent +IF (FUSE_INCLUDE_DIR) + SET (FUSE_FIND_QUIETLY TRUE) +ENDIF (FUSE_INCLUDE_DIR) + +# find includes +FIND_PATH (FUSE_INCLUDE_DIR fuse.h + /usr/include/fuse + /usr/local/include/fuse + /opt/include/fuse + /opt/local/include/fuse + /usr/include/osxfuse + /usr/local/include/osxfuse + /opt/local/include/osxfuse + /usr/pkg/include/fuse +) + +# find lib +if (APPLE) + SET(FUSE_NAMES libosxfuse.dylib fuse) +else (APPLE) + SET(FUSE_NAMES fuse) +endif (APPLE) +FIND_LIBRARY(FUSE_LIBRARIES + NAMES ${FUSE_NAMES} + PATHS /lib64 /lib /usr/lib64 /usr/lib + /usr/local/lib64 /usr/local/lib + /opt/local/lib /usr/pkg/lib +) + +include ("FindPackageHandleStandardArgs") +find_package_handle_standard_args ("FUSE" DEFAULT_MSG + FUSE_INCLUDE_DIR FUSE_LIBRARIES) + +mark_as_advanced (FUSE_INCLUDE_DIR FUSE_LIBRARIES) + diff --git a/cmake/FindRLog.cmake b/cmake/FindRLog.cmake new file mode 100644 index 0000000..87e1173 --- /dev/null +++ b/cmake/FindRLog.cmake @@ -0,0 +1,28 @@ +# FindRLog +# -------- +# +# Find RLog +# +# Find the RLog logging library. This module defines +# +# :: +# +# RLOG_INCLUDE_DIR, where to find rlog.h, etc. +# RLOG_LIBRARIES, the libraries needed to use RLog. +# RLOG_FOUND, If false, do not try to use RLog. + +find_path(RLOG_INCLUDE_DIR rlog/rlog.h) + +set(RLOG_NAMES ${RLOG_NAMES} rlog librlog) +find_library(RLOG_LIBRARY NAMES ${RLOG_NAMES} ) + +# handle the QUIETLY and REQUIRED arguments and set RLOG_FOUND to TRUE if +# all listed variables are TRUE +include (FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(RLOG DEFAULT_MSG RLOG_LIBRARY RLOG_INCLUDE_DIR) + +if(RLOG_FOUND) + set(RLOG_LIBRARIES ${RLOG_LIBRARY}) +endif() + +mark_as_advanced(RLOG_LIBRARY RLOG_INCLUDE_DIR ) diff --git a/config.h.cmake b/config.h.cmake new file mode 100644 index 0000000..c182452 --- /dev/null +++ b/config.h.cmake @@ -0,0 +1,16 @@ +#define VERSION "@ENCFS_VERSION@" + +#cmakedefine HAVE_ATTR_XATTR_H +#cmakedefine HAVE_SYS_XATTR_H +#cmakedefine XATTR_ADD_OPT + +#cmakedefine HAVE_TR1_MEMORY +#cmakedefine HAVE_TR1_UNORDERED_MAP +#cmakedefine HAVE_TR1_UNORDERED_SET +#cmakedefine HAVE_TR1_TUPLE + +#cmakedefine HAVE_LCHMOD + +/* TODO: add other thread library support. */ +#cmakedefine CMAKE_USE_PTHREADS_INIT + diff --git a/devmode b/devmode new file mode 100644 index 0000000..cb53a37 --- /dev/null +++ b/devmode @@ -0,0 +1,4 @@ +# Script which sets up the CMake build for Debug mode. +# After running, chdir to the build subdir ane run "make" +mkdir build +cd build && cmake .. -DCMAKE_BUILD_TYPE=Debug $@ diff --git a/encfs/SSL_Cipher.cpp b/encfs/SSL_Cipher.cpp index b939d7c..50f1d95 100644 --- a/encfs/SSL_Cipher.cpp +++ b/encfs/SSL_Cipher.cpp @@ -158,7 +158,7 @@ int TimedPBKDF2(const char *pass, int passlen, const unsigned char *salt, static Interface BlowfishInterface("ssl/blowfish", 3, 0, 2); static Interface AESInterface("ssl/aes", 3, 0, 2); -#if defined(HAVE_EVP_BF) +#ifndef OPENSSL_NO_BF static Range BFKeyRange(128, 256, 32); static Range BFBlockRange(64, 4096, 8); @@ -182,7 +182,7 @@ static bool BF_Cipher_registered = BFKeyRange, BFBlockRange, NewBFCipher); #endif -#if defined(HAVE_EVP_AES) +#ifndef OPENSSL_NO_AES static Range AESKeyRange(128, 256, 64); static Range AESBlockRange(64, 4096, 16); diff --git a/encfs/encfs.cpp b/encfs/encfs.cpp index 42beac4..73b3e18 100644 --- a/encfs/encfs.cpp +++ b/encfs/encfs.cpp @@ -31,9 +31,9 @@ #include #endif -#if HAVE_SYS_XATTR_H +#if defined(HAVE_SYS_XATTR_H) #include -#elif HAVE_ATTR_XATTR_H +#elif defined(HAVE_ATTR_XATTR_H) #include #endif diff --git a/encfs/encfsctl.cpp b/encfs/encfsctl.cpp index e01880b..08782eb 100644 --- a/encfs/encfsctl.cpp +++ b/encfs/encfsctl.cpp @@ -29,10 +29,8 @@ #include #include -#ifdef HAVE_SSL #define NO_DES #include -#endif #include "Cipher.h" #include "Context.h" @@ -697,10 +695,8 @@ int main(int argc, char **argv) { textdomain(PACKAGE); #endif -#ifdef HAVE_SSL SSL_load_error_strings(); SSL_library_init(); -#endif StdioNode *slog = new StdioNode(STDERR_FILENO); slog->subscribeTo(GetGlobalChannel("error")); diff --git a/encfs/test.cpp b/encfs/test.cpp index defebb6..22d7242 100644 --- a/encfs/test.cpp +++ b/encfs/test.cpp @@ -39,13 +39,11 @@ #include #include -#ifdef HAVE_SSL #define NO_DES #include #ifndef OPENSSL_NO_ENGINE #include #endif -#endif using namespace std; using namespace rel; @@ -397,7 +395,6 @@ int main(int argc, char *argv[]) { stdLog.subscribeTo(RLOG_CHANNEL("debug")); #endif -#ifdef HAVE_SSL SSL_load_error_strings(); SSL_library_init(); @@ -406,7 +403,6 @@ int main(int argc, char *argv[]) { ENGINE_register_all_ciphers(); ENGINE_register_all_digests(); ENGINE_register_all_RAND(); -#endif #endif srand(time(0));