-
Notifications
You must be signed in to change notification settings - Fork 64
/
CMakeLists.txt
279 lines (243 loc) · 9.84 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
##################################################################
# Project and CMake settings
##################################################################
cmake_minimum_required(VERSION 3.0.2)
project(creepMiner)
set(CMAKE_CXX_STANDARD 14)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RELWITHDEBINFO)
endif ()
##################################################################
# Configuration types
##################################################################
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
option(MINIMAL_BUILD "If yes, the miner will be build without any extras like CUDA, CPU instructions..." OFF)
option(NO_GPU "If yes, the miner will be build without CUDA and OpenCL." OFF)
##################################################################
# Environment variables
##################################################################
# get the version number from version.id
file(STRINGS version.id VERSION_RAW)
string(REPLACE "version:" "" VERSION ${VERSION_RAW})
# make a list
string(REPLACE "." ";" VERSION_LIST ${VERSION})
# filter version numbers
list(GET VERSION_LIST 0 VERSION_MAJOR)
list(GET VERSION_LIST 1 VERSION_MINOR)
list(GET VERSION_LIST 2 VERSION_BUILD)
list(GET VERSION_LIST 3 VERSION_REVISION)
# define it for the source files
add_definitions(-DVERSION_MAJOR=${VERSION_MAJOR}
-DVERSION_MINOR=${VERSION_MINOR}
-DVERSION_BUILD=${VERSION_BUILD}
-DVERSION_REVISION=${VERSION_REVISION})
##################################################################
# using Conan for dependencies
##################################################################
option(USE_CONAN "If ON, Conan will be used to satisfy OpenSSL,POCO,and zlib dependency" ON)
if (USE_CONAN)
# init conan
if (CONAN_DEBUG)
include(conan/debug/conanbuildinfo.cmake)
else ()
include(conanbuildinfo.cmake)
endif ()
conan_basic_setup()
endif ()
##################################################################
# CPU architecture (only for Unix/Mac)
##################################################################
if (UNIX OR APPLE)
set(CPU_ARCH "X64" CACHE STRING "CPU architecture")
set_property(CACHE CPU_ARCH PROPERTY STRINGS X32 X64)
if (CPU_ARCH STREQUAL "X32")
add_definitions(-m32)
endif ()
endif ()
##################################################################
# GPU acceleration
##################################################################
option(USE_CUDA "If yes, CUDA will be enabled" ON)
option(USE_OPENCL "If yes, OpenCL will be enabled" ON)
if (USE_CUDA AND NOT MINIMAL_BUILD AND NOT NO_GPU)
find_package(CUDA REQUIRED)
add_definitions(-DUSE_CUDA)
set(GPU_CUDA_ARCH "sm_52" CACHE STRING "The CUDA architecture")
set(CUDA_NVCC_FLAGS
${CUDA_NVCC_FLAGS}
-arch=${GPU_CUDA_ARCH}
-std=c++11
-default-stream per-thread
-gencode=arch=compute_30,code=sm_30
-gencode=arch=compute_50,code=sm_50
-gencode=arch=compute_52,code=sm_52
-gencode=arch=compute_52,code=compute_52
-gencode=arch=compute_60,code=sm_60
-gencode=arch=compute_61,code=sm_61
-gencode=arch=compute_62,code=sm_62)
endif()
if (USE_OPENCL AND NOT MINIMAL_BUILD AND NOT NO_GPU)
find_package(OpenCL REQUIRED)
include_directories(${OpenCL_INCLUDE_DIR})
add_definitions(-DUSE_OPENCL)
endif ()
##################################################################
# Additional options
##################################################################
option(CONAN_DEBUG "Only for development" OFF)
##################################################################
# UNIX / BSD specific
##################################################################
if (UNIX OR APPLE)
add_definitions(-D_REENTRANT -std=c++14)
link_directories(/usr/local/lib)
include_directories(/usr/local/include ${CMAKE_CURRENT_SOURCE_DIR}/src)
##################################################################
# MSVC specific
##################################################################
elseif (MSVC)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)
set_source_files_properties(bin/icon.ico src/resources.rc PROPERTIES LANGUAGE RC)
add_definitions(/MP)
endif ()
##################################################################
# Source files
##################################################################
file(GLOB SOURCE_FILES
src/*.*pp
src/gpu/impl/*.*pp
src/logging/channels/*.*pp
src/logging/*.*pp
src/mining/*.*pp
src/network/*.*pp
src/nxt/nxt_address.h
src/nxt/nxt_address.cpp
src/plots/*.*pp
src/shabal/*.*pp
src/shabal/sphlib/*.*pp
src/wallet/*.*pp
src/webserver/*.*pp
src/resources.rc)
##################################################################
# Special files and settings
##################################################################
option(USE_SSE4 "If yes, SSE4 will be enabled" ON)
option(USE_AVX "If yes, AVX will be enabled" ON)
option(USE_AVX2 "If yes, AVX2 will be enabled" ON)
if (USE_SSE4 AND NOT MINIMAL_BUILD)
add_definitions(-DUSE_SSE4)
set(SOURCE_FILES ${SOURCE_FILES} src/shabal/mshabal/mshabal_sse4.cpp)
if (UNIX OR APPLE)
set_source_files_properties(src/shabal/mshabal/mshabal_sse4.cpp PROPERTIES COMPILE_FLAGS -msse2)
endif ()
endif ()
if (USE_AVX AND NOT MINIMAL_BUILD)
add_definitions(-DUSE_AVX)
set(SOURCE_FILES ${SOURCE_FILES} src/shabal/mshabal/mshabal_avx1.cpp)
if (UNIX OR APPLE)
set_source_files_properties(src/shabal/mshabal/mshabal_avx1.cpp PROPERTIES COMPILE_FLAGS -mavx)
elseif (MSVC)
set_source_files_properties(src/shabal/mshabal/mshabal_avx1.cpp PROPERTIES COMPILE_FLAGS /arch:AVX)
endif ()
endif ()
if (USE_AVX2 AND NOT MINIMAL_BUILD)
add_definitions(-DUSE_AVX2)
set(SOURCE_FILES ${SOURCE_FILES} src/shabal/mshabal/mshabal_avx2.cpp)
if (UNIX OR APPLE)
set_source_files_properties(src/shabal/mshabal/mshabal_avx2.cpp PROPERTIES COMPILE_FLAGS -mavx2)
elseif (MSVC)
set_source_files_properties(src/shabal/mshabal/mshabal_avx2.cpp PROPERTIES COMPILE_FLAGS /arch:AVX2)
endif ()
endif ()
if (USE_CUDA AND NOT MINIMAL_BUILD AND NOT NO_GPU)
set(SOURCE_FILES ${SOURCE_FILES} src/shabal/cuda/Shabal.cu)
endif ()
##################################################################
# Executable
##################################################################
if (USE_CUDA AND NOT MINIMAL_BUILD AND NOT NO_GPU)
cuda_add_executable(creepMiner ${SOURCE_FILES})
else ()
add_executable(creepMiner ${SOURCE_FILES})
endif ()
##################################################################
# Libraries
##################################################################
# Optimised Shabal Library
find_library(SHABAL_LIB NAMES shabal.dll libshabal.dylib libshabal.so HINTS "${CMAKE_SOURCE_DIR}/libShabal")
add_library(shabalLib STATIC IMPORTED)
set_property(TARGET shabalLib PROPERTY IMPORTED_LOCATION ${SHABAL_LIB})
target_link_libraries(creepMiner shabalLib)
target_link_libraries(creepMiner ${CONAN_LIBS})
if (NOT USE_CONAN)
find_package(Poco REQUIRED Foundation Util Net Crypto NetSSL)
target_link_libraries(creepMiner ${Poco_LIBRARIES})
endif()
if (USE_OPENCL)
target_link_libraries(creepMiner ${OpenCL_LIBRARY})
endif ()
##################################################################
# Naming
##################################################################
set_target_properties(creepMiner PROPERTIES DEBUG_POSTFIX -d)
##################################################################
# Installing
##################################################################
install(FILES src/shabal/opencl/mining.cl DESTINATION .)
install(DIRECTORY resources/public DESTINATION .)
if (NOT MSVC)
install(DIRECTORY bin/ DESTINATION . USE_SOURCE_PERMISSIONS)
install(FILES resources/run.sh resources/screen.sh DESTINATION . PERMISSIONS
OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_WRITE GROUP_EXECUTE
WORLD_READ WORLD_WRITE WORLD_EXECUTE)
if (UNIX)
install(DIRECTORY lib/ DESTINATION lib)
install(FILES libShabal/libshabal.so DESTINATION .)
elseif (APPLE)
install(FILES libShabal/libshabal.dylib DESTINATION .)
endif()
else ()
install(TARGETS creepMiner RUNTIME DESTINATION .)
install(FILES libShabal/shabal.dll DESTINATION .)
endif ()
##################################################################
# Packaging
##################################################################
if (USE_CUDA AND NOT MINIMAL_BUILD AND NOT NO_GPU)
set(PACKAGE_NAME ${CMAKE_PROJECT_NAME}-cuda)
elseif (USE_OPENCL AND NOT MINIMAL_BUILD AND NOT NO_GPU)
set(PACKAGE_NAME ${CMAKE_PROJECT_NAME}-opencl)
else ()
set(PACKAGE_NAME ${CMAKE_PROJECT_NAME})
endif ()
set(CPACK_PACKAGE_NAME ${PACKAGE_NAME})
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Burstcoin C++ CPU and GPU Miner")
set(CPACK_PACKAGE_VENDOR "Creepsky")
set(CPACK_PACKAGE_VERSION ${VERSION})
set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${VERSION_BUILD})
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.md")
SET(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
set(CPACK_SOURCE_PACKAGE_FILE ${PACKAGE_NAME})
#set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
if (UNIX OR APPLE)
set(CPACK_SET_DESTDIR true)
set(CPACK_INSTALL_PREFIX "/opt/${CMAKE_PROJECT_NAME}-${VERSION}")
set(CPACK_SOURCE_GENERATOR "TGZ;TBZ2")
set(CPACK_GENERATOR "TGZ")
set(CPACK_PACKAGE_SECTION "misc")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Creepsky")
include(CPack)
elseif (WIN32)
set(CPACK_GENERATOR "ZIP")
#set(CPACK_PACKAGE_ICON "${CMAKE_SOURCE_DIR}\\resources\\icon.ico")
#set(CPACK_NSIS_MUI_ICON "${CMAKE_SOURCE_DIR}\\resources\\icon.ico")
#set(CPACK_NSIS_MUI_UNIICON "${CMAKE_SOURCE_DIR}\\resources\\icon.ico")
set(CPACK_NSIS_MENU_LINKS "creepMiner.exe" "creepMiner")
include(CPack)
endif ()