aboutsummaryrefslogtreecommitdiff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt90
1 files changed, 46 insertions, 44 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5ac4a2f95..5b382264b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -45,34 +45,33 @@ function (die msg)
message(FATAL_ERROR "${BoldRed}${msg}${ColourReset}")
endfunction ()
-if ("${ARCH}" STREQUAL "" OR "${ARCH}" STREQUAL "native")
- set(ARCH ${CMAKE_SYSTEM_PROCESSOR})
- message(STATUS "Building natively on ${ARCH}")
+# ARCH defines the target architecture, either by an explicit identifier or
+# one of the following two keywords. By default, ARCH a value of 'native':
+# target arch = host arch, binary is not portable. When ARCH is set to the
+# string 'default', no -march arg is passed, which creates a binary that is
+# portable across processors in the same family as host processor. In cases
+# when ARCH is not set to an explicit identifier, cmake's builtin is used
+# to identify the target architecture, to direct logic in this cmake script.
+# Since ARCH is a cached variable, it will not be set on first cmake invocation.
+if (NOT ARCH OR ARCH STREQUAL "" OR ARCH STREQUAL "native" OR ARCH STREQUAL "default")
+ set(ARCH_ID "${CMAKE_SYSTEM_PROCESSOR}")
+else()
+ set(ARCH_ID "${ARCH}")
endif()
-
-if (NOT "${ARCH}" STREQUAL "")
- string(SUBSTRING ${ARCH} 0 3 IS_ARM)
- string(TOLOWER ${IS_ARM} IS_ARM)
-
- if (${IS_ARM} STREQUAL "arm")
- string(SUBSTRING ${ARCH} 0 5 ARM_TEST)
- string(TOLOWER ${ARM_TEST} ARM_TEST)
-
- if (${ARM_TEST} STREQUAL "armv6")
- set(ARM6 1)
- else()
- set(ARM6 0)
- endif()
-
- if (${ARM_TEST} STREQUAL "armv7")
- set(ARM7 1)
- else()
- set(ARM7 0)
- endif()
+string(TOLOWER ${ARCH_ID} ARM_ID)
+string(SUBSTRING ${ARCH_ID} 0 3 ARM_TEST)
+if (ARM_TEST STREQUAL "arm")
+ set(ARM 1)
+ string(SUBSTRING ${ARCH_ID} 0 5 ARM_TEST)
+ if (ARM_TEST STREQUAL "armv6")
+ set(ARM6 1)
+ endif()
+ if (ARM_TEST STREQUAL "armv7")
+ set(ARM7 1)
endif()
endif()
-if(WIN32 OR ARM7 OR ARM6)
+if(WIN32 OR ARM)
set(OPT_FLAGS_RELEASE "-O2")
else()
set(OPT_FLAGS_RELEASE "-Ofast")
@@ -235,10 +234,6 @@ elseif (DATABASE STREQUAL "berkeleydb")
message(STATUS "Using Berkeley DB as default DB type")
add_definitions("-DDEFAULT_DB_TYPE=\"berkeley\"")
-elseif (DATABASE STREQUAL "memory")
- set(BLOCKCHAIN_DB DB_MEMORY)
- message(STATUS "Using Serialised In Memory as default DB type")
- add_definitions("-DDEFAULT_DB_TYPE=\"memory\"")
else()
die("Invalid database type: ${DATABASE}")
endif()
@@ -251,7 +246,8 @@ add_definitions("-DBLOCKCHAIN_DB=${BLOCKCHAIN_DB}")
find_package(Libunwind)
# Can't install hook in static build on OSX, because OSX linker does not support --wrap
-if(LIBUNWIND_FOUND AND NOT (STATIC AND APPLE))
+# On ARM, having libunwind package (with .so's only) installed breaks static link.
+if(LIBUNWIND_FOUND AND NOT (STATIC AND (APPLE OR ARM)))
set(DEFAULT_STACK_TRACE ON)
else()
set(DEFAULT_STACK_TRACE OFF)
@@ -312,16 +308,12 @@ if(MSVC)
endif()
include_directories(SYSTEM src/platform/msc)
else()
- set(ARCH native CACHE STRING "CPU to build for: -march value or default")
- # -march=armv7-a conflicts with -mcpu=cortex-a7
- if(ARCH STREQUAL "default" OR ARM7 OR ARM6)
+ set(ARCH native CACHE STRING "CPU to build for: -march value or 'default' to not pass -march at all")
+ message(STATUS "Building on ${CMAKE_SYSTEM_PROCESSOR} for ${ARCH}")
+ if(ARCH STREQUAL "default")
set(ARCH_FLAG "")
else()
- if(ARCH STREQUAL "x86_64")
- set(ARCH_FLAG "-march=x86-64")
- else()
- set(ARCH_FLAG "-march=${ARCH}")
- endif()
+ set(ARCH_FLAG "-march=${ARCH}")
endif()
set(WARNINGS "-Wall -Wextra -Wpointer-arith -Wundef -Wvla -Wwrite-strings -Wno-error=extra -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-unused-variable -Wno-error=unused-variable -Wno-error=undef -Wno-error=uninitialized")
if(NOT MINGW)
@@ -329,7 +321,7 @@ else()
endif()
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
set(WARNINGS "${WARNINGS} -Wno-deprecated-register -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")
- if(ARM6 OR ARM7)
+ if(ARM)
set(WARNINGS "${WARNINGS} -Wno-error=inline-asm")
endif()
else()
@@ -366,11 +358,11 @@ else()
option(NO_AES "Explicitly disable AES support" ${NO_AES})
- if(NOT NO_AES AND NOT (ARM6 OR ARM7))
+ if(NOT NO_AES AND NOT ARM)
message(STATUS "AES support enabled")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -maes")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -maes")
- elseif(ARM7 OR ARM6)
+ elseif(ARM)
message(STATUS "AES support disabled (not available on ARM)")
else()
message(STATUS "AES support disabled")
@@ -392,9 +384,9 @@ else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DGTEST_HAS_TR1_TUPLE=0")
endif()
if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND NOT (CMAKE_C_COMPILER_VERSION VERSION_LESS 4.8))
- set(DEBUG_FLAGS "-g3 -Og")
+ set(DEBUG_FLAGS "-g3 -Og -fprofile-arcs -ftest-coverage --coverage")
else()
- set(DEBUG_FLAGS "-g3 -O0")
+ set(DEBUG_FLAGS "-g3 -O0 -fprofile-arcs -ftest-coverage --coverage")
endif()
if(NOT DEFINED USE_LTO_DEFAULT)
@@ -430,8 +422,18 @@ else()
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${RELEASE_FLAGS}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${RELEASE_FLAGS}")
- if(STATIC AND NOT APPLE AND NOT FREEBSD AND NOT OPENBSD)
- set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++")
+ if(STATIC)
+ # STATIC already configures most deps to be linked in statically,
+ # here we make more deps static if the platform permits it
+ if (MINGW)
+ # On Windows, this is as close to fully-static as we get:
+ # this leaves only deps on /c/Windows/system32/*.dll
+ set(STATIC_FLAGS "-static")
+ elseif (NOT (APPLE OR FREEBSD OR OPENBSD))
+ # On Linux, we don't support fully static build, but these can be static
+ set(STATIC_FLAGS "-static-libgcc -static-libstdc++")
+ endif()
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${STATIC_FLAGS} ")
endif()
endif()