diff options
author | psychocrypt <psychocrypt@users.noreply.github.com> | 2017-04-12 21:15:36 +0200 |
---|---|---|
committer | psychocrypt <psychocrypt@users.noreply.github.com> | 2017-04-12 21:15:36 +0200 |
commit | a8d40d15fd9c52fd69a330fb0a5b1b55eeb45102 (patch) | |
tree | c1ec16cbaec792b722080c497674af307431c1e3 /CMakeLists.txt | |
parent | 00568d05e383ad14fee881539f171e00b10adf46 (diff) | |
download | xmr-stak-a8d40d15fd9c52fd69a330fb0a5b1b55eeb45102.zip xmr-stak-a8d40d15fd9c52fd69a330fb0a5b1b55eeb45102.tar.gz |
refactor CMake
- allow compiling without microhttpd
- allow compiling without OpenSSL
- install `config.txt` with command `make install`
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r-- | CMakeLists.txt | 104 |
1 files changed, 87 insertions, 17 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 85249c4..49b7065 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,38 +1,108 @@ project(xmr-stak-cpu) -cmake_minimum_required(VERSION 2.8.10) +cmake_minimum_required(VERSION 3.0.1) +# enforce C++11 +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) +set(CMAKE_CXX_STANDARD 11) + +if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}" CACHE PATH "install prefix" FORCE) +endif(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + +# allow user to extent CMAKE_PREFIX_PATH via environment variable +list(APPEND CMAKE_PREFIX_PATH "$ENV{CMAKE_PREFIX_PATH}") + +################################################################################ +# CMake user options +################################################################################ + +# gcc 5.1 is the first GNU version without CoW strings +# https://github.com/fireice-uk/xmr-stak-nvidia/pull/10#issuecomment-290821792 +# If you remove this guard to compile with older gcc versions the miner will produce +# a high rate of wrong shares. if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.1) + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.1) message(FATAL_ERROR "GCC version must be at least 5.1!") endif() endif() +set(BUILD_TYPE "Release;Debug") +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build" FORCE) +endif() +set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "${BUILD_TYPE}") + +################################################################################ +# Find PThreads +################################################################################ + +find_package(Threads REQUIRED) +set(LIBS ${LIBS} ${CMAKE_THREAD_LIBS_INIT}) + +################################################################################ +# Find microhttpd +################################################################################ + find_library(MHTD NAMES microhttpd) if("${MHTD}" STREQUAL "MHTD-NOTFOUND") - message(FATAL_ERROR "libmicrohttpd is required") + message(STATUS "microhttpd NOT found: disable http server") + add_definitions("-DCONF_NO_HTTPD") +else() + set(LIBS ${LIBS} ${MHTD}) endif() -find_package(OpenSSL REQUIRED) -include_directories(${OPENSSL_INCLUDE_DIR}) +############################################################################### +# Find OpenSSL +############################################################################### -#set(CMAKE_VERBOSE_MAKEFILE ON) -set(CMAKE_CONFIGURATION_TYPES "RELEASE;STATIC") -if("${CMAKE_BUILD_TYPE}" STREQUAL "") - set(CMAKE_BUILD_TYPE RELEASE) +find_package(OpenSSL) +include_directories(${OPENSSL_INCLUDE_DIR}) +set(LIBS ${LIBS} ${OPENSSL_LIBRARIES}) +if(NOT OPENSSL_FOUND) + add_definitions("-DCONF_NO_TLS") endif() -set(CMAKE_C_FLAGS "-DNDEBUG -march=westmere -O3 -m64 -s") -set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=c++11") +################################################################################ +# Compile & Link +################################################################################ + +# activate sse2 and aes-ni +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2 -maes") -set(CMAKE_EXE_LINKER_FLAGS_RELSEASE "") -set(CMAKE_EXE_LINKER_FLAGS_STATIC "-static-libgcc -static-libstdc++") +file(GLOB SRCFILES_CPP "*.cpp" "crypto/*.cpp") +file(GLOB SRCFILES_C "crypto/*.c") + +add_library(xmr-stak-c + STATIC + ${SRCFILES_C} +) +set_property(TARGET xmr-stak-c PROPERTY C_STANDARD 99) + +add_executable(xmr-stak-cpu + ${SRCFILES_CPP} +) set(EXECUTABLE_OUTPUT_PATH "bin") +target_link_libraries(xmr-stak-cpu xmr-stak-c ${LIBS}) -file(GLOB SOURCES "crypto/*.c" "crypto/*.cpp" "*.cpp") +################################################################################ +# Install +################################################################################ + +# do not install the binary if the project and install are equal +if( NOT "${CMAKE_INSTALL_PREFIX}" STREQUAL "${PROJECT_BINARY_DIR}" ) + install(TARGETS xmr-stak-amd + RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/bin") +endif() -add_executable(xmr-stak-cpu ${SOURCES}) -target_link_libraries(xmr-stak-cpu pthread microhttpd crypto ssl) - +# avoid overwrite of user defined settings +# install `config.txt`if file not exists in `${CMAKE_INSTALL_PREFIX}/bin` +install(CODE " \ + if(NOT EXISTS ${CMAKE_INSTALL_PREFIX}/bin/config.txt)\n \ + file(INSTALL ${CMAKE_CURRENT_SOURCE_DIR}/config.txt \ + DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)\n \ + endif()" +) |