-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathCMakeLists.txt
293 lines (264 loc) · 9.05 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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
cmake_policy(VERSION 3.0)
message(STATUS "Running CMake version ${CMAKE_VERSION}")
project(NiceHashQtMiner)
set(NHQTM_VERSION_MAJOR 0)
set(NHQTM_VERSION_MINOR 1)
set(NHQTM_VERSION_PATCH 2)
set(DEVELOPMENT_BUILD TRUE)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_VERBOSE_MAKEFILE FALSE)
option(WITH_DEBUG "With debug" ON)
option(SWITCH_TESTING "SWITCH_TESTING" OFF)
option(ENABLE_AMD "Enable AMD" ON)
option(ENABLE_NVIDIA "Enable NVIDIA" ON)
if (ENABLE_NVIDIA)
if (NOT DEFINED CUDA_TOOLKIT_ROOT_DIR)
if (DEFINED $ENV{CUDA_TOOLKIT_ROOT_DIR})
message("Using ENV[CUDA_TOOLKIT_ROOT_DIR]=$ENV{CUDA_TOOLKIT_ROOT_DIR}")
set(CUDA_TOOLKIT_ROOT_DIR $ENV{CUDA_TOOLKIT_ROOT_DIR})
else ()
set(CUDA_TOOLKIT_ROOT_DIR "/opt/cuda")
message("CUDA_TOOLKIT_ROOT_DIR set to ${CUDA_TOOLKIT_ROOT_DIR}")
endif ()
else ()
message("Using CUDA_TOOLKIT_ROOT_DIR=${CUDA_TOOLKIT_ROOT_DIR}")
endif ()
endif ()
if (DEFINED CMAKE_BUILD_TYPE AND NOT ${CMAKE_BUILD_TYPE} EQUAL "")
set(HAVE_CMAKE_BUILD_TYPE TRUE)
endif ()
set(CUSTOM_C_FLAGS $ENV{CFLAGS})
set(CUSTOM_CXX_FLAGS $ENV{CXXFLAGS})
get_filename_component(ROOT_DIR ${CMAKE_SOURCE_DIR} REALPATH CACHE)
set(SOURCE_DIR ${ROOT_DIR}/src)
set(INCLUDE_DIR ${ROOT_DIR}/include)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${ROOT_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${ROOT_DIR}/bin)
#SET(CMAKE_SKIP_BUILD_RPATH FALSE)
#SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
#set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
# for all binaries created in a CMake project:
#SET(CMAKE_INSTALL_RPATH "$ORIGIN/../lib:$ORIGIN/")
#set(CMAKE_INSTALL_RPATH "${ROOT_DIR}/lib")
#SET(CMAKE_INSTALL_RPATH "\$ORIGIN:\$ORIGIN/lib:\$ORIGIN/../lib")
#SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
#LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
#if ("${isSystemDir}" STREQUAL "-1")
# SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
#endif ()
# Arch
if (NOT DEFINED ${NHQTM_ARCH})
if (CMAKE_SIZEOF_VOID_P MATCHES "8")
SET(NHQTM_ARCH "x86_64" CACHE STRING "ARCH")
elseif (CMAKE_SIZEOF_VOID_P MATCHES "4")
SET(NHQTM_ARCH "x86" CACHE STRING "ARCH")
else ()
SET(NHQTM_ARCH "x86_64" CACHE STRING "ARCH")
MESSAGE(WARNING "Could not define ARCH, using ${NHQTM_ARCH}.")
endif ()
elseif (NOT NHQTM_ARCH MATCHES "x86_64" AND NOT NHQTM_ARCH MATCHES "x86")
MESSAGE(FATAL_ERROR "Invalid NHQTM_ARCH (${NHQTM_ARCH}), use x86_64 or x86")
endif ()
if (UNIX AND CMAKE_SYSTEM_NAME MATCHES Linux)
set(LINUX true)
endif ()
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules")
include(cmake/Macros.cmake)
include(CheckInSourceBuild)
#include(CheckFunctionExists)
include(CheckIncludeFile)
include(CheckLibraryExists)
include(cmake/util.cmake)
set(BUILDTYPE_DOCSTRING
"Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel"
)
if (WITH_DEBUG OR DEVELOPMENT_BUILD)
if (HAVE_CMAKE_BUILD_TYPE)
if (CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")
message(WARNING "WITH_DEBUG and DEVELOPMENT_BUILD are in conflict with CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}, disabling Debug/Dev")
set(WITH_DEBUG FALSE)
set(DEVELOPMENT_BUILD FALSE)
elseif (CMAKE_BUILD_TYPE STREQUAL "Release")
message(WARNING "WITH_DEBUG or DEVELOPMENT_BUILD set to TRUE are in conflict with CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}, updating CMAKE_BUILD_TYPE to RelWithDebInfo")
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING ${BUILDTYPE_DOCSTRING} FORCE)
endif ()
else ()
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING ${BUILDTYPE_DOCSTRING} FORCE)
endif ()
elseif (NOT HAVE_CMAKE_BUILD_TYPE)
if (CUSTOM_C_FLAGS)
set(CMAKE_BUILD_TYPE "" CACHE STRING ${BUILDTYPE_DOCSTRING} FORCE)
elseif (CMAKE_BUILDTYPE_ MATCHES "Debug" OR NOT HAVE_CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING ${BUILDTYPE_DOCSTRING} FORCE)
endif ()
endif ()
include(cmake/CommonCompilerFlags.cmake)
check_include_file(stdint.h HAVE_STDINT_H)
if(false)
find_package(OpenSSL 0.9.9 REQUIRED)
if (OPENSSL_FOUND)
list(APPEND CRYPTO_LIBRARIES ${OPENSSL_LIBRARIES})
include(cmake/Modules/CheckOpenSSL.cmake)
check_function_exists(SHA256_Update HAVE_SHA256_UPDATE)
endif ()
endif(false)
find_package(Threads REQUIRED)
set(WITH_AMD FALSE)
if (ENABLE_AMD)
find_package(OpenCL 1.2 REQUIRED)
#MESSAGE( STATUS "OPENCL_INCLUDE_DIRS=${OPENCL_INCLUDE_DIRS}" )
#if (NOT OPENCL_HAS_CXX)
# message(WARNING "C++ bindings not found. Using Kronos supplied reference OpenCL v1.1 C++ bindings.")
# list(APPEND OPENCL_INCLUDE_DIRS ${viscl_SOURCE_DIR}/kronos)
#endif ()
#include_directories(SYSTEM ${OPENCL_INCLUDE_DIRS})
#add_definitions(${OPENCL_CXX_DEFINITIONS})
# foreach (lib ${OPENCL_LIBRARIES})
# get_filename_component(fname ${lib} NAME)
# get_filename_component(rpath ${lib} REALPATH)
# get_filename_component(rfname ${rpath} NAME)
# message("Copying ${lib} to ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
# file(COPY ${rpath}
# DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
# )
# file(RENAME "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${rfname}" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${fname}")
# endforeach ()
# check_library_exists(atiadlxx ADL_MAIN_CONTROL_CREATE "" HAVE_LIBADL)
if (OPENCL_FOUND)
set(WITH_AMD true)
endif ()
# check_library_exists(atiadlxx ADL_MAIN_CONTROL_CREATE "" HAVE_LIBADL)
find_package(ADL)
endif ()
set(WITH_NVIDIA FALSE)
if (ENABLE_NVIDIA)
# include(cmake/Modules/FindCUDA.cmake)
find_package(CUDA 8.0)
find_package(NVML)
# find_package(NVCtrlLib)
if (CUDA_FOUND AND NVML_FOUND)
set(WITH_NVIDIA true)
endif ()
if (CUDA_FOUND AND false)
set(WITH_CUDA TRUE)
find_library(NVML_LIBRARY
NAMES
nvidia-ml
# libnvidia-ml
# libnvidia-ml.so
HINTS
${CUDA_TOOLKIT_ROOT_DIR}
PATH_SUFFIXES
/lib
/lib64
/lib/stubs
/lib64/stubs
)
if (NVML_LIBRARY)
get_filename_component(fname ${NVML_LIBRARY} NAME)
get_filename_component(rpath ${NVML_LIBRARY} REALPATH)
get_filename_component(rfname ${rpath} NAME)
message("Copying ${NVML_LIBRARY} to ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
file(COPY ${rpath}
DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
)
file(RENAME "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${rfname}" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${fname}")
endif ()
endif ()
endif ()
check_library_exists(cpuid cpuid_present "" HAVE_LIBCPUID)
if (HAVE_LIBCPUID)
list(APPEND HW_LIBRARIES cpuid)
endif ()
check_library_exists(hd hd_list "" HAVE_LIBHD)
if (HAVE_LIBHD)
list(APPEND HW_LIBRARIES hd)
endif ()
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBXSS xscrnsaver)
find_package(Qt5 5.12
COMPONENTS
Core
Gui
Widgets
Network
WebSockets
Concurrent
Sql
REQUIRED
)
find_library(DL_LIBRARY
NAMES dl
)
find_library(LOG4_LIBRARY
log4qt
)
configure_file(
${ROOT_DIR}/cmake/config.h.in
${INCLUDE_DIR}/config.h
)
set_source_files_properties(${INCLUDE_DIR}/config.h PROPERTIES GENERATED 1)
list(APPEND ADDITIONAL_MAKE_CLEAN_FILES ${INCLUDE_DIR}/config.h)
include(cmake/Version.cmake)
set_source_files_properties(${INCLUDE_DIR}/version.h PROPERTIES GENERATED 1)
list(APPEND ADDITIONAL_MAKE_CLEAN_FILES ${INCLUDE_DIR}/version.h)
if (ENABLE_STRIP OR CMAKE_BUILD_TYPE MATCHES "MinSizeRel")
if (CMAKE_BUILD_TYPE MATCHES "Debug" OR CMAKE_BUILD_TYPE MATCHES "RelWithDebInfo")
message(WARNING "ENABLE_STRIP & CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} are in conflict, ENABLE_STRIP ignored")
elseif (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_GNUC)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s")
endif ()
endif ()
if (ENABLE_MULTIBUILD)
if (WIN32 AND MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
message(STATUS "Added parallel build arguments to CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
endif ()
endif ()
include_directories(include)
set(SUBDIRS
3rdparty
tools
NiceHashQtMiner
)
foreach (subdir ${SUBDIRS})
add_subdirectory(${subdir})
endforeach ()
add_custom_target(
permission chown root NiceHashQtMiner
COMMAND chmod u+s NiceHashQtMiner
)
message("${PROJECT_NAME} ${PROJECT_VERSION}\n")
if (WIN32 AND MSVC)
message("Platform: Windows (MSVC)")
elseif (WIN32 AND MINGW)
message("Platform: Windows (MinGW)")
elseif (WIN32)
message("Platform: Windows (Other)")
elseif (LINUX)
message("Platform: Linux")
else ()
message("Platform: Other/No platform code")
endif ()
message("System : ${CMAKE_SYSTEM}")
message(" Arch: ${NHQTM_ARCH}
compiler | ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}
cxxflags | ${CMAKE_CXX_FLAGS}
builddir | ${CMAKE_BINARY_DIR}
buildtype | ${CMAKE_BUILD_TYPE}
Building with support for:")
show_end_message_yesno("Debug" WITH_DEBUG)
show_end_message_yesno(" - SWITCH_TESTING" SWITCH_TESTING)
show_end_message_yesno("AMD" WITH_AMD)
show_end_message_yesno(" - OPENCL" OPENCL_FOUND)
#show_end_message_yesno(" - ADL" ADL_FOUND)
show_end_message(" - ADL" "")
show_end_message_yesno(" - FOUND" ADL_FOUND)
show_end_message_yesno(" - LIBWORKS" ADL_LIBWORKS)
show_end_message_yesno("NVIDIA" WITH_NVIDIA)
show_end_message_yesno(" - CUDA" CUDA_FOUND)
show_end_message_yesno(" - NVML" NVML_FOUND)
#show_end_message_yesno(" - NVCtrlLib" NVCtrlLib_FOUND)
show_end_message_yesno("SCRNSAVER" LIBXSS_FOUND)
install(SCRIPT chown.cmake)