2014-09-11 06:25:07 +00:00
|
|
|
# Copyright (c) 2014, The Monero Project
|
|
|
|
#
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without modification, are
|
|
|
|
# permitted provided that the following conditions are met:
|
|
|
|
#
|
|
|
|
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
|
|
|
# conditions and the following disclaimer.
|
|
|
|
#
|
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
|
|
|
# of conditions and the following disclaimer in the documentation and/or other
|
|
|
|
# materials provided with the distribution.
|
|
|
|
#
|
|
|
|
# 3. Neither the name of the copyright holder nor the names of its contributors may be
|
|
|
|
# used to endorse or promote products derived from this software without specific
|
|
|
|
# prior written permission.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
|
|
|
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
|
|
|
# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
|
|
|
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
#
|
|
|
|
# Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
|
|
|
|
|
2014-03-03 22:07:58 +00:00
|
|
|
cmake_minimum_required(VERSION 2.8.6)
|
|
|
|
|
|
|
|
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
|
|
|
set(CMAKE_CONFIGURATION_TYPES "Debug;Release")
|
|
|
|
enable_testing()
|
|
|
|
|
2014-09-09 12:03:42 +00:00
|
|
|
# Check if we're on FreeBSD so we can exclude the local miniupnpc (it should be installed from ports instead)
|
|
|
|
# CMAKE_SYSTEM_NAME checks are commonly known, but specifically taken from libsdl's CMakeLists
|
|
|
|
if(CMAKE_SYSTEM_NAME MATCHES "kFreeBSD.*")
|
|
|
|
set(FREEBSD TRUE)
|
|
|
|
elseif(CMAKE_SYSTEM_NAME MATCHES "DragonFly.*|FreeBSD")
|
|
|
|
set(FREEBSD TRUE)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# TODO: check bsdi, NetBSD, OpenBSD, to see if they need the same FreeBSD changes
|
|
|
|
#
|
|
|
|
# elseif(CMAKE_SYSTEM_NAME MATCHES "kNetBSD.*|NetBSD.*")
|
|
|
|
# set(NETBSD TRUE)
|
|
|
|
# elseif(CMAKE_SYSTEM_NAME MATCHES "kOpenBSD.*|OpenBSD.*")
|
|
|
|
# set(OPENBSD TRUE)
|
|
|
|
# elseif(CMAKE_SYSTEM_NAME MATCHES ".*BSDI.*")
|
|
|
|
# set(BSDI TRUE)
|
|
|
|
|
2014-04-09 12:14:35 +00:00
|
|
|
include_directories(src contrib/epee/include external "${CMAKE_BINARY_DIR}/version")
|
2014-03-03 22:07:58 +00:00
|
|
|
|
2014-04-30 17:52:21 +00:00
|
|
|
if(APPLE)
|
2014-04-30 20:50:06 +00:00
|
|
|
include_directories(SYSTEM /usr/include/malloc)
|
2014-04-30 17:52:21 +00:00
|
|
|
endif()
|
|
|
|
|
2014-08-06 16:27:16 +00:00
|
|
|
if(MSVC OR MINGW)
|
|
|
|
set(DEFAULT_STATIC true)
|
|
|
|
else()
|
|
|
|
set(DEFAULT_STATIC false)
|
|
|
|
endif()
|
|
|
|
set(STATIC ${DEFAULT_STATIC} CACHE BOOL "Link libraries statically")
|
2014-03-03 22:07:58 +00:00
|
|
|
|
2014-06-11 17:15:23 +00:00
|
|
|
if (UNIX AND NOT APPLE)
|
|
|
|
# Note that at the time of this writing the -Wstrict-prototypes flag added below will make this fail
|
2014-06-13 04:01:04 +00:00
|
|
|
find_package(Threads)
|
2014-06-11 17:15:23 +00:00
|
|
|
endif()
|
|
|
|
|
2014-03-03 22:07:58 +00:00
|
|
|
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__")
|
|
|
|
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Dinline=__inline")
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:10485760")
|
|
|
|
if(STATIC)
|
|
|
|
foreach(VAR CMAKE_C_FLAGS_DEBUG CMAKE_CXX_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_CXX_FLAGS_RELEASE)
|
|
|
|
string(REPLACE "/MD" "/MT" ${VAR} "${${VAR}}")
|
|
|
|
endforeach()
|
|
|
|
endif()
|
|
|
|
include_directories(SYSTEM src/platform/msc)
|
|
|
|
else()
|
|
|
|
set(ARCH native CACHE STRING "CPU to build for: -march value or 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")
|
|
|
|
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()
|
|
|
|
set(WARNINGS "${WARNINGS} -Wlogical-op -Wno-error=maybe-uninitialized")
|
|
|
|
endif()
|
|
|
|
if(MINGW)
|
2014-08-06 16:32:59 +00:00
|
|
|
set(WARNINGS "${WARNINGS} -Wno-error=unused-value -Wno-error=unused-but-set-variable")
|
2014-08-06 16:42:24 +00:00
|
|
|
set(MINGW_FLAG "${MINGW_FLAG} -DWIN32_LEAN_AND_MEAN")
|
2014-08-06 16:43:01 +00:00
|
|
|
set(Boost_THREADAPI win32)
|
2014-03-03 22:07:58 +00:00
|
|
|
include_directories(SYSTEM src/platform/mingw)
|
|
|
|
endif()
|
|
|
|
set(C_WARNINGS "-Waggregate-return -Wnested-externs -Wold-style-definition -Wstrict-prototypes")
|
|
|
|
set(CXX_WARNINGS "-Wno-reorder -Wno-missing-field-initializers")
|
|
|
|
try_compile(STATIC_ASSERT_RES "${CMAKE_CURRENT_BINARY_DIR}/static-assert" "${CMAKE_CURRENT_SOURCE_DIR}/utils/test-static-assert.c" COMPILE_DEFINITIONS "-std=c11")
|
|
|
|
if(STATIC_ASSERT_RES)
|
|
|
|
set(STATIC_ASSERT_FLAG "")
|
|
|
|
else()
|
|
|
|
set(STATIC_ASSERT_FLAG "-Dstatic_assert=_Static_assert")
|
|
|
|
endif()
|
2014-05-21 20:02:46 +00:00
|
|
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -D_GNU_SOURCE ${MINGW_FLAG} ${STATIC_ASSERT_FLAG} ${WARNINGS} ${C_WARNINGS} ${ARCH_FLAG} -maes")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -D_GNU_SOURCE ${MINGW_FLAG} ${WARNINGS} ${CXX_WARNINGS} ${ARCH_FLAG} -maes")
|
2014-04-30 20:50:06 +00:00
|
|
|
if(APPLE)
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DGTEST_HAS_TR1_TUPLE=0")
|
|
|
|
endif()
|
2014-03-03 22:07:58 +00:00
|
|
|
if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND NOT (CMAKE_C_COMPILER_VERSION VERSION_LESS 4.8))
|
|
|
|
set(DEBUG_FLAGS "-g3 -Og")
|
|
|
|
else()
|
|
|
|
set(DEBUG_FLAGS "-g3 -O0")
|
|
|
|
endif()
|
2014-08-06 16:52:25 +00:00
|
|
|
|
2014-05-22 11:00:48 +00:00
|
|
|
set(RELEASE_FLAGS "-Ofast -DNDEBUG -Wno-unused-variable")
|
2014-08-06 16:52:25 +00:00
|
|
|
|
2014-08-07 23:34:10 +00:00
|
|
|
if(NOT DEFINED USE_LTO_DEFAULT)
|
|
|
|
set(USE_LTO_DEFAULT true)
|
|
|
|
endif()
|
|
|
|
set(USE_LTO ${USE_LTO_DEFAULT} CACHE BOOL "Use Link-Time Optimization (Release mode only)")
|
2014-09-15 20:47:26 +00:00
|
|
|
|
|
|
|
# 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)
|
|
|
|
endif()
|
2014-08-06 16:52:25 +00:00
|
|
|
if(USE_LTO)
|
2014-05-22 11:00:48 +00:00
|
|
|
set(RELEASE_FLAGS "${RELEASE_FLAGS} -flto")
|
2014-08-06 16:52:25 +00:00
|
|
|
if(STATIC)
|
|
|
|
set(RELEASE_FLAGS "${RELEASE_FLAGS} -ffat-lto-objects")
|
|
|
|
endif()
|
|
|
|
# Since gcc 4.9 the LTO format is non-standard (slim), so we need the gcc-specific ar and ranlib binaries
|
|
|
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9.0))
|
|
|
|
set(CMAKE_AR "gcc-ar")
|
|
|
|
set(CMAKE_RANLIB "gcc-ranlib")
|
|
|
|
endif()
|
2014-05-22 11:00:48 +00:00
|
|
|
endif()
|
2014-08-06 16:52:25 +00:00
|
|
|
|
2014-03-03 22:07:58 +00:00
|
|
|
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${DEBUG_FLAGS}")
|
|
|
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${DEBUG_FLAGS}")
|
|
|
|
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${RELEASE_FLAGS}")
|
|
|
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${RELEASE_FLAGS}")
|
2014-09-15 06:08:03 +00:00
|
|
|
if(STATIC AND NOT APPLE AND NOT FREEBSD)
|
2014-08-06 16:45:47 +00:00
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
|
2014-03-03 22:07:58 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(STATIC)
|
|
|
|
set(Boost_USE_STATIC_LIBS ON)
|
|
|
|
set(Boost_USE_STATIC_RUNTIME ON)
|
|
|
|
endif()
|
2014-05-25 17:06:40 +00:00
|
|
|
find_package(Boost 1.53 REQUIRED COMPONENTS system filesystem thread date_time chrono regex serialization program_options)
|
2014-03-03 22:07:58 +00:00
|
|
|
if((${Boost_MAJOR_VERSION} EQUAL 1) AND (${Boost_MINOR_VERSION} EQUAL 54))
|
|
|
|
message(SEND_ERROR "Boost version 1.54 is unsupported, more details are available here http://goo.gl/RrCFmA")
|
|
|
|
endif()
|
|
|
|
include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
|
|
|
|
if(MINGW)
|
2014-08-06 16:50:12 +00:00
|
|
|
set(Boost_LIBRARIES "${Boost_LIBRARIES};pthread;mswsock;ws2_32")
|
2014-09-15 06:08:03 +00:00
|
|
|
elseif(APPLE OR FREEBSD)
|
2014-04-30 17:52:21 +00:00
|
|
|
set(Boost_LIBRARIES "${Boost_LIBRARIES}")
|
2014-04-30 20:50:06 +00:00
|
|
|
elseif(NOT MSVC)
|
2014-08-06 16:50:12 +00:00
|
|
|
#set(Boost_LIBRARIES "${Boost_LIBRARIES};rt;pthread")
|
2014-03-03 22:07:58 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/version")
|
2014-09-12 11:06:51 +00:00
|
|
|
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")
|
2014-03-03 22:07:58 +00:00
|
|
|
configure_file("src/version.h.in" "version/version.h")
|
|
|
|
add_custom_target(version ALL)
|
|
|
|
endif()
|
|
|
|
|
2014-04-09 12:14:35 +00:00
|
|
|
add_subdirectory(external)
|
2014-09-11 06:22:49 +00:00
|
|
|
|
|
|
|
# Final setup for miniupnpc
|
|
|
|
if(UPNP_STATIC)
|
|
|
|
add_definitions("-DUPNP_STATIC")
|
|
|
|
else()
|
|
|
|
add_definitions("-DUPNP_DYNAMIC")
|
|
|
|
include_directories(${UPNP_INCLUDE})
|
|
|
|
endif()
|
|
|
|
|
2014-03-03 22:07:58 +00:00
|
|
|
add_subdirectory(src)
|
|
|
|
add_subdirectory(tests)
|