Mining software...
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

597 wiersze
22 KiB

  1. project(xmr-stak)
  2. cmake_minimum_required(VERSION 3.4.0)
  3. # enforce C++11
  4. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  5. set(CMAKE_CXX_EXTENSIONS OFF)
  6. set(CMAKE_CXX_STANDARD 11)
  7. if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
  8. set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}" CACHE PATH "install prefix" FORCE)
  9. endif(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
  10. # help to find cuda on systems with a software module system
  11. list(APPEND CMAKE_PREFIX_PATH "$ENV{CUDA_ROOT}")
  12. # allow user to extent CMAKE_PREFIX_PATH via environment variable
  13. list(APPEND CMAKE_PREFIX_PATH "$ENV{CMAKE_PREFIX_PATH}")
  14. ################################################################################
  15. # CMake user options
  16. ################################################################################
  17. # gcc 5.1 is the first GNU version without CoW strings
  18. # https://github.com/fireice-uk/xmr-stak-nvidia/pull/10#issuecomment-290821792
  19. # If you remove this guard to compile with older gcc versions the miner will produce
  20. # a high rate of wrong shares.
  21. if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
  22. if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.1)
  23. message(FATAL_ERROR "g++ version must be at least 5.1!")
  24. endif()
  25. endif()
  26. set(BUILD_TYPE "Release;Debug")
  27. if(NOT CMAKE_BUILD_TYPE)
  28. set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build" FORCE)
  29. endif()
  30. set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "${BUILD_TYPE}")
  31. set(XMR-STAK_COMPILE "native" CACHE STRING "select CPU compute architecture")
  32. set_property(CACHE XMR-STAK_COMPILE PROPERTY STRINGS "native;generic")
  33. if(XMR-STAK_COMPILE STREQUAL "native")
  34. if(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
  35. set(CMAKE_CXX_FLAGS "-march=native -mtune=native ${CMAKE_CXX_FLAGS}")
  36. set(CMAKE_C_FLAGS "-march=native -mtune=native ${CMAKE_C_FLAGS}")
  37. endif()
  38. elseif(XMR-STAK_COMPILE STREQUAL "generic")
  39. add_definitions("-DCONF_ENFORCE_OpenCL_1_2=1")
  40. else()
  41. message(FATAL_ERROR "XMR-STAK_COMPILE is set to an unknown value '${XMR-STAK_COMPILE}'")
  42. endif()
  43. # option to add static libgcc and libstdc++
  44. option(CMAKE_LINK_STATIC "link as much as possible libraries static" ON)
  45. ################################################################################
  46. # Find CUDA
  47. ################################################################################
  48. #option(CUDA_USE_STATIC_CUDA_RUNTIME "Use the static version of the CUDA runtime library if available" OFF)
  49. #set(CUDA_USE_STATIC_CUDA_RUNTIME OFF CACHE BOOL "Use the static version of the CUDA runtime library if available" FORCE)
  50. option(CUDA_ENABLE "Enable or disable CUDA support (NVIDIA backend)" ON)
  51. if(CUDA_ENABLE)
  52. find_package(CUDA 7.5)
  53. if(CUDA_FOUND)
  54. list(APPEND BACKEND_TYPES "nvidia")
  55. option(XMR-STAK_LARGEGRID "Support large CUDA block count > 128" ON)
  56. if(XMR-STAK_LARGEGRID)
  57. add_definitions("-DXMR_STAK_LARGEGRID=${XMR-STAK_LARGEGRID}")
  58. endif()
  59. set(DEVICE_COMPILER "nvcc")
  60. set(CUDA_COMPILER "${DEVICE_COMPILER}" CACHE STRING "Select the device compiler")
  61. if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
  62. list(APPEND DEVICE_COMPILER "clang")
  63. endif()
  64. set_property(CACHE CUDA_COMPILER PROPERTY STRINGS "${DEVICE_COMPILER}")
  65. set(XMR-STAK_THREADS 0 CACHE STRING "Set maximum number of threads (for compile time optimization)")
  66. if(NOT XMR-STAK_THREADS EQUAL 0)
  67. message(STATUS "xmr-stak-nvidia: set max threads per block to ${XMR-STAK_THREADS}")
  68. add_definitions("-DXMR_STAK_THREADS=${XMR-STAK_THREADS}")
  69. endif()
  70. set(DEFAULT_CUDA_ARCH "30;35;37;50;52")
  71. # Fermi GPUs are only supported with CUDA < 9.0
  72. if(CUDA_VERSION VERSION_LESS 9.0)
  73. list(APPEND DEFAULT_CUDA_ARCH "20")
  74. endif()
  75. # add Pascal support for CUDA >= 8.0
  76. if(NOT CUDA_VERSION VERSION_LESS 8.0)
  77. list(APPEND DEFAULT_CUDA_ARCH "60" "61" "62")
  78. endif()
  79. # add Volta support for CUDA >= 9.0
  80. if(NOT CUDA_VERSION VERSION_LESS 9.0)
  81. # Volta GPUs are currently not supported on MACOSX
  82. # https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html#cuda-general-known-issues
  83. if(NOT APPLE)
  84. list(APPEND DEFAULT_CUDA_ARCH "70")
  85. endif()
  86. endif()
  87. # add Turing support for CUDA >= 10.0
  88. if(NOT CUDA_VERSION VERSION_LESS 10.0)
  89. list(APPEND DEFAULT_CUDA_ARCH "75")
  90. endif()
  91. set(CUDA_ARCH "${DEFAULT_CUDA_ARCH}" CACHE STRING "Set GPU architecture (semicolon separated list, e.g. '-DCUDA_ARCH=20;35;60')")
  92. # generate comma separated list with architectures
  93. string(REPLACE ";" "+" STR_CUDA_ARCH "${CUDA_ARCH}")
  94. add_definitions("-DXMRSTAK_CUDA_ARCH_LIST=${STR_CUDA_ARCH}")
  95. # validate architectures (only numbers are allowed)
  96. foreach(CUDA_ARCH_ELEM ${CUDA_ARCH})
  97. string(REGEX MATCH "^[0-9]+$" IS_NUMBER ${CUDA_ARCH})
  98. if(NOT IS_NUMBER)
  99. message(FATAL_ERROR "Defined compute architecture '${CUDA_ARCH_ELEM}' in "
  100. "'${CUDA_ARCH}' is not an integral number, use e.g. '30' (for compute architecture 3.0).")
  101. endif()
  102. unset(IS_NUMBER)
  103. if(${CUDA_ARCH_ELEM} LESS 20)
  104. message(FATAL_ERROR "Unsupported CUDA architecture '${CUDA_ARCH_ELEM}' specified. "
  105. "Use '20' (for compute architecture 2.0) or higher.")
  106. endif()
  107. endforeach()
  108. option(CUDA_SHOW_REGISTER "Show registers used for each kernel and compute architecture" OFF)
  109. option(CUDA_KEEP_FILES "Keep all intermediate files that are generated during internal compilation steps" OFF)
  110. if(CUDA_COMPILER STREQUAL "clang")
  111. set(CLANG_BUILD_FLAGS "-O3 -x cuda --cuda-path=${CUDA_TOOLKIT_ROOT_DIR}")
  112. # activation usage of FMA
  113. set(CLANG_BUILD_FLAGS "${CLANG_BUILD_FLAGS} -ffp-contract=fast")
  114. if(CUDA_SHOW_REGISTER)
  115. set(CLANG_BUILD_FLAGS "${CLANG_BUILD_FLAGS} -Xcuda-ptxas -v")
  116. endif(CUDA_SHOW_REGISTER)
  117. if(CUDA_KEEP_FILES)
  118. set(CLANG_BUILD_FLAGS "${CLANG_BUILD_FLAGS} -save-temps=${PROJECT_BINARY_DIR}")
  119. endif(CUDA_KEEP_FILES)
  120. foreach(CUDA_ARCH_ELEM ${CUDA_ARCH})
  121. # set flags to create device code for the given architectures
  122. set(CLANG_BUILD_FLAGS "${CLANG_BUILD_FLAGS} --cuda-gpu-arch=sm_${CUDA_ARCH_ELEM}")
  123. endforeach()
  124. elseif(CUDA_COMPILER STREQUAL "nvcc")
  125. # add c++11 for cuda
  126. if(NOT CMAKE_CXX_FLAGS MATCHES "-std=c\\+\\+11")
  127. set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -std=c++11")
  128. endif()
  129. # avoid that nvcc in CUDA 8 complains about sm_20 pending removal
  130. if(CUDA_VERSION VERSION_EQUAL 8.0)
  131. set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -Wno-deprecated-gpu-targets")
  132. endif()
  133. # avoid that nvcc in CUDA < 8 tries to use libc `memcpy` within the kernel
  134. if(CUDA_VERSION VERSION_LESS 8.0)
  135. add_definitions(-D_FORCE_INLINES)
  136. endif()
  137. foreach(CUDA_ARCH_ELEM ${CUDA_ARCH})
  138. # set flags to create device code for the given architecture
  139. set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS}
  140. "--generate-code arch=compute_${CUDA_ARCH_ELEM},code=sm_${CUDA_ARCH_ELEM} --generate-code arch=compute_${CUDA_ARCH_ELEM},code=compute_${CUDA_ARCH_ELEM}")
  141. endforeach()
  142. # give each thread an independent default stream
  143. set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} --default-stream per-thread")
  144. option(CUDA_SHOW_CODELINES "Show kernel lines in cuda-gdb and cuda-memcheck" OFF)
  145. if(CUDA_SHOW_CODELINES)
  146. set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS}" --source-in-ptx -lineinfo)
  147. set(CUDA_KEEP_FILES ON CACHE BOOL "activate keep files" FORCE)
  148. endif(CUDA_SHOW_CODELINES)
  149. if(CUDA_SHOW_REGISTER)
  150. set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS}" -Xptxas=-v)
  151. endif(CUDA_SHOW_REGISTER)
  152. if(CUDA_KEEP_FILES)
  153. set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS}" --keep --keep-dir "${PROJECT_BINARY_DIR}")
  154. endif(CUDA_KEEP_FILES)
  155. if(CUDA_VERSION VERSION_LESS 8.0)
  156. # for CUDA 7.5 fix compile error: https://github.com/fireice-uk/xmr-stak/issues/34
  157. set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS}" "-D_MWAITXINTRIN_H_INCLUDED")
  158. endif()
  159. if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC" AND
  160. (CUDA_VERSION VERSION_EQUAL 9.0 OR
  161. CUDA_VERSION VERSION_EQUAL 9.1 OR
  162. CUDA_VERSION VERSION_EQUAL 9.2 OR
  163. CUDA_VERSION VERSION_EQUAL 10.0)
  164. )
  165. # workaround find_package(CUDA) is using the wrong path to the CXX host compiler
  166. # overwrite the CUDA host compiler variable with the used CXX MSVC
  167. set(CUDA_HOST_COMPILER ${CMAKE_CXX_COMPILER} CACHE FILEPATH "Host side compiler used by NVCC" FORCE)
  168. endif()
  169. else()
  170. message(FATAL_ERROR "selected CUDA compiler '${CUDA_COMPILER}' is not supported")
  171. endif()
  172. else()
  173. message(FATAL_ERROR "CUDA NOT found: use `-DCUDA_ENABLE=OFF` to build without NVIDIA GPU support")
  174. endif()
  175. else()
  176. add_definitions("-DCONF_NO_CUDA")
  177. endif()
  178. # help to find AMD app SDK on systems with a software module system
  179. list(APPEND CMAKE_PREFIX_PATH "$ENV{AMDAPPSDKROOT}")
  180. # allow user to extent CMAKE_PREFIX_PATH via environment variable
  181. list(APPEND CMAKE_PREFIX_PATH "$ENV{CMAKE_PREFIX_PATH}")
  182. ###############################################################################
  183. # Find OpenCL
  184. ###############################################################################
  185. option(OpenCL_ENABLE "Enable or disable OpenCL spport (AMD GPU support)" ON)
  186. if(OpenCL_ENABLE)
  187. # try to find AMD OpenCL before NVIDIA OpenCL
  188. find_path(OpenCL_INCLUDE_DIR
  189. NAMES
  190. CL/cl.h
  191. OpenCL/cl.h
  192. NO_DEFAULT_PATH
  193. PATHS
  194. ENV "OpenCL_ROOT"
  195. ENV AMDAPPSDKROOT
  196. ENV ATISTREAMSDKROOT
  197. ENV "PROGRAMFILES(X86)"
  198. /usr
  199. PATH_SUFFIXES
  200. include
  201. OpenCL/common/inc
  202. "AMD APP/include")
  203. find_library(OpenCL_LIBRARY
  204. NAMES
  205. OpenCL
  206. OpenCL.lib
  207. NO_DEFAULT_PATH
  208. PATHS
  209. ENV "OpenCL_ROOT"
  210. ENV AMDAPPSDKROOT
  211. ENV ATISTREAMSDKROOT
  212. ENV "PROGRAMFILES(X86)"
  213. PATH_SUFFIXES
  214. "AMD APP/lib/x86_64"
  215. lib/x86_64
  216. lib/x86_64-linux-gnu
  217. lib/x64
  218. OpenCL/common/lib/x64)
  219. # find package will use the previews searched path variables
  220. find_package(OpenCL)
  221. if(OpenCL_FOUND)
  222. list(APPEND BACKEND_TYPES "amd")
  223. include_directories(SYSTEM ${OpenCL_INCLUDE_DIRS})
  224. #set(LIBS ${LIBS} ${OpenCL_LIBRARY})
  225. link_directories(${OpenCL_LIBRARY})
  226. else()
  227. message(FATAL_ERROR "OpenCL NOT found: use `-DOpenCL_ENABLE=OFF` to build without OpenCL support for AMD gpu's")
  228. endif()
  229. else()
  230. add_definitions("-DCONF_NO_OPENCL")
  231. endif()
  232. ###############################################################################
  233. # CPU backend
  234. ###############################################################################
  235. option(CPU_ENABLE "Enable or disable CPU support" ON)
  236. if(NOT CPU_ENABLE)
  237. add_definitions("-DCONF_NO_CPU")
  238. else()
  239. list(APPEND BACKEND_TYPES "cpu")
  240. endif()
  241. ################################################################################
  242. # Find PThreads
  243. ################################################################################
  244. if(NOT WIN32)
  245. find_package(Threads REQUIRED)
  246. set(LIBS ${LIBS} ${CMAKE_THREAD_LIBS_INIT})
  247. endif()
  248. ################################################################################
  249. # Find microhttpd
  250. ################################################################################
  251. option(MICROHTTPD_ENABLE "Enable or disable the requirement of microhttp (http daemon)" ON)
  252. if(MICROHTTPD_ENABLE)
  253. find_path(MTHD_INCLUDE_DIR
  254. NAMES
  255. microhttpd.h
  256. PATHS
  257. /opt/local
  258. /usr/local
  259. /usr
  260. ENV "PROGRAMFILES(X86)"
  261. ENV "MICROHTTPD_ROOT"
  262. PATH_SUFFIXES
  263. include)
  264. find_library(MHTD
  265. NAMES
  266. microhttpd
  267. libmicrohttpd.lib
  268. PATHS
  269. ENV "MICROHTTPD_ROOT"
  270. PATH_SUFFIXES
  271. lib)
  272. if(MHTD STREQUAL "MHTD-NOTFOUND")
  273. message(FATAL_ERROR "microhttpd NOT found: use `-DMICROHTTPD_ENABLE=OFF` to build without http daemon support")
  274. else()
  275. set(LIBS ${LIBS} ${MHTD})
  276. include_directories(AFTER ${MTHD_INCLUDE_DIR})
  277. endif()
  278. else()
  279. add_definitions("-DCONF_NO_HTTPD")
  280. endif()
  281. ###############################################################################
  282. # Find OpenSSL
  283. ###############################################################################
  284. option(OpenSSL_ENABLE "Enable or disable the requirement of OpenSSL" ON)
  285. if(OpenSSL_ENABLE)
  286. find_package(OpenSSL)
  287. if(OPENSSL_FOUND)
  288. include_directories(${OPENSSL_INCLUDE_DIR})
  289. set(LIBS ${LIBS} ${OPENSSL_LIBRARIES})
  290. else()
  291. message(FATAL_ERROR "OpenSSL NOT found: use `-DOpenSSL_ENABLE=OFF` to build without SSL support")
  292. endif()
  293. else()
  294. add_definitions("-DCONF_NO_TLS")
  295. endif()
  296. ################################################################################
  297. # Find hwloc
  298. ################################################################################
  299. option(HWLOC_ENABLE "Enable or disable the requirement of hwloc" ON)
  300. if(HWLOC_ENABLE)
  301. find_path(HWLOC_INCLUDE_DIR
  302. NAMES
  303. hwloc.h
  304. PATHS
  305. /opt/local
  306. /usr/local
  307. /usr
  308. ENV "PROGRAMFILES(X86)"
  309. ENV "HWLOC_ROOT"
  310. PATH_SUFFIXES
  311. include)
  312. find_library(HWLOC
  313. NAMES
  314. libhwloc.lib
  315. hwloc
  316. PATHS
  317. ENV "HWLOC_ROOT"
  318. PATH_SUFFIXES
  319. lib)
  320. if(HWLOC STREQUAL "HWLOC-NOTFOUND" OR ${HWLOC_INCLUDE_DIR} STREQUAL "HWLOC_INCLUDE_DIR-NOTFOUND")
  321. message(FATAL_ERROR "hwloc NOT found: use `-DHWLOC_ENABLE=OFF` to build without hwloc support")
  322. else()
  323. set(LIBS ${LIBS} ${HWLOC})
  324. include_directories(AFTER ${HWLOC_INCLUDE_DIR})
  325. endif()
  326. else()
  327. add_definitions("-DCONF_NO_HWLOC")
  328. endif()
  329. ################################################################################
  330. # Windows Sockets
  331. ################################################################################
  332. if(WIN32)
  333. set(LIBS ${LIBS} wsock32 ws2_32)
  334. endif()
  335. ################################################################################
  336. # Versioning
  337. ################################################################################
  338. # Get the current working branch
  339. execute_process(
  340. COMMAND git rev-parse --abbrev-ref HEAD
  341. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  342. OUTPUT_VARIABLE GIT_BRANCH
  343. OUTPUT_STRIP_TRAILING_WHITESPACE
  344. )
  345. # Get the latest abbreviated commit hash of the working branch
  346. execute_process(
  347. COMMAND git log -1 --format=%h
  348. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  349. OUTPUT_VARIABLE GIT_COMMIT_HASH
  350. OUTPUT_STRIP_TRAILING_WHITESPACE
  351. )
  352. if(NOT GIT_COMMIT_HASH STREQUAL "")
  353. add_definitions("-DGIT_COMMIT_HASH=${GIT_COMMIT_HASH}")
  354. endif()
  355. if(NOT GIT_BRANCH STREQUAL "")
  356. add_definitions("-DGIT_BRANCH=${GIT_BRANCH}")
  357. endif()
  358. # generate backend string
  359. string(REPLACE ";" "-" STR_BACKEND_TYPES "${BACKEND_TYPES}")
  360. add_definitions("-DBACKEND_TYPE=${STR_BACKEND_TYPES}")
  361. ################################################################################
  362. # Compile & Link
  363. ################################################################################
  364. include_directories(BEFORE .)
  365. set (CMAKE_POSITION_INDEPENDENT_CODE TRUE)
  366. if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
  367. # remove warnings that f_open() is not save and f_open_s should be used
  368. add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
  369. # disable min define to allow usage of std::min
  370. add_definitions(-DNOMINMAX)
  371. else()
  372. # activate sse2 and aes-ni
  373. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2 -maes")
  374. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse2 -maes")
  375. endif()
  376. # add -Wall for debug builds with gcc
  377. if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  378. if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  379. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
  380. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
  381. endif()
  382. endif()
  383. if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
  384. set(CMAKE_CXX_FLAGS "-Wl,-z,noexecstack ${CMAKE_CXX_FLAGS}")
  385. set(CMAKE_C_FLAGS "-Wl,-z,noexecstack ${CMAKE_C_FLAGS}")
  386. endif()
  387. # activate static libgcc and libstdc++ linking
  388. if(CMAKE_LINK_STATIC)
  389. set(BUILD_SHARED_LIBRARIES OFF)
  390. set(DL_LIB ${CMAKE_DL_LIBS})
  391. set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
  392. if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_C_COMPILER_ID} STREQUAL "GNU")
  393. set(LIBS "-static-libgcc -static-libstdc++ ${LIBS}")
  394. endif()
  395. endif()
  396. if(CMAKE_C_COMPILER_ID MATCHES "MSVC")
  397. # asm optimized monero v8 code
  398. enable_language(ASM_MASM)
  399. set_property(SOURCE "xmrstak/backend/cpu/crypto/asm/cryptonight_v8_main_loop.asm" PROPERTY ASM_MASM)
  400. add_library(xmr-stak-asm
  401. STATIC
  402. "xmrstak/backend/cpu/crypto/asm/cryptonight_v8_main_loop.asm"
  403. )
  404. else()
  405. # asm optimized monero v8 code
  406. enable_language(ASM)
  407. set_property(SOURCE "xmrstak/backend/cpu/crypto/asm/cryptonight_v8_main_loop.S" PROPERTY CPP)
  408. set_source_files_properties("xmrstak/backend/cpu/crypto/asm/cryptonight_v8_main_loop.S" PROPERTIES COMPILE_FLAGS "-x assembler-with-cpp")
  409. add_library(xmr-stak-asm
  410. STATIC
  411. "xmrstak/backend/cpu/crypto/asm/cryptonight_v8_main_loop.S"
  412. )
  413. endif()
  414. set_property(TARGET xmr-stak-asm PROPERTY LINKER_LANGUAGE C)
  415. # compile C files
  416. file(GLOB SRCFILES_C "xmrstak/backend/cpu/crypto/*.c")
  417. add_library(xmr-stak-c
  418. STATIC
  419. ${SRCFILES_C}
  420. )
  421. set_property(TARGET xmr-stak-c PROPERTY C_STANDARD 99)
  422. if(MICROHTTPD_ENABLE)
  423. target_link_libraries(xmr-stak-c ${MHTD})
  424. endif()
  425. target_link_libraries(xmr-stak-c ${LIBS} xmr-stak-asm)
  426. # compile generic backend files
  427. file(GLOB BACKEND_CPP
  428. "xmrstak/*.cpp"
  429. "xmrstak/backend/cpu/*.cpp"
  430. "xmrstak/backend/*.cpp"
  431. "xmrstak/backend/cpu/crypto/*.cpp"
  432. "xmrstak/http/*.cpp"
  433. "xmrstak/misc/*.cpp"
  434. "xmrstak/net/*.cpp")
  435. add_library(xmr-stak-backend
  436. STATIC
  437. ${BACKEND_CPP}
  438. )
  439. target_link_libraries(xmr-stak-backend xmr-stak-c ${CMAKE_DL_LIBS} xmr-stak-asm)
  440. # compile CUDA backend
  441. if(CUDA_FOUND)
  442. file(GLOB CUDASRCFILES
  443. "xmrstak/backend/nvidia/nvcc_code/*.cu"
  444. "xmrstak/backend/nvidia/*.cpp")
  445. if(CUDA_COMPILER STREQUAL "clang")
  446. # build device code with clang
  447. add_library(
  448. xmrstak_cuda_backend
  449. SHARED
  450. ${CUDASRCFILES}
  451. )
  452. set_target_properties(xmrstak_cuda_backend PROPERTIES COMPILE_FLAGS ${CLANG_BUILD_FLAGS})
  453. set_target_properties(xmrstak_cuda_backend PROPERTIES LINKER_LANGUAGE CXX)
  454. set_source_files_properties(${CUDASRCFILES} PROPERTIES LANGUAGE CXX)
  455. else()
  456. # build device code with nvcc
  457. cuda_add_library(
  458. xmrstak_cuda_backend
  459. SHARED
  460. ${CUDASRCFILES}
  461. )
  462. endif()
  463. target_link_libraries(xmrstak_cuda_backend ${CUDA_LIBRARIES})
  464. target_link_libraries(xmrstak_cuda_backend xmr-stak-backend xmr-stak-asm)
  465. endif()
  466. # compile AMD backend
  467. if(OpenCL_FOUND)
  468. file(GLOB OPENCLSRCFILES
  469. "xmrstak/backend/amd/amd_gpu/*.cpp"
  470. "xmrstak/backend/amd/*.cpp")
  471. add_library(xmrstak_opencl_backend
  472. SHARED
  473. ${OPENCLSRCFILES}
  474. )
  475. target_link_libraries(xmrstak_opencl_backend ${OpenCL_LIBRARY} )
  476. target_link_libraries(xmrstak_opencl_backend xmr-stak-backend xmr-stak-asm)
  477. endif()
  478. # compile final binary
  479. file(GLOB SRCFILES_CPP "xmrstak/cli/*.cpp")
  480. set_source_files_properties(${SRCFILES_CPP} PROPERTIES LANGUAGE CXX)
  481. if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
  482. add_executable(xmr-stak ${SRCFILES_CPP} xmrstak/cli/xmr-stak.manifest)
  483. else()
  484. add_executable(xmr-stak ${SRCFILES_CPP})
  485. endif()
  486. set(EXECUTABLE_OUTPUT_PATH "bin" CACHE STRING "Path to place executables relative to ${CMAKE_INSTALL_PREFIX}")
  487. set(LIBRARY_OUTPUT_PATH "bin" CACHE STRING "Path to place libraries relative to ${CMAKE_INSTALL_PREFIX}")
  488. target_link_libraries(xmr-stak ${LIBS} xmr-stak-c xmr-stak-backend xmr-stak-asm)
  489. ################################################################################
  490. # Install
  491. ################################################################################
  492. # do not install the binary if the project and install are equal
  493. if( NOT CMAKE_INSTALL_PREFIX STREQUAL PROJECT_BINARY_DIR )
  494. install(TARGETS xmr-stak
  495. RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/${EXECUTABLE_OUTPUT_PATH}")
  496. if(CUDA_FOUND)
  497. if(WIN32)
  498. install(TARGETS xmrstak_cuda_backend
  499. RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/${LIBRARY_OUTPUT_PATH}")
  500. else()
  501. install(TARGETS xmrstak_cuda_backend
  502. LIBRARY DESTINATION "${CMAKE_INSTALL_PREFIX}/${LIBRARY_OUTPUT_PATH}")
  503. endif()
  504. endif()
  505. if(OpenCL_FOUND)
  506. if(WIN32)
  507. install(TARGETS xmrstak_opencl_backend
  508. RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/${LIBRARY_OUTPUT_PATH}")
  509. else()
  510. install(TARGETS xmrstak_opencl_backend
  511. LIBRARY DESTINATION "${CMAKE_INSTALL_PREFIX}/${LIBRARY_OUTPUT_PATH}")
  512. endif()
  513. endif()
  514. else()
  515. # this rule is used if the install prefix is the build directory
  516. install(CODE "MESSAGE(\"xmr-stak installed to folder 'bin'\")")
  517. endif()