diff options
-rw-r--r-- | CMakeLists.txt | 18 | ||||
-rw-r--r-- | cmake/FindFuse.cmake | 181 | ||||
-rw-r--r-- | src/version.c.in | 1 |
3 files changed, 164 insertions, 36 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 0141b05..5e3241c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ ################################################################################ PROJECT(dnbd3 C) -CMAKE_MINIMUM_REQUIRED(VERSION 2.6.2) +CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12) IF (CMAKE_BUILD_TYPE STREQUAL "") SET(CMAKE_BUILD_TYPE Debug) ENDIF() @@ -108,26 +108,18 @@ FILE(WRITE ${CMAKE_BINARY_DIR}/version.cmake ADD_CUSTOM_TARGET( version ${CMAKE_COMMAND} -D SRC=${CMAKE_SOURCE_DIR}/src/version.c.in - -D DST=${CMAKE_BINARY_DIR}/version.c + -D DST=${CMAKE_BINARY_DIR}/generated/version.c -D CMD=${CMAKE_SOURCE_DIR}/get-version.sh -P ${CMAKE_BINARY_DIR}/version.cmake ) -## This is required if you're not building the kernel module -## TODO: Find a nicer way to avoid parent includes, -## especially the ../version.h -> version.c -> version.h cycle -FILE(GLOB COMMON_HEADER_FILES src/*.h) -FOREACH(COMMON_HEADER_FILE ${COMMON_HEADER_FILES}) - CONFIGURE_FILE(${COMMON_HEADER_FILE} ${CMAKE_BINARY_DIR} COPYONLY) -ENDFOREACH( COMMON_HEADER_FILE ) - +INCLUDE_DIRECTORIES( ${CMAKE_BINARY_DIR}/generated ) ################################################################################ # CLIENT # ################################################################################ if(BUILD_KERNEL_MODULE) - INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}) FILE(GLOB_RECURSE CLIENT_SRCS src/client/*.c) ADD_EXECUTABLE(dnbd3-client ${CLIENT_SRCS}) TARGET_LINK_LIBRARIES(dnbd3-client) @@ -145,9 +137,9 @@ if(BUILD_SERVER) message(" ######################## Building server for AFL mode - will be useless otherwise!") ADD_DEFINITIONS(-DAFL_MODE) ENDIF() - INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${JANSSON_INCLUDE_DIR}) FILE(GLOB SERVER_SRCS src/server/*.c src/shared/*.c src/server/picohttpparser/*.c) ADD_EXECUTABLE(dnbd3-server ${SERVER_SRCS}) + TARGET_INCLUDE_DIRECTORIES(dnbd3-server PRIVATE ${JANSSON_INCLUDE_DIR}) TARGET_LINK_LIBRARIES(dnbd3-server ${CMAKE_THREAD_LIBS_INIT} ${JANSSON_LIBRARIES}) if(UNIX AND NOT APPLE) target_link_libraries(dnbd3-server rt) @@ -163,9 +155,9 @@ endif() ################################################################################ if(BUILD_FUSE_CLIENT) - INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${FUSE_INCLUDE_DIR}) FILE(GLOB FUSE_SRCS src/fuse/*.c src/shared/*.c) ADD_EXECUTABLE(dnbd3-fuse ${FUSE_SRCS}) + TARGET_INCLUDE_DIRECTORIES(dnbd3-fuse PRIVATE ${FUSE_INCLUDE_DIRS}) TARGET_LINK_LIBRARIES(dnbd3-fuse ${CMAKE_THREAD_LIBS_INIT} ${FUSE_LIBRARIES}) ADD_DEPENDENCIES(dnbd3-fuse version) INSTALL(TARGETS dnbd3-fuse RUNTIME DESTINATION bin) diff --git a/cmake/FindFuse.cmake b/cmake/FindFuse.cmake index b9c6f91..dd8a6c1 100644 --- a/cmake/FindFuse.cmake +++ b/cmake/FindFuse.cmake @@ -1,30 +1,167 @@ -# - Find fuse -# Find the native fuse includes and library +# This module can find FUSE Library # -# FUSE_INCLUDE_DIR - where to find fuse/fuse.h. -# FUSE_LIBRARIES - List of libraries when using fuse. -# FUSE_FOUND - True if fuse found. +# Requirements: +# - CMake >= 2.8.3 +# +# The following variables will be defined for your use: +# - FUSE_FOUND : was FUSE found? +# - FUSE_INCLUDE_DIRS : FUSE include directory +# - FUSE_LIBRARIES : FUSE library +# - FUSE_DEFINITIONS : FUSE cflags +# - FUSE_VERSION : complete version of FUSE (major.minor) +# - FUSE_MAJOR_VERSION : major version of FUSE +# - FUSE_MINOR_VERSION : minor version of FUSE +# +# Example Usage: +# +# 1. Copy this file in the root of your project source directory +# 2. Then, tell CMake to search this non-standard module in your project directory by adding to your CMakeLists.txt: +# set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}) +# 3. Finally call find_package() once, here are some examples to pick from +# +# Require FUSE 2.6 or later +# find_package(FUSE 2.6 REQUIRED) +# +# if(FUSE_FOUND) +# add_definitions(${FUSE_DEFINITIONS}) +# include_directories(${FUSE_INCLUDE_DIRS}) +# add_executable(myapp myapp.c) +# target_link_libraries(myapp ${FUSE_LIBRARIES}) +# endif() + +#============================================================================= +# Copyright (c) 2012, julp +# +# Distributed under the OSI-approved BSD License +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +#============================================================================= + +cmake_minimum_required(VERSION 2.8.3) + +########## Private ########## +function(fusedebug _varname) + if(FUSE_DEBUG) + message("${_varname} = ${${_varname}}") + endif(FUSE_DEBUG) +endfunction(fusedebug) + +########## Public ########## +set(FUSE_FOUND TRUE) +set(FUSE_LIBRARIES ) +set(FUSE_DEFINITIONS ) +set(FUSE_INCLUDE_DIRS ) + +find_package(PkgConfig) + +set(PC_FUSE_INCLUDE_DIRS ) +set(PC_FUSE_LIBRARY_DIRS ) +if(PKG_CONFIG_FOUND) + pkg_check_modules(PC_FUSE "fuse" QUIET) + if(PC_FUSE_FOUND) +# fusedebug(PC_FUSE_LIBRARIES) +# fusedebug(PC_FUSE_LIBRARY_DIRS) +# fusedebug(PC_FUSE_LDFLAGS) +# fusedebug(PC_FUSE_LDFLAGS_OTHER) +# fusedebug(PC_FUSE_INCLUDE_DIRS) +# fusedebug(PC_FUSE_CFLAGS) +# fusedebug(PC_FUSE_CFLAGS_OTHER) + set(FUSE_DEFINITIONS "${PC_FUSE_CFLAGS_OTHER}") + endif(PC_FUSE_FOUND) +endif(PKG_CONFIG_FOUND) + +find_path( + FUSE_INCLUDE_DIRS + NAMES fuse_common.h fuse_lowlevel.h fuse.h + PATHS "${PC_FUSE_INCLUDE_DIRS}" + DOC "Include directories for FUSE" +) + +if(NOT FUSE_INCLUDE_DIRS) + set(FUSE_FOUND FALSE) +endif(NOT FUSE_INCLUDE_DIRS) + +find_library( + FUSE_LIBRARIES + NAMES "fuse" + PATHS "${PC_FUSE_LIBRARY_DIRS}" + DOC "Libraries for FUSE" +) +if(NOT FUSE_LIBRARIES) + set(FUSE_FOUND FALSE) +endif(NOT FUSE_LIBRARIES) -IF (FUSE_INCLUDE_DIR) - # Already in cache, be silent - SET(FUSE_FIND_QUIETLY TRUE) -ENDIF (FUSE_INCLUDE_DIR) +if(FUSE_FOUND) + if(EXISTS "${FUSE_INCLUDE_DIRS}/fuse_common.h") + file(READ "${FUSE_INCLUDE_DIRS}/fuse_common.h" _contents) + string(REGEX REPLACE ".*# *define *FUSE_MAJOR_VERSION *([0-9]+).*" "\\1" FUSE_MAJOR_VERSION "${_contents}") + string(REGEX REPLACE ".*# *define *FUSE_MINOR_VERSION *([0-9]+).*" "\\1" FUSE_MINOR_VERSION "${_contents}") + set(FUSE_VERSION "${FUSE_MAJOR_VERSION}.${FUSE_MINOR_VERSION}") + endif() -FIND_PATH(FUSE_INCLUDE_DIR fuse/fuse.h) + include(CheckCSourceCompiles) + # Backup CMAKE_REQUIRED_* + set(OLD_CMAKE_REQUIRED_INCLUDES "${CMAKE_REQUIRED_INCLUDES}") + set(OLD_CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}") + set(OLD_CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS}") + # Add FUSE compilation flags + set(CMAKE_REQUIRED_INCLUDES "${CMAKE_REQUIRED_INCLUDES}" "${FUSE_INCLUDE_DIRS}") + set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}" "${FUSE_LIBRARIES}") + set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS}" "${FUSE_DEFINITIONS}") + check_c_source_compiles("#include <stdlib.h> +#include <fuse.h> +#include <stdio.h> +#include <string.h> +#include <errno.h> +#include <fcntl.h> -SET(FUSE_NAMES fuse) -FIND_LIBRARY(FUSE_LIBRARY NAMES ${FUSE_NAMES} ) +int main(void) { +return 0; +}" FUSE_CFLAGS_CHECK) + if(NOT FUSE_CFLAGS_CHECK) + set(FUSE_DEFINITIONS "-D_FILE_OFFSET_BITS=64") + # Should we run again previous test to assume the failure was due to missing definition -D_FILE_OFFSET_BITS=64? + endif(NOT FUSE_CFLAGS_CHECK) + # Restore CMAKE_REQUIRED_* + set(CMAKE_REQUIRED_INCLUDES "${OLD_CMAKE_REQUIRED_INCLUDES}") + set(CMAKE_REQUIRED_LIBRARIES "${OLD_CMAKE_REQUIRED_LIBRARIES}") + set(CMAKE_REQUIRED_DEFINITIONS "${OLD_CMAKE_REQUIRED_DEFINITIONS}") +endif(FUSE_FOUND) -# handle the QUIETLY and REQUIRED arguments and set FUSE_FOUND to TRUE if -# all listed variables are TRUE -INCLUDE(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(FUSE REQUIRED FUSE_LIBRARY FUSE_INCLUDE_DIR) +if(FUSE_INCLUDE_DIRS) + include(FindPackageHandleStandardArgs) + if(FUSE_FIND_REQUIRED AND NOT FUSE_FIND_QUIETLY) + find_package_handle_standard_args(FUSE REQUIRED_VARS FUSE_LIBRARIES FUSE_INCLUDE_DIRS VERSION_VAR FUSE_VERSION) + else() + find_package_handle_standard_args(FUSE "FUSE not found" FUSE_LIBRARIES FUSE_INCLUDE_DIRS) + endif() +else(FUSE_INCLUDE_DIRS) + if(FUSE_FIND_REQUIRED AND NOT FUSE_FIND_QUIETLY) + message(FATAL_ERROR "Could not find FUSE include directory") + endif() +endif(FUSE_INCLUDE_DIRS) -IF(FUSE_FOUND) - SET( FUSE_LIBRARIES ${FUSE_LIBRARY} ) -ELSE(FUSE_FOUND) - SET( FUSE_LIBRARIES ) -ENDIF(FUSE_FOUND) +mark_as_advanced( + FUSE_INCLUDE_DIRS + FUSE_LIBRARIES +) -MARK_AS_ADVANCED( FUSE_LIBRARY FUSE_INCLUDE_DIR ) +# IN (args) +fusedebug("FUSE_FIND_COMPONENTS") +fusedebug("FUSE_FIND_REQUIRED") +fusedebug("FUSE_FIND_QUIETLY") +fusedebug("FUSE_FIND_VERSION") +# OUT +# Found +fusedebug("FUSE_FOUND") +# Definitions +fusedebug("FUSE_DEFINITIONS") +# Linking +fusedebug("FUSE_INCLUDE_DIRS") +fusedebug("FUSE_LIBRARIES") +# Version +fusedebug("FUSE_MAJOR_VERSION") +fusedebug("FUSE_MINOR_VERSION") +fusedebug("FUSE_VERSION") diff --git a/src/version.c.in b/src/version.c.in index 54854c9..ab937a2 100644 --- a/src/version.c.in +++ b/src/version.c.in @@ -1,4 +1,3 @@ -#include "version.h" const char * VERSION_STRING = "@VERSION@"; |