aboutsummaryrefslogtreecommitdiff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2014-11-25 21:48:54 +0200
committerRiccardo Spagni <ric@spagni.net>2014-11-25 21:49:00 +0200
commitab7c6c07e71c025a978948760159f823cc48fe37 (patch)
tree076a6ae171a256e68474d3617abbd3715fa579fc /CMakeLists.txt
parentMerge pull request #184 (diff)
parentcmake: work around a bug with implicit link directories (diff)
downloadmonero-ab7c6c07e71c025a978948760159f823cc48fe37.tar.xz
Merge pull request #180
ce71c01 cmake: work around a bug with implicit link directories (Ben Boeckel) de4fc40 mingw: copy required libraries to the build tree (Ben Boeckel) ec54e2f cmake: place binaries together in the build tree (Ben Boeckel) 18c56ab msys: don't use LTO (Ben Boeckel) 5680c9c msys: factor out -Werror on msys (Ben Boeckel) 4751542 msys: look in msys' directory for files (Ben Boeckel) d855fe4 miniupnpc: bump the _POSIX_C_SOURCE feature macro (Ben Boeckel) c696492 unbound: fix getaddrinfo detection for 32-bit windows (Ben Boeckel) e377687 cmake: Windows and static builds need this (Ben Boeckel) 01895dd cmake: fix up link lines (Ben Boeckel) 4b6515c unbound: fix type checking (Ben Boeckel) d43a20f unbound: plumb the libdir up (Ben Boeckel) 7d708e4 cmake: support 2.8.7 (Ben Boeckel) 464c280 cmake: fix up miniupnpc's define (Ben Boeckel) 9689df9 cmake: clean up EXTRA_LIBRARIES (Ben Boeckel) 3b7bdcb cmake: set the project name (Ben Boeckel) 0f0efc4 cmake: prepend to CMAKE_MODULE_PATH (Ben Boeckel) 031e3da cmake: remove scream-make (all-caps functions) (Ben Boeckel) abbd5c0 unbound: import cmake build system (Ben Boeckel) e59b5b7 miniupnpc: clean up build system (Ben Boeckel) 475fe20 cmake: minor cleanups (indentation and typos) (Ben Boeckel) 799e8b2 cmake: use option() for STATIC (Ben Boeckel) c24d22b cmake: clean up if auto-dereferencing (Ben Boeckel) 9ed415a build: inform the build of what generates version.h (Ben Boeckel) eba180a cmake: support git info in released tarballs (Ben Boeckel) eeffac6 cmake: fix up BOOST_IGNORE_SYSTEM_PATHS (Ben Boeckel) a43f1a8 cmake: remove configuration variables (Ben Boeckel) a87ce09 cmake: factor out error messages (Ben Boeckel) 9aa48b6 miniupnpc: clear out else/endfoo command arguments (Ben Boeckel) 8a86ac8 daemon_tests: update cmake code (Ben Boeckel) fa3ff75 gtest: support an external gtest (Ben Boeckel) 7bfcffa cmake: put each test executable in its own directory (Ben Boeckel) f53f047 cmake: handle private vs. public headers (Ben Boeckel) 55ca7d3 cmake: refactor common code with libraries (Ben Boeckel) c773f46 cmake: refactor common code with executables (Ben Boeckel) 89cff7b cmake: put each library into its own directory (Ben Boeckel)
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)