Guest User

Untitled

a guest
Oct 20th, 2017
56
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. diff --git a/CMakeLists.txt b/CMakeLists.txt
  2. index 9f4ab2d..18ec365 100644
  3. --- a/CMakeLists.txt
  4. +++ b/CMakeLists.txt
  5. @@ -6,6 +6,9 @@ project(QtShadowsocks
  6.  
  7.  option(BUILD_SHARED_LIBS "Build ${PROJECT_NAME} as a shared library" ON)
  8.  option(USE_BOTAN2 "Build ${PROJECT_NAME} with Botan-2" OFF)
  9. +option(USE_STATIC_BOTAN "Link aginst static botan" OFF)
  10. +option(USE_PKG_CONFIG "You can try to manually specify packages if pkg-config won't work" ON)
  11. +option(STATIC_BUILD "" OFF)
  12.  
  13.  set(LIB_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib
  14.      CACHE PATH "Installation directory for libraries")
  15. @@ -17,28 +20,52 @@ set(CMAKE_CXX_STANDARD 14)
  16.  set(CMAKE_CXX_STANDARD_REQUIRED ON)
  17.  set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
  18.  
  19. +
  20.  find_package(Qt5Core 5.5)
  21.  find_package(Qt5Network 5.5)
  22. -find_package(PkgConfig)
  23. -
  24. -if (USE_BOTAN2)
  25. -    add_definitions(-DUSE_BOTAN2)
  26. -    pkg_check_modules(BOTAN REQUIRED botan-2>=2.3.0)
  27. +if (USE_PKG_CONFIG)
  28. +    set(PKG_CONFIG_PATH "" CACHE PATH "Extra search path for PKG_CONFIG_PATH")
  29. +    set(_pkgconfig_path_old "$ENV{PKG_CONFIG_PATH}")
  30. +    if(WIN32)
  31. +        set(ENV{PKG_CONFIG_PATH} "${PKG_CONFIG_PATH};$ENV{PKG_CONFIG_PATH}")
  32. +    else()
  33. +        set(ENV{PKG_CONFIG_PATH} "${PKG_CONFIG_PATH}:$ENV{PKG_CONFIG_PATH}")
  34. +    endif()
  35. +    find_package(PkgConfig)
  36. +    if (USE_BOTAN2)
  37. +        add_definitions(-DUSE_BOTAN2)
  38. +        pkg_check_modules(BOTAN REQUIRED botan-2>=2.3.0)
  39. +    else()
  40. +        pkg_check_modules(BOTAN REQUIRED botan-1.10)
  41. +    endif()
  42. +    set(ENV{PKG_CONFIG_PATH} "${_pkgconfig_path_old}")
  43. +    unset(_pkgconfig_path_old)
  44.  else()
  45. -    pkg_check_modules(BOTAN REQUIRED botan-1.10)
  46. +    if (USE_BOTAN2)
  47. +        set(BOTAN_LIBRARY_NAME "botan-2" CACHE STRING "")
  48. +    else()
  49. +        set(BOTAN_LIBRARY_NAME "botan" CACHE STRING "")
  50. +    endif()
  51. +    set(BOTAN_LIBRARY_DIRS "" CACHE PATH "")
  52.  endif()
  53.  find_library(BOTAN_LIBRARY_VAR
  54. -             NAMES ${BOTAN_LIBRARIES}
  55. -             HINTS ${BOTAN_LIBRARY_DIRS} ${BOTAN_LIBDIR})
  56. +            NAMES ${BOTAN_LIBRARIES}
  57. +            HINTS ${BOTAN_LIBRARY_DIRS} ${BOTAN_LIBDIR})
  58. +
  59. +include_directories(BEFORE ${BOTAN_INCLUDEDIR})
  60. +
  61. +if(USE_STATIC_BOTAN)
  62. +  add_definitions(-DBOTAN_DLL=)
  63. +endif()
  64.  
  65.  if(BUILD_SHARED_LIBS)
  66.     add_definitions(-DQSS_LIBRARY)
  67.  else()
  68.     add_definitions(-DQSS_STATIC)
  69.      if (MINGW)
  70. -        # This however doesn't fix the problem that the executables are depending on the GCC shared libraries
  71. -        # I can't find a solution in CMake so far. The workaround is to manually append "-l:libgcc.a -l:libstdc++.a -l:libwinpthread.a" to the end of executables' linklibs.rsp files (in CMakeFiles directory)
  72. -        set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++")
  73. +      # This however doesn't fix the problem that the executables are depending on the GCC shared libraries
  74. +      # I can't find a solution in CMake so far. The workaround is to manually append "-l:libgcc.a -l:libstdc++.a -l:libwinpthread.a" to the end of executables' linklibs.rsp files (in CMakeFiles directory)
  75. +      set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++")
  76.      endif()
  77.  endif()
  78.  
  79. @@ -46,6 +73,20 @@ if(WIN32 OR APPLE)
  80.      add_definitions(-DFD_SETSIZE=1024)
  81.  endif()
  82.  
  83. +if(WIN32 AND STATIC_BUILD)
  84. +    message(STATUS "Using /MT and /MTd instead of /MD")
  85. +    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
  86. +    set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /MT")
  87. +    set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /MT")
  88. +    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
  89. +    set(EXTRA_WIN32_STATIC_QT_LIBS optimized "${Qt5Core_DIR}/../../qtpcre2.lib" debug "${Qt5Core_DIR}/../../qtpcre2d.lib")
  90. +endif()
  91. +
  92. +set(EXTRA_PREDEFINE "" CACHE STRING "Extra pre-defined symbols, seperated with ; .")
  93. +foreach(EXTRA_PREDEFINE_I ${EXTRA_PREDEFINE})
  94. +  add_definitions("-D${EXTRA_PREDEFINE}")
  95. +endforeach()
  96. +
  97.  add_subdirectory(lib)
  98.  add_subdirectory(shadowsocks-libqss)
  99.  add_subdirectory(test)
  100. diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
  101. index 272c0b8..3bb3ef9 100644
  102. --- a/lib/CMakeLists.txt
  103. +++ b/lib/CMakeLists.txt
  104. @@ -46,6 +46,16 @@ target_link_libraries(${LIBNAME}
  105.      PUBLIC Qt5::Core
  106.      PUBLIC Qt5::Network
  107.      PRIVATE ${BOTAN_LIBRARY_VAR})
  108. +if(WIN32 AND STATIC_BUILD)
  109. +    target_link_libraries(${LIBNAME}
  110. +        PUBLIC "ws2_32.lib"
  111. +        PUBLIC "Iphlpapi.lib"
  112. +        PUBLIC "Dnsapi.lib"
  113. +        PUBLIC "Winmm.lib"
  114. +        PUBLIC "Mincore.lib")
  115. +    target_link_libraries(${LIBNAME}
  116. +        PUBLIC ${EXTRA_WIN32_STATIC_QT_LIBS})
  117. +endif()
  118.  target_include_directories(${LIBNAME} PRIVATE ${BOTAN_INCLUDE_DIRS})
  119.  
  120.  foreach(LIB Qt5Network Qt5Core ${BOTAN_LIBRARIES})
  121. diff --git a/lib/cipher.h b/lib/cipher.h
  122. index 969fb76..d35025d 100644
  123. --- a/lib/cipher.h
  124. +++ b/lib/cipher.h
  125. @@ -35,12 +35,9 @@
  126.  #include "rc4.h"
  127.  #include "chacha.h"
  128.  #include "export.h"
  129. -
  130. -namespace Botan {
  131. -class Keyed_Filter;
  132. -class Pipe;
  133. -class KDF;
  134. -}
  135. +#include "botan/key_filt.h"
  136. +#include "botan/pipe.h"
  137. +#include "botan/kdf.h"
  138.  
  139.  namespace QSS {
  140.  
  141. diff --git a/shadowsocks-libqss/CMakeLists.txt b/shadowsocks-libqss/CMakeLists.txt
  142. index ff7cb31..06637d4 100644
  143. --- a/shadowsocks-libqss/CMakeLists.txt
  144. +++ b/shadowsocks-libqss/CMakeLists.txt
  145. @@ -7,8 +7,15 @@ set(SOURCE
  146.      )
  147.  
  148.  add_executable(${TASK} ${SOURCE})
  149. +remove_definitions(-DQSS_LIBRARY)
  150.  
  151.  target_link_libraries(${TASK} Qt5::Core Qt5::Network QtShadowsocks)
  152. +if(WIN32 AND STATIC_BUILD)
  153. +    target_link_libraries(${TASK} "ws2_32.lib" "Iphlpapi.lib" "Dnsapi.lib" "Winmm.lib" "Mincore.lib")
  154. +    target_link_libraries(${TASK}
  155. +        ${EXTRA_WIN32_STATIC_QT_LIBS})
  156. +endif()
  157. +
  158.  target_include_directories(${TASK}
  159.      PUBLIC ${PROJECT_SOURCE_DIR}/lib)
  160.  
  161. diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
  162. index e076ecc..daac06c 100644
  163. --- a/test/CMakeLists.txt
  164. +++ b/test/CMakeLists.txt
  165. @@ -10,8 +10,15 @@ set(SOURCE
  166.      )
  167.  
  168.  add_executable(${TASK} ${SOURCE})
  169. +remove_definitions(-DQSS_LIBRARY)
  170.  
  171.  find_package(Qt5Test)
  172.  target_link_libraries(${TASK} Qt5::Core Qt5::Network Qt5::Test QtShadowsocks)
  173. +if(WIN32 AND STATIC_BUILD)
  174. +    target_link_libraries(${TASK} "ws2_32.lib" "Iphlpapi.lib" "Dnsapi.lib" "Winmm.lib" "Mincore.lib")
  175. +    target_link_libraries(${TASK}
  176. +        ${EXTRA_WIN32_STATIC_QT_LIBS})
  177. +endif()
  178. +
  179.  target_include_directories(${TASK}
  180.      PUBLIC ${PROJECT_SOURCE_DIR}/lib)
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×