aboutsummaryrefslogtreecommitdiff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt107
1 files changed, 61 insertions, 46 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 78e4b426f..ebca5c6fb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -28,33 +28,41 @@
#
# Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
-cmake_minimum_required(VERSION 2.8.6)
+cmake_minimum_required(VERSION 2.8.7)
-if(NOT WIN32)
- string(ASCII 27 Esc)
- set(ColourReset "${Esc}[m")
- set(BoldRed "${Esc}[1;31m")
-endif()
+project(bitmonero)
+
+function (die msg)
+ if (NOT WIN32)
+ string(ASCII 27 Esc)
+ set(ColourReset "${Esc}[m")
+ set(BoldRed "${Esc}[1;31m")
+ else ()
+ set(ColourReset "")
+ set(BoldRed "")
+ endif ()
-set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
+ message(FATAL_ERROR "${BoldRed}${msg}${ColourReset}")
+endfunction ()
+
+list(INSERT CMAKE_MODULE_PATH 0
+ "${CMAKE_SOURCE_DIR}/cmake")
if (NOT DEFINED ENV{DEVELOPER_LOCAL_TOOLS})
- message(STATUS "Could not find DEVELOPER_LOCAL_TOOLS in env (not required)")
- set(BOOST_IGNORE_SYSTEM_PATHS_DEFAULT OFF)
-elseif ("$ENV{DEVELOPER_LOCAL_TOOLS}" EQUAL 1)
- message(STATUS "Found: env DEVELOPER_LOCAL_TOOLS = 1")
- set(BOOST_IGNORE_SYSTEM_PATHS_DEFAULT ON)
- option(BOOST_IGNORE_SYSTEM_PATHS "Ignore boost system paths for local boost installation" ON)
+ message(STATUS "Could not find DEVELOPER_LOCAL_TOOLS in env (not required)")
+ set(BOOST_IGNORE_SYSTEM_PATHS_DEFAULT OFF)
+elseif (ENV{DEVELOPER_LOCAL_TOOLS} EQUAL 1)
+ message(STATUS "Found: env DEVELOPER_LOCAL_TOOLS = 1")
+ set(BOOST_IGNORE_SYSTEM_PATHS_DEFAULT ON)
else()
- message(STATUS "found: env DEVELOPER_LOCAL_TOOLS = 0")
- set(BOOST_IGNORE_SYSTEM_PATHS_DEFAULT OFF)
+ message(STATUS "Found: env DEVELOPER_LOCAL_TOOLS = 0")
+ set(BOOST_IGNORE_SYSTEM_PATHS_DEFAULT OFF)
endif()
message(STATUS "BOOST_IGNORE_SYSTEM_PATHS defaults to ${BOOST_IGNORE_SYSTEM_PATHS_DEFAULT}")
-option(BOOST_IGNORE_SYSTEM_PATHS "Ignore boost system paths for local boost ins tallation" $BOOST_IGNORE_SYSTEM_PATHS_DEFAULT)
+option(BOOST_IGNORE_SYSTEM_PATHS "Ignore boost system paths for local boost installation" ${BOOST_IGNORE_SYSTEM_PATHS_DEFAULT})
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
-set(CMAKE_CONFIGURATION_TYPES "Debug;Release")
enable_testing()
# Check if we're on FreeBSD so we can exclude the local miniupnpc (it should be installed from ports instead)
@@ -85,15 +93,28 @@ if(MSVC OR MINGW)
else()
set(DEFAULT_STATIC false)
endif()
-set(STATIC ${DEFAULT_STATIC} CACHE BOOL "Link libraries statically")
+option(STATIC "Link libraries statically" ${DEFAULT_STATIC})
-IF(STATIC)
- IF(MSVC)
- SET(CMAKE_FIND_LIBRARY_SUFFIXES .lib .dll.a .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
- ELSE()
- SET(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
- ENDIF()
-ENDIF()
+if(MINGW)
+ get_filename_component(msys2_install_path "[HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MSYS2 64bit;InstallLocation]" ABSOLUTE)
+ set(CMAKE_INCLUDE_PATH "${msys2_install_path}/mingw64/include")
+ # This is necessary because otherwise CMake will make Boost libraries -lfoo
+ # rather than a full path. Unfortunately, this makes the shared libraries get
+ # linked due to a bug in CMake which misses putting -static flags around the
+ # -lfoo arguments.
+ list(REMOVE_ITEM CMAKE_C_IMPLICIT_LINK_DIRECTORIES
+ "${msys2_install_path}/mingw64/lib")
+ list(REMOVE_ITEM CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES
+ "${msys2_install_path}/mingw64/lib")
+endif()
+
+if(STATIC)
+ if(MSVC)
+ set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .dll.a .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
+ else()
+ set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
+ endif()
+endif()
if (UNIX AND NOT APPLE)
# Note that at the time of this writing the -Wstrict-prototypes flag added below will make this fail
@@ -112,6 +133,7 @@ endif()
# Final setup for libunbound
include_directories(${UNBOUND_INCLUDE})
+link_directories(${UNBOUND_LIBRARY_DIRS})
if(MSVC)
add_definitions("/bigobj /MP /W3 /GS- /D_CRT_SECURE_NO_WARNINGS /wd4996 /wd4345 /D_WIN32_WINNT=0x0600 /DWIN32_LEAN_AND_MEAN /DGTEST_HAS_TR1_TUPLE=0 /FIinline_c.h /D__SSE4_1__")
@@ -125,12 +147,15 @@ if(MSVC)
include_directories(SYSTEM src/platform/msc)
else()
set(ARCH native CACHE STRING "CPU to build for: -march value or default")
- if("${ARCH}" STREQUAL "default")
+ if(ARCH STREQUAL "default")
set(ARCH_FLAG "")
else()
set(ARCH_FLAG "-march=${ARCH}")
endif()
- set(WARNINGS "-Wall -Wextra -Wpointer-arith -Wundef -Wvla -Wwrite-strings -Werror -Wno-error=extra -Wno-error=deprecated-declarations -Wno-error=sign-compare -Wno-error=strict-aliasing -Wno-error=type-limits -Wno-unused-parameter -Wno-error=unused-variable -Wno-error=undef -Wno-error=uninitialized")
+ set(WARNINGS "-Wall -Wextra -Wpointer-arith -Wundef -Wvla -Wwrite-strings -Wno-error=extra -Wno-error=deprecated-declarations -Wno-error=sign-compare -Wno-error=strict-aliasing -Wno-error=type-limits -Wno-unused-parameter -Wno-error=unused-variable -Wno-error=undef -Wno-error=uninitialized")
+ if(NOT MINGW)
+ set(WARNINGS "${WARNINGS} -Werror")
+ endif()
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
set(WARNINGS "${WARNINGS} -Wno-error=mismatched-tags -Wno-error=null-conversion -Wno-overloaded-shift-op-parentheses -Wno-error=shift-count-overflow -Wno-error=tautological-constant-out-of-range-compare -Wno-error=unused-private-field -Wno-error=unneeded-internal-declaration")
else()
@@ -141,6 +166,8 @@ else()
set(MINGW_FLAG "${MINGW_FLAG} -DWIN32_LEAN_AND_MEAN")
set(Boost_THREADAPI win32)
include_directories(SYSTEM src/platform/mingw)
+ # mingw doesn't support LTO (multiple definition errors at link time)
+ set(USE_LTO_DEFAULT false)
endif()
set(C_WARNINGS "-Waggregate-return -Wnested-externs -Wold-style-definition -Wstrict-prototypes")
set(CXX_WARNINGS "-Wno-reorder -Wno-missing-field-initializers")
@@ -170,7 +197,7 @@ else()
# There is a clang bug that does not allow to compile code that uses AES-NI intrinsics if -flto is enabled, so explicitly disable
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
- set(USE_LTO false)
+ set(USE_LTO false)
endif()
if(USE_LTO)
set(RELEASE_FLAGS "${RELEASE_FLAGS} -flto")
@@ -194,7 +221,7 @@ else()
endif()
if (BOOST_IGNORE_SYSTEM_PATHS)
- set(Boost_NO_SYSTEM_PATHS TRUE)
+ set(Boost_NO_SYSTEM_PATHS TRUE)
endif()
if(STATIC)
@@ -204,36 +231,24 @@ endif()
find_package(Boost 1.53 QUIET REQUIRED COMPONENTS system filesystem thread date_time chrono regex serialization program_options)
if(NOT Boost_FOUND)
- MESSAGE(FATAL_ERROR "${BoldRed}Could not find Boost libraries, please make sure you have installed Boost or libboost-all-dev (1.53 or 1.55+) or the equivalent${ColourReset}")
+ die("Could not find Boost libraries, please make sure you have installed Boost or libboost-all-dev (1.53 or 1.55+) or the equivalent")
endif()
-if((${Boost_MAJOR_VERSION} EQUAL 1) AND (${Boost_MINOR_VERSION} EQUAL 54))
- message(FATAL_ERROR "${BoldRed}Boost version 1.54 is unsupported due to a bug (see: http://goo.gl/RrCFmA), please install Boost 1.53 or 1.55 and above${ColourReset}")
+if((Boost_MAJOR_VERSION EQUAL 1) AND (Boost_MINOR_VERSION EQUAL 54))
+ die("Boost version 1.54 is unsupported due to a bug (see: http://goo.gl/RrCFmA), please install Boost 1.53 or 1.55 and above")
endif()
include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
if(MINGW)
- set(EXTRA_LIBRARIES pthread;mswsock;ws2_32)
+ set(EXTRA_LIBRARIES mswsock;ws2_32;iphlpapi)
elseif(APPLE OR FREEBSD)
set(EXTRA_LIBRARIES "")
elseif(NOT MSVC)
find_library(RT rt)
- find_library(PTHREAD pthread)
- find_library(DL dl)
set(EXTRA_LIBRARIES ${RT} ${PTHREAD} ${DL})
endif()
-file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/version")
-find_package(Git QUIET)
-if(Git_FOUND OR GIT_FOUND)
- message(STATUS "Found Git: ${GIT_EXECUTABLE}")
- add_custom_target(version ALL "${CMAKE_COMMAND}" "-D" "GIT=${GIT_EXECUTABLE}" "-D" "TO=${CMAKE_BINARY_DIR}/version/version.h" "-P" "src/version.cmake" WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
-else()
- message(STATUS "WARNING: Git was not found!")
- set(VERSIONTAG "unknown")
- configure_file("src/version.h.in" "version/version.h")
- add_custom_target(version ALL)
-endif()
+include(version.cmake)
add_subdirectory(src)
add_subdirectory(tests)