From 11fe130e63197c465bb7863ee6963096d1f566d6 Mon Sep 17 00:00:00 2001
From: Treeve Jelbert <treeve@sourcemage.org>
Date: Sat, 13 Apr 2019 13:26:15 +0200
Subject: [PATCH 3/3] cmake fixes

cmake tweaks

clean & fix cmake
---
 CMakeLists.txt                   | 19 ++++++-------------
 cmake-utils/utils.cmake          | 11 ++---------
 src/CMakeLists.txt               |  9 +++++++++
 src/cpp-utils/CMakeLists.txt     |  2 +-
 src/cryfs-cli/CMakeLists.txt     | 14 +++++---------
 src/cryfs-unmount/CMakeLists.txt | 12 ++++--------
 src/cryfs/CMakeLists.txt         | 12 ++++++------
 src/fspp/fuse/CMakeLists.txt     |  2 +-
 src/stats/CMakeLists.txt         |  1 +
 9 files changed, 35 insertions(+), 47 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index fdbff71..330fa54 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
+cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
 cmake_policy(SET CMP0054 NEW)

 # TODO Perf test:
@@ -6,6 +6,8 @@ cmake_policy(SET CMP0054 NEW)
 #    -> if yes, offer a cmake option to enable both of these

 project(cryfs)
+set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
+set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)

 list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake-utils)
 include(utils)
@@ -24,15 +26,6 @@ option(USE_CLANG_TIDY "build with clang-tidy checks enabled" OFF)
 option(USE_IWYU "build with iwyu checks enabled" OFF)
 option(CLANG_TIDY_WARNINGS_AS_ERRORS "treat clang-tidy warnings as errors" OFF)

-if(USE_IWYU)
-    # note: for iwyu, we need cmake 3.3
-    cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
-endif()
-if(USE_CLANG_TIDY)
-    # note: for clang-tidy, we need cmake 3.6, or (if the return code should be handled correctly, e.g. on CI), we need 3.8.
-    cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
-endif()
-

 if (MSVC)
     option(DOKAN_PATH "Location of the Dokan library, e.g. C:\\Program Files\\Dokan\\DokanLibrary-1.1.0" "")
@@ -48,8 +41,8 @@ if(MSVC)
   add_definitions(/bigobj)
 endif()

-add_subdirectory(vendor EXCLUDE_FROM_ALL)
+#add_subdirectory(vendor EXCLUDE_FROM_ALL)
 add_subdirectory(src)
 add_subdirectory(doc)
-add_subdirectory(test)
-add_subdirectory(cpack)
+#add_subdirectory(test)
+#add_subdirectory(cpack)
diff --git a/cmake-utils/utils.cmake b/cmake-utils/utils.cmake
index da4dff8..4b227b7 100644
--- a/cmake-utils/utils.cmake
+++ b/cmake-utils/utils.cmake
@@ -107,16 +107,9 @@ endfunction(target_enable_style_warnings)
 ##################################################
 function(target_add_boost TARGET)
     # Load boost libraries
-    if(NOT DEFINED Boost_USE_STATIC_LIBS OR Boost_USE_STATIC_LIBS)
-        # Many supported systems don't have boost >= 1.65.1. Better link it statically.
-        message(STATUS "Boost will be statically linked")
-        set(Boost_USE_STATIC_LIBS ON)
-    else(NOT DEFINED Boost_USE_STATIC_LIBS OR Boost_USE_STATIC_LIBS)
-        message(STATUS "Boost will be dynamically linked")
-        set(Boost_USE_STATIC_LIBS OFF)
-    endif(NOT DEFINED Boost_USE_STATIC_LIBS OR Boost_USE_STATIC_LIBS)
+    option(Boost_USE_STATIC_LIBS "use static Boost libraries" OFF)
     set(BOOST_THREAD_VERSION 4)
-    find_package(Boost 1.65.1
+    find_package(Boost 1.70.0
             REQUIRED
             COMPONENTS ${ARGN})
     target_include_directories(${TARGET} SYSTEM PUBLIC ${Boost_INCLUDE_DIRS})
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index a803b1c..c18c676 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,5 +1,14 @@
 include_directories(${CMAKE_CURRENT_SOURCE_DIR})
+find_package(PkgConfig REQUIRED)
+find_package(spdlog REQUIRED)
+find_package(fmt REQUIRED)
+add_definitions("-DSPDLOG_FMT_EXTERNAL=1")
+#include_directories(${FMT_INCLUDE_DIR})
+#include_directories(/usr/include)

+#find_library(SCRYPT NAMES libpercival percival)
+pkg_search_module(SCRYPT REQUIRED libpercival)
+#find_package(scrypt REQUIRED)
 add_subdirectory(gitversion)
 add_subdirectory(cpp-utils)
 add_subdirectory(fspp)
diff --git a/src/cpp-utils/CMakeLists.txt b/src/cpp-utils/CMakeLists.txt
index f66f99f..079ef18 100644
--- a/src/cpp-utils/CMakeLists.txt
+++ b/src/cpp-utils/CMakeLists.txt
@@ -89,7 +89,7 @@ target_link_libraries(${PROJECT_NAME} PUBLIC ${CMAKE_THREAD_LIBS_INIT})

 target_link_libraries(${PROJECT_NAME} PUBLIC ${CMAKE_DL_LIBS})

-target_link_libraries(${PROJECT_NAME} PUBLIC spdlog cryptopp)
+target_link_libraries(${PROJECT_NAME} PUBLIC cryptopp fmt)

 target_add_boost(${PROJECT_NAME} filesystem system thread chrono)
 target_enable_style_warnings(${PROJECT_NAME})
diff --git a/src/cryfs-cli/CMakeLists.txt b/src/cryfs-cli/CMakeLists.txt
index 90edb22..5a5b0dc 100644
--- a/src/cryfs-cli/CMakeLists.txt
+++ b/src/cryfs-cli/CMakeLists.txt
@@ -11,8 +11,10 @@ set(SOURCES
         program_options/Parser.cpp
 )

-add_library(${PROJECT_NAME} ${SOURCES})
+add_executable(${PROJECT_NAME} main.cpp  ${SOURCES})
+target_compile_definitions(${PROJECT_NAME} PRIVATE -D_FILE_OFFSET_BITS=64)
 target_link_libraries(${PROJECT_NAME} PUBLIC cryfs cpp-utils gitversion fspp-fuse)
+target_link_libraries(${PROJECT_NAME} PUBLIC boost_program_options boost_filesystem boost_system boost_thread boost_chrono)
 target_enable_style_warnings(${PROJECT_NAME})
 target_activate_cpp14(${PROJECT_NAME})

@@ -20,13 +22,7 @@ if(NOT CRYFS_UPDATE_CHECKS)
     target_compile_definitions(${PROJECT_NAME} PRIVATE -DCRYFS_NO_UPDATE_CHECKS)
 endif(NOT CRYFS_UPDATE_CHECKS)

-add_executable(${PROJECT_NAME}_bin main.cpp)
-set_target_properties(${PROJECT_NAME}_bin PROPERTIES OUTPUT_NAME cryfs)
-target_link_libraries(${PROJECT_NAME}_bin PUBLIC ${PROJECT_NAME})
-target_enable_style_warnings(${PROJECT_NAME}_bin)
-target_activate_cpp14(${PROJECT_NAME}_bin)
-
-install(TARGETS ${PROJECT_NAME}_bin
+install(TARGETS ${PROJECT_NAME}
         CONFIGURATIONS Debug Release RelWithDebInfo
-        DESTINATION ${CMAKE_INSTALL_BINDIR}
+        DESTINATION bin
 )
diff --git a/src/cryfs-unmount/CMakeLists.txt b/src/cryfs-unmount/CMakeLists.txt
index 0a246a7..b362807 100644
--- a/src/cryfs-unmount/CMakeLists.txt
+++ b/src/cryfs-unmount/CMakeLists.txt
@@ -7,18 +7,14 @@ set(SOURCES
	Cli.cpp
 )

-add_library(${PROJECT_NAME} ${SOURCES})
+add_executable(${PROJECT_NAME} main_unmount.cpp ${SOURCES})
 target_link_libraries(${PROJECT_NAME} PUBLIC cpp-utils cryfs fspp-fuse)
+target_link_libraries(${PROJECT_NAME} PUBLIC boost_program_options boost_filesystem boost_thread boost_chrono)
 target_enable_style_warnings(${PROJECT_NAME})
 target_activate_cpp14(${PROJECT_NAME})

-add_executable(${PROJECT_NAME}_bin main_unmount.cpp)
-set_target_properties(${PROJECT_NAME}_bin PROPERTIES OUTPUT_NAME cryfs-unmount)
-target_link_libraries(${PROJECT_NAME}_bin PUBLIC ${PROJECT_NAME})
-target_enable_style_warnings(${PROJECT_NAME}_bin)
-target_activate_cpp14(${PROJECT_NAME}_bin)

-install(TARGETS ${PROJECT_NAME}_bin
+install(TARGETS ${PROJECT_NAME}
		CONFIGURATIONS Debug Release RelWithDebInfo
-		DESTINATION ${CMAKE_INSTALL_BINDIR}
+		DESTINATION bin
 )
diff --git a/src/cryfs/CMakeLists.txt b/src/cryfs/CMakeLists.txt
index 62d358d..45358e9 100644
--- a/src/cryfs/CMakeLists.txt
+++ b/src/cryfs/CMakeLists.txt
@@ -49,13 +49,13 @@ set(LIB_SOURCES
         localstate/BasedirMetadata.cpp
 )

-add_library(${PROJECT_NAME} STATIC ${LIB_SOURCES})
+add_library(${PROJECT_NAME} SHARED ${LIB_SOURCES})
 target_link_libraries(${PROJECT_NAME} PUBLIC cpp-utils fspp-interface blockstore blobstore gitversion)
-target_add_boost(${PROJECT_NAME} program_options chrono) # TODO Check that dependent projects don't get boost added (use PRIVATE here)
+target_add_boost(${PROJECT_NAME} filesystem program_options chrono thread) # TODO Check that dependent projects don't get boost added (use PRIVATE here)
 target_enable_style_warnings(${PROJECT_NAME})
 target_activate_cpp14(${PROJECT_NAME})

-#install(TARGETS ${PROJECT_NAME}
-#        DESTINATION lib
-#        CONFIGURATIONS Release
-#)
+install(TARGETS ${PROJECT_NAME}
+        DESTINATION lib
+        CONFIGURATIONS Release
+)
diff --git a/src/fspp/fuse/CMakeLists.txt b/src/fspp/fuse/CMakeLists.txt
index b991bd7..55197a2 100644
--- a/src/fspp/fuse/CMakeLists.txt
+++ b/src/fspp/fuse/CMakeLists.txt
@@ -32,7 +32,7 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
   target_link_libraries(${PROJECT_NAME} PUBLIC "${DOKAN_LIB_PATH}/lib/dokanfuse1.lib")

   install(FILES "${DOKAN_LIB_PATH}/dokan1.dll" "${DOKAN_LIB_PATH}/dokanfuse1.dll"
-    DESTINATION "${CMAKE_INSTALL_BINDIR}"
+    DESTINATION bin
   )

 elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
diff --git a/src/stats/CMakeLists.txt b/src/stats/CMakeLists.txt
index c29f44e..d90bdb6 100644
--- a/src/stats/CMakeLists.txt
+++ b/src/stats/CMakeLists.txt
@@ -6,6 +6,7 @@ set(SOURCES

 add_executable(${PROJECT_NAME} ${SOURCES})
 target_link_libraries(${PROJECT_NAME} PUBLIC cryfs cpp-utils gitversion)
+target_link_libraries(${PROJECT_NAME} PUBLIC boost_program_options boost_filesystem boost_thread boost_chrono)
 target_enable_style_warnings(${PROJECT_NAME})
 target_activate_cpp14(${PROJECT_NAME})
 set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME cryfs-stats)
--
2.21.0
