forked from etotheipi/BitcoinArmory
-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add cmake support for linux/mac/windows
This is a complete reproduction of the autotools code in cmake, with improvements where cmake has an advantage. The options are documented in README.md Dependencies on Windows with Visual Studio are handled with vcpkg, and the `VCPKG_TARGET_TRIPLET` variable can activate vcpkg support on other platforms as well. Include the FindPython2 cmake modules as they are not in the base cmake package on Ubuntu. Make some minor fixes to the autotools code as well, for things broken by adding the cmake support and some other fixes. Signed-off-by: Rafael Kitover <rkitover@gmail.com>
- Loading branch information
Showing
27 changed files
with
3,381 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
cmake_minimum_required(VERSION 2.8.12) # ubuntu 14 version | ||
|
||
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) | ||
|
||
set(VCPKG_DEPS protobuf openssl libwebsockets) | ||
|
||
include(Set-Toolchain-vcpkg) | ||
|
||
project(BitcoinArmory C CXX) | ||
|
||
if(NOT CMAKE_BUILD_TYPE) | ||
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "release build with debug info" FORCE) | ||
endif() | ||
|
||
if(POLICY CMP0077) | ||
cmake_policy(SET CMP0077 NEW) | ||
endif() | ||
|
||
include(ArmorySupport) | ||
include(PrettyCompilerColors) | ||
|
||
use_cxx11() | ||
|
||
set(CMAKE_POSITION_INDEPENDENT_CODE ON) | ||
|
||
# use ccache if available, and not already enabled on the command line | ||
# but not with ninja and msys ccache on msys2 | ||
if(NOT (WIN32 AND (NOT $ENV{MSYSTEM} STREQUAL "") AND CMAKE_GENERATOR STREQUAL Ninja)) | ||
if(NOT CMAKE_CXX_COMPILER_LAUNCHER AND NOT CMAKE_C_COMPILER_LAUNCHER) | ||
find_program(CCACHE_FOUND ccache) | ||
if(CCACHE_FOUND) | ||
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) | ||
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache) | ||
endif(CCACHE_FOUND) | ||
endif() | ||
endif() | ||
|
||
# build for host CPU if desired (default yes) | ||
option(WITH_HOST_CPU_FEATURES "support the CPU features of the build host, gcc only" ON) | ||
|
||
if(WITH_HOST_CPU_FEATURES AND CMAKE_CXX_COMPILER_ID STREQUAL GNU) | ||
check_x86_cpu_features() | ||
|
||
add_compile_options(-march=native ${X86_CPU_FEATURES_COMPILER_FLAGS}) | ||
endif() | ||
|
||
if(MSVC) | ||
add_compile_definitions(NOMINMAX _WINSOCKAPI_) | ||
endif() | ||
|
||
add_subdirectory(cppForSwig) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{ | ||
"configurations": [ | ||
{ | ||
"name": "x64-Debug", | ||
"generator": "Ninja", | ||
"configurationType": "Debug", | ||
"inheritEnvironments": [ | ||
"msvc_x64" | ||
], | ||
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}", | ||
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}", | ||
"cmakeCommandArgs": "-DVCPKG_TRIPLET=x64-windows", | ||
"buildCommandArgs": "-v", | ||
"ctestCommandArgs": "" | ||
}, { | ||
"name": "x64-Release", | ||
"generator": "Ninja", | ||
"configurationType": "Release", | ||
"inheritEnvironments": [ | ||
"msvc_x64" | ||
], | ||
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}", | ||
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}", | ||
"cmakeCommandArgs": "-DVCPKG_TRIPLET=x64-windows", | ||
"buildCommandArgs": "-v", | ||
"ctestCommandArgs": "" | ||
}, { | ||
"name": "x86-Debug", | ||
"generator": "Ninja", | ||
"configurationType": "Debug", | ||
"inheritEnvironments": [ | ||
"msvc_x86" | ||
], | ||
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}", | ||
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}", | ||
"cmakeCommandArgs": "-DVCPKG_TRIPLET=x86-windows", | ||
"buildCommandArgs": "-v", | ||
"ctestCommandArgs": "" | ||
}, { | ||
"name": "x86-Release", | ||
"generator": "Ninja", | ||
"configurationType": "Release", | ||
"inheritEnvironments": [ | ||
"msvc_x86" | ||
], | ||
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}", | ||
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}", | ||
"cmakeCommandArgs": "-DVCPKG_TRIPLET=x86-windows", | ||
"buildCommandArgs": "-v", | ||
"ctestCommandArgs": "" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# random utility functions/macros | ||
|
||
# make sure architecture is set | ||
if(NOT CMAKE_SYSTEM_PROCESSOR) | ||
if(NOT CMAKE_TOOLCHAIN_FILE AND CMAKE_HOST_SYSTEM_PROCESSOR) | ||
set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_HOST_SYSTEM_PROCESSOR}) | ||
elseif(CMAKE_TOOLCHAIN_FILE MATCHES mxe) | ||
if(CMAKE_TOOLCHAIN_FILE MATCHES "i[3-9]86") | ||
set(CMAKE_SYSTEM_PROCESSOR i686) | ||
else() | ||
set(CMAKE_SYSTEM_PROCESSOR x86_64) | ||
endif() | ||
endif() | ||
endif() | ||
|
||
macro(string_option opt doc_string initial_value) | ||
if(NOT DEFINED ${${opt}}) | ||
set(${opt} ${initial_value}) | ||
endif() | ||
|
||
set(${opt} ${${opt}} CACHE STRING ${doc_string}) | ||
endmacro() | ||
|
||
# This is from: | ||
# https://stackoverflow.com/a/31010221 | ||
macro(use_cxx11) | ||
if (CMAKE_VERSION VERSION_LESS 3.1) | ||
if(CMAKE_CXX_COMPILER_ID STREQUAL GNU OR CMAKE_CXX_COMPILER_ID STREQUAL Clang) | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11") | ||
endif() | ||
else() | ||
# Fix behavior of CMAKE_CXX_STANDARD when targeting macOS. | ||
if(POLICY CMP0025) | ||
cmake_policy(SET CMP0025 NEW) | ||
endif() | ||
|
||
set(CMAKE_CXX_STANDARD 11) | ||
endif() | ||
endmacro(use_cxx11) | ||
|
||
unset(X86_CPU_FEATURES_COMPILER_FLAGS) | ||
|
||
# check for x86 cpu features and sets X86_CPU_FEATURES_COMPILER_FLAGS for gcc/clang | ||
function(check_x86_cpu_features) | ||
if(NOT CMAKE_SYSTEM_PROCESSOR MATCHES "i.86|x86_64") | ||
return() | ||
endif() | ||
|
||
if(DEFINED X86_CPU_FEATURES_COMPILER_FLAGS) # already computed, do nothing | ||
return() | ||
endif() | ||
|
||
include(CheckCXXSourceCompiles) | ||
|
||
check_cxx_source_compiles(" | ||
#include <stdlib.h> | ||
int main(int argc, char** argv) | ||
{ | ||
__builtin_cpu_init(); | ||
} | ||
" HAVE_CPU_INIT) | ||
|
||
if(HAVE_CPU_INIT) | ||
include(CheckCXXSourceRuns) | ||
|
||
foreach(cpu_feature mmx popcnt sse sse2 sse3 sse4.1 sse4.2 sse4a avx avx2 avx512f fma fma4 bmi bmi2) | ||
string(REPLACE . _ cpu_feature_var ${cpu_feature}) | ||
|
||
check_cxx_source_runs(" | ||
#include <stdlib.h> | ||
int main(int argc, char** argv) | ||
{ | ||
__builtin_cpu_init(); | ||
if (__builtin_cpu_supports(\"${cpu_feature}\")) | ||
return 0; | ||
return 1; | ||
} | ||
" HAVE_${cpu_feature_var}) | ||
|
||
if(HAVE_${cpu_feature_var}) | ||
list(APPEND X86_CPU_FEATURES_COMPILER_FLAGS -m${cpu_feature}) | ||
endif() | ||
endforeach() | ||
|
||
set(X86_CPU_FEATURES_COMPILER_FLAGS ${X86_CPU_FEATURES_COMPILER_FLAGS} CACHE STRING "gcc/clang cpu feature flags for the build host" FORCE) | ||
endif() | ||
endfunction() |
Oops, something went wrong.