Skip to content

Commit

Permalink
fix Linux build, one cmake file (TODO make shared lib all in one build)
Browse files Browse the repository at this point in the history
  • Loading branch information
S74nk0 committed Jan 12, 2017
1 parent d56e5e8 commit af3a5c4
Show file tree
Hide file tree
Showing 50 changed files with 2,147 additions and 1,575 deletions.
198 changes: 198 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
project(nheqminer)
cmake_minimum_required(VERSION 3.5)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") # -Wall

## Enable solvers here
#### older slower
option(USE_CPU_TROMP "USE CPU_TROMP" OFF)
option(USE_CUDA_TROMP "USE CUDA_TROMP" OFF)
#### faster
option(USE_CPU_XENONCAT "USE CPU_XENONCAT" ON)
option(USE_CUDA_DJEZO "USE CUDA_DJEZO" ON)

## Add solvers here
if (USE_CPU_TROMP)
add_definitions(-DUSE_CPU_TROMP)
message("-- USE_CPU_TROMP DEFINED")
endif()
if (USE_CPU_XENONCAT)
add_definitions(-DUSE_CPU_XENONCAT)
message("-- USE_CPU_XENONCAT DEFINED")
endif()
if (USE_CUDA_TROMP)
add_definitions(-DUSE_CUDA_TROMP)
message("-- USE_CUDA_TROMP DEFINED")
endif()
if (USE_CUDA_DJEZO)
add_definitions(-DUSE_CUDA_DJEZO)
message("-- USE_CUDA_DJEZO DEFINED")
endif()


########
# LINUX
if(CMAKE_COMPILER_IS_GNUCXX)
# # use native cpu features
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native -fPIC")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -fPIC")

# # optimizations
# add_definitions(-O3)

# use
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m64 -msse2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64 -msse2")
# optimizations
add_definitions(-O2)
endif()

# Common
include_directories(${nheqminer_SOURCE_DIR}/nheqminer)

# BOOST
#find_package(Threads REQUIRED COMPONENTS)
# compile boost staticaly
set(Boost_USE_STATIC_LIBS ON)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
#set(BUILD_SHARED_LIBRARIES OFF)
#set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -static")
find_package(Boost REQUIRED COMPONENTS system log_setup log date_time filesystem thread)

if (Boost_FOUND)
# From the offical documentation:
# Add include directories to the build. [...] If the SYSTEM option is given,
# the compiler will be told the directories are meant as system include
# directories on some platforms (signalling this setting might achieve effects
# such as the compiler skipping warnings [...])."
include_directories (SYSTEM ${Boost_INCLUDE_DIR})

# From the offical documentation:
# "Specify directories in which the linker will look for libraries. [...] Note
# that this command is rarely necessary. Library locations returned by
# find_package() and find_library() are absolute paths. Pass these absolute
# library file paths directly to the target_link_libraries() command. CMake
# will ensure the linker finds them."
link_directories (${Boost_LIBRARY_DIRS})
else()
message("Boost_FOUND NOT FOUND")
endif ()

include_directories(${CMAKE_CURRENT_BINARY_DIR}/../)

set(SOURCE_FILES
# sources
nheqminer/amount.cpp
nheqminer/api.cpp
nheqminer/arith_uint256.cpp
nheqminer/crypto/sha256.cpp
nheqminer/json/json_spirit_reader.cpp
nheqminer/json/json_spirit_value.cpp
nheqminer/json/json_spirit_writer.cpp
nheqminer/libstratum/ZcashStratum.cpp
nheqminer/main.cpp
nheqminer/primitives/block.cpp
nheqminer/speed.cpp
nheqminer/uint256.cpp
nheqminer/utilstrencodings.cpp
# headers
nheqminer/amount.h
nheqminer/api.hpp
nheqminer/arith_uint256.h
nheqminer/crypto/sha256.h
nheqminer/hash.h
nheqminer/json/json_spirit.h
nheqminer/json/json_spirit_error_position.h
nheqminer/json/json_spirit_reader.h
nheqminer/json/json_spirit_reader_template.h
nheqminer/json/json_spirit_stream_reader.h
nheqminer/json/json_spirit_utils.h
nheqminer/json/json_spirit_value.h
nheqminer/json/json_spirit_writer.h
nheqminer/json/json_spirit_writer_template.h
nheqminer/libstratum/StratumClient.cpp
nheqminer/libstratum/StratumClient.h
nheqminer/libstratum/ZcashStratum.cpp
nheqminer/libstratum/ZcashStratum.h
nheqminer/primitives/block.h
nheqminer/primitives/transaction.h
nheqminer/script/script.h
nheqminer/serialize.h
nheqminer/speed.hpp
nheqminer/streams.h
nheqminer/support/allocators/zeroafterfree.h
nheqminer/tinyformat.h
nheqminer/uint252.h
nheqminer/uint256.h
nheqminer/utilstrencodings.h
nheqminer/version.h
nheqminer/zcash/JoinSplit.hpp
nheqminer/zcash/NoteEncryption.hpp
nheqminer/zcash/Proof.hpp
nheqminer/zcash/Zcash.h
nheqminer/SolverStub.h # just a stub

nheqminer/AvailableSolvers.h
nheqminer/ISolver.h
nheqminer/Solver.h
nheqminer/MinerFactory.h
nheqminer/MinerFactory.cpp

# make same path on windows
#blake shared
# src
blake2/blake2bx.cpp
# headers
blake2/blake2.h
blake2/blake2b-load-sse2.h
blake2/blake2b-load-sse41.h
blake2/blake2b-round.h
blake2/blake2-config.h
blake2/blake2-impl.h
blake2/blake2-round.h
)

#set(LIBS ${LIBS} ${Threads_LIBRARIES} ${Boost_LIBRARIES})
set(LIBS ${LIBS} ${Boost_LIBRARIES})

message("-- CXXFLAGS: ${CMAKE_CXX_FLAGS}")
message("-- LIBS: ${LIBS}")

if (USE_CPU_TROMP)
add_subdirectory(cpu_tromp)
endif()
if (USE_CPU_XENONCAT)
add_subdirectory(cpu_xenoncat)
endif()
if (USE_CUDA_TROMP)
add_subdirectory(cuda_tromp)
endif()
if (USE_CUDA_DJEZO)
add_subdirectory(cuda_djezo)
endif()

#add_subdirectory(cpu_xenoncat)

ADD_EXECUTABLE(${PROJECT_NAME} ${SOURCE_FILES})

#target_link_libraries(${PROJECT_NAME} ${LIBS} ${CUDA_LIBRARIES} )
target_link_libraries(${PROJECT_NAME} ${CMAKE_THREAD_LIBS_INIT} ${LIBS} )

# link libs
if (USE_CPU_TROMP)
target_link_libraries(${PROJECT_NAME} cpu_tromp)
endif()
if (USE_CPU_XENONCAT)
add_library ( xenoncat_avx1 SHARED IMPORTED GLOBAL )
set_target_properties ( xenoncat_avx1 PROPERTIES IMPORTED_LOCATION "../nheqminer/cpu_xenoncat/asm_linux/equihash_avx1.o" )
add_library ( xenoncat_avx2 SHARED IMPORTED GLOBAL )
set_target_properties ( xenoncat_avx2 PROPERTIES IMPORTED_LOCATION "../nheqminer/cpu_xenoncat/asm_linux/equihash_avx2.o" )
target_link_libraries(${PROJECT_NAME} cpu_xenoncat xenoncat_avx1 xenoncat_avx2)
endif()
if (USE_CUDA_TROMP)
target_link_libraries(${PROJECT_NAME} cuda_tromp)
endif()
if (USE_CUDA_DJEZO)
target_link_libraries(${PROJECT_NAME} cuda_djezo)
endif()

58 changes: 25 additions & 33 deletions Linux_cmake/nheqminer_cuda_tromp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,7 @@ endif()
# Common
include_directories(${nheqminer_SOURCE_DIR})

#add_definitions(-DBOOST_ALL_NO_LIB -DBOOST_ALL_DYN_LINK -DBOOST_LOG_DYN_LINK)
# BOOST
#find_package(Threads REQUIRED COMPONENTS)
# compile boost staticaly
set(Boost_USE_STATIC_LIBS ON)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
#set(BUILD_SHARED_LIBRARIES OFF)
#set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -static")
find_package(Boost REQUIRED COMPONENTS system log_setup log date_time filesystem thread)

if (Boost_FOUND)
# From the offical documentation:
# Add include directories to the build. [...] If the SYSTEM option is given,
# the compiler will be told the directories are meant as system include
# directories on some platforms (signalling this setting might achieve effects
# such as the compiler skipping warnings [...])."
include_directories (SYSTEM ${Boost_INCLUDE_DIR})

# From the offical documentation:
# "Specify directories in which the linker will look for libraries. [...] Note
# that this command is rarely necessary. Library locations returned by
# find_package() and find_library() are absolute paths. Pass these absolute
# library file paths directly to the target_link_libraries() command. CMake
# will ensure the linker finds them."
link_directories (${Boost_LIBRARY_DIRS})
else()
message("Boost_FOUND NOT FOUND")
endif ()
add_definitions(-DBOOST_ALL_NO_LIB -DBOOST_ALL_DYN_LINK -DBOOST_LOG_DYN_LINK)

#set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};-m64;--std=c++11;--disable-warnings;--ptxas-options=-v;-use_fast_math;-lineinfo)

Expand Down Expand Up @@ -75,6 +48,25 @@ else()
message("CUDA NOT FOUND")
endif()

if (Boost_FOUND)
# From the offical documentation:
# Add include directories to the build. [...] If the SYSTEM option is given,
# the compiler will be told the directories are meant as system include
# directories on some platforms (signalling this setting might achieve effects
# such as the compiler skipping warnings [...])."
include_directories (SYSTEM ${Boost_INCLUDE_DIR})

# From the offical documentation:
# "Specify directories in which the linker will look for libraries. [...] Note
# that this command is rarely necessary. Library locations returned by
# find_package() and find_library() are absolute paths. Pass these absolute
# library file paths directly to the target_link_libraries() command. CMake
# will ensure the linker finds them."
link_directories (${Boost_LIBRARY_DIRS})
else()
message("Boost_FOUND NOT FOUND")
endif ()

## Add solvers here
#add_definitions(-DUSE_CPU_XENONCAT)
#add_definitions(-DUSE_CPU_TROMP)
Expand Down Expand Up @@ -141,11 +133,11 @@ set(SOURCE_FILES
../../nheqminer/SolverStub.h # just a stub


../../nheqminer/AvailableSolvers.h
../../nheqminer/ISolver.h
../../nheqminer/Solver.h
../../nheqminer/MinerFactory.h
../../nheqminer/MinerFactory.cpp
../../nheqminer/AvailableSolvers.h
../../nheqminer/ISolver.h
../../nheqminer/Solver.h
../../nheqminer/MinerFactory.h
../../nheqminer/MinerFactory.cpp

# # cpu tromp
# ../../cpu_tromp/blake2/blake2bx.cpp
Expand Down
72 changes: 72 additions & 0 deletions blake2/blake2-config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
BLAKE2 reference source code package - optimized C implementations
Written in 2012 by Samuel Neves <[email protected]>
To the extent possible under law, the author(s) have dedicated all copyright
and related and neighboring rights to this software to the public domain
worldwide. This software is distributed without any warranty.
You should have received a copy of the CC0 Public Domain Dedication along with
this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
#pragma once
#ifndef __BLAKE2_CONFIG_H__
#define __BLAKE2_CONFIG_H__

// These don't work everywhere
#if (defined(__SSE2__) || defined(_M_AMD_64) || defined(_M_X64))
#define HAVE_SSE2
#endif

#if defined(__SSSE3__)
#define HAVE_SSSE3
#endif

#if defined(__SSE4_1__)
#define HAVE_SSE41
#endif

#if defined(__AVX__)
#define HAVE_AVX
#endif

#if defined(__XOP__)
#define HAVE_XOP
#endif


#ifdef HAVE_AVX2
#ifndef HAVE_AVX
#define HAVE_AVX
#endif
#endif

#ifdef HAVE_XOP
#ifndef HAVE_AVX
#define HAVE_AVX
#endif
#endif

#ifdef HAVE_AVX
#ifndef HAVE_SSE41
#define HAVE_SSE41
#endif
#endif

#ifdef HAVE_SSE41
#ifndef HAVE_SSSE3
#define HAVE_SSSE3
#endif
#endif

#ifdef HAVE_SSSE3
#define HAVE_SSE2
#endif

#if !defined(HAVE_SSE2)
#error "This code requires at least SSE2."
#endif

#endif

Loading

0 comments on commit af3a5c4

Please sign in to comment.