Squashed 'cmake/cable/' content from commit d7bbd20

git-subtree-dir: cmake/cable
git-subtree-split: d7bbd20f9fe03a0ab1948434d83a9a3b9ea79d17
This commit is contained in:
Paweł Bylica 2018-04-10 16:28:36 +02:00
commit 553d384123
17 changed files with 1244 additions and 0 deletions

79
CableBuildInfo.cmake Normal file
View File

@ -0,0 +1,79 @@
# Copyright 2018 Pawel Bylica.
# Licensed under the Apache License, Version 2.0. See the LICENSE file.
if(cable_build_info_included)
return()
endif()
set(cable_build_info_included TRUE)
set(cable_buildinfo_template_dir ${CMAKE_CURRENT_LIST_DIR}/buildinfo)
function(cable_add_buildinfo_library)
cmake_parse_arguments("" "" PREFIX "" ${ARGN})
# Come up with the target and C function name.
if(_PREFIX)
set(NAME ${_PREFIX}-buildinfo)
set(FUNCTION_NAME ${_PREFIX}_get_buildinfo)
else()
set(NAME buildinfo)
set(FUNCTION_NAME get_buildinfo)
endif()
set(binary_dir ${CMAKE_CURRENT_BINARY_DIR})
if(CMAKE_CONFIGURATION_TYPES)
set(build_type ${CMAKE_CFG_INTDIR})
else()
set(build_type ${CMAKE_BUILD_TYPE})
endif()
# Find git here to allow the user to provide hints.
find_package(Git)
# Git info target.
#
# This target is named <name>-git and is always built.
# The executed script gitinfo.cmake check git status and updates files
# containing git information if anything has changed.
add_custom_target(
${NAME}-git
COMMAND ${CMAKE_COMMAND}
-DGIT=${GIT_EXECUTABLE}
-DSOURCE_DIR=${PROJECT_SOURCE_DIR}
-DBINARY_DIR=${binary_dir}
-P ${cable_buildinfo_template_dir}/gitinfo.cmake
)
add_custom_command(
COMMENT "Updating ${NAME}:"
OUTPUT ${binary_dir}/${NAME}.c
COMMAND ${CMAKE_COMMAND}
-DBINARY_DIR=${binary_dir}
-DNAME=${NAME}
-DFUNCTION_NAME=${FUNCTION_NAME}
-DPROJECT_VERSION=${PROJECT_VERSION}
-DSYSTEM_NAME=${CMAKE_SYSTEM_NAME}
-DSYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR}
-DCOMPILER_ID=${CMAKE_CXX_COMPILER_ID}
-DCOMPILER_VERSION=${CMAKE_CXX_COMPILER_VERSION}
-DBUILD_TYPE=${build_type}
-P ${cable_buildinfo_template_dir}/buildinfo.cmake
DEPENDS
${cable_buildinfo_template_dir}/buildinfo.cmake
${cable_buildinfo_template_dir}/buildinfo.c.in
${NAME}-git
${binary_dir}/git_commit_hash.txt
)
string(TIMESTAMP TIMESTAMP)
configure_file(${cable_buildinfo_template_dir}/buildinfo.h.in ${binary_dir}/${NAME}.h)
# Add buildinfo library under given name.
# Make is static and do not build by default until some other target will actually use it.
add_library(${NAME} STATIC EXCLUDE_FROM_ALL ${binary_dir}/${NAME}.c ${binary_dir}/${NAME}.h)
target_include_directories(${NAME} PUBLIC ${binary_dir})
endfunction()

43
CableBuildType.cmake Normal file
View File

@ -0,0 +1,43 @@
# Copyright 2018 Pawel Bylica.
# Licensed under the Apache License, Version 2.0. See the LICENSE file.
if(cable_build_type_included)
return()
endif()
set(cable_build_type_included TRUE)
macro(cable_set_build_type)
if(NOT PROJECT_IS_NESTED)
# Do this configuration only in the top project.
if(NOT PROJECT_SOURCE_DIR)
message(FATAL_ERROR "cable_set_build_type() can be used only after project()")
endif()
cmake_parse_arguments(build_type "" DEFAULT CONFIGURATION_TYPES ${ARGN})
if(CMAKE_CONFIGURATION_TYPES)
if(build_type_CONFIGURATION_TYPES)
set(
CMAKE_CONFIGURATION_TYPES
${build_type_CONFIGURATION_TYPES}
CACHE
STRING
"Available configurations for multi-configuration generators"
FORCE
)
endif()
message(STATUS "[cable] Configurations: ${CMAKE_CONFIGURATION_TYPES}")
else()
if(build_type_DEFAULT AND NOT CMAKE_BUILD_TYPE)
set(
CMAKE_BUILD_TYPE
${build_type_DEFAULT}
CACHE STRING
"Build type for single-configuration generators"
FORCE
)
endif()
message(STATUS "[cable] Build type: ${CMAKE_BUILD_TYPE}")
endif()
endif()
endmacro()

106
CableCompilerSettings.cmake Normal file
View File

@ -0,0 +1,106 @@
include(CheckCXXCompilerFlag)
# Adds CXX compiler flag if the flag is supported by the compiler.
#
# This is effectively a combination of CMake's check_cxx_compiler_flag()
# and add_compile_options():
#
# if(check_cxx_compiler_flag(flag))
# add_compile_options(flag)
#
function(cable_add_cxx_compiler_flag_if_supported FLAG)
# Remove leading - or / from the flag name.
string(REGEX REPLACE "^-|/" "" name ${FLAG})
check_cxx_compiler_flag(${FLAG} ${name})
if(${name})
add_compile_options(${FLAG})
endif()
# If the optional argument passed, store the result there.
if(ARGV1)
set(${ARGV1} ${name} PARENT_SCOPE)
endif()
endfunction()
# Configures the compiler with default flags.
macro(cable_configure_compiler)
if(NOT PROJECT_IS_NESTED)
# Do this configuration only in the top project.
# Set helper variables recognizing C++ compilers.
if(${CMAKE_CXX_COMPILER_ID} STREQUAL GNU)
set(CABLE_COMPILER_GNU TRUE)
elseif(${CMAKE_CXX_COMPILER_ID} MATCHES Clang)
# This matches both clang and AppleClang.
set(CABLE_COMPILER_CLANG TRUE)
endif()
if(CABLE_COMPILER_GNU OR CABLE_COMPILER_CLANG)
set(CABLE_COMPILER_GNULIKE TRUE)
endif()
if(CABLE_COMPILER_GNULIKE)
# Enable basing warnings set and treat them as errors.
add_compile_options(-Wall -Wextra -Werror -pedantic)
# Allow unknown pragmas, we don't want to wrap them with #ifdefs.
add_compile_options(-Wno-unknown-pragmas)
elseif(MSVC)
# Enable basing warnings set and treat them as errors.
add_compile_options(/W4 /WX)
# Allow unknown pragmas, we don't want to wrap them with #ifdefs.
add_compile_options(/wd4068)
endif()
cable_add_cxx_compiler_flag_if_supported(-fstack-protector-strong have_stack_protector_strong_support)
if(NOT have_stack_protector_strong_support)
cable_add_cxx_compiler_flag_if_supported(-fstack-protector)
endif()
cable_add_cxx_compiler_flag_if_supported(-Wimplicit-fallthrough)
# Sanitizers support.
set(SANITIZE OFF CACHE STRING "Build with the specified sanitizer")
if(SANITIZE)
# Set the linker flags first, they are required to properly test the compiler flag.
set(CMAKE_SHARED_LINKER_FLAGS "-fsanitize=${SANITIZE} ${CMAKE_SHARED_LINKER_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "-fsanitize=${SANITIZE} ${CMAKE_EXE_LINKER_FLAGS}")
set(test_name have_fsanitize_${SANITIZE})
check_cxx_compiler_flag(-fsanitize=${SANITIZE} ${test_name})
if(NOT ${test_name})
message(FATAL_ERROR "Unsupported sanitizer: ${SANITIZE}")
endif()
add_compile_options(-fno-omit-frame-pointer -fsanitize=${SANITIZE})
set(backlist_file ${PROJECT_SOURCE_DIR}/sanitizer-blacklist.txt)
if(EXISTS ${backlist_file})
check_cxx_compiler_flag(-fsanitize-blacklist=${backlist_file} have_fsanitize-blacklist)
if(have_fsanitize-blacklist)
add_compile_options(-fsanitize-blacklist=${backlist_file})
endif()
endif()
endif()
# Code coverage support.
option(COVERAGE "Build with code coverage support" OFF)
if(COVERAGE)
# Set the linker flags first, they are required to properly test the compiler flag.
set(CMAKE_SHARED_LINKER_FLAGS "--coverage ${CMAKE_SHARED_LINKER_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "--coverage ${CMAKE_EXE_LINKER_FLAGS}")
check_cxx_compiler_flag(--coverage have_coverage)
if(NOT have_coverage)
message(FATAL_ERROR "Unsupported sanitizer: ${SANITIZE}")
endif()
add_compile_options(-g --coverage)
endif()
endif()
endmacro()

23
CableToolchains.cmake Normal file
View File

@ -0,0 +1,23 @@
# Copyright 2018 Pawel Bylica.
# Licensed under the Apache License, Version 2.0. See the LICENSE file.
set(cable_toolchain_dir ${CMAKE_CURRENT_LIST_DIR}/toolchains)
function(cable_configure_toolchain)
if(NOT PROJECT_IS_NESTED)
# Do this configuration only in the top project.
cmake_parse_arguments("" "" "DEFAULT" "" ${ARGN})
set(default_toolchain default)
if(_DEFAULT)
set(default_toolchain ${_DEFAULT})
endif()
set(TOOLCHAIN ${default_toolchain} CACHE STRING "CMake toolchain")
set(toolchain_file ${cable_toolchain_dir}/${TOOLCHAIN}.cmake)
set(CMAKE_TOOLCHAIN_FILE ${toolchain_file} CACHE FILEPATH "CMake toolchain file")
endif()
endfunction()

543
HunterGate.cmake Normal file
View File

@ -0,0 +1,543 @@
# Copyright (c) 2013-2017, Ruslan Baratov
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * 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.
#
# 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.
# This is a gate file to Hunter package manager.
# Include this file using `include` command and add package you need, example:
#
# cmake_minimum_required(VERSION 3.0)
#
# include("cmake/HunterGate.cmake")
# HunterGate(
# URL "https://github.com/path/to/hunter/archive.tar.gz"
# SHA1 "798501e983f14b28b10cda16afa4de69eee1da1d"
# )
#
# project(MyProject)
#
# hunter_add_package(Foo)
# hunter_add_package(Boo COMPONENTS Bar Baz)
#
# Projects:
# * https://github.com/hunter-packages/gate/
# * https://github.com/ruslo/hunter
option(HUNTER_ENABLED "Enable Hunter package manager support" ON)
if(HUNTER_ENABLED)
if(CMAKE_VERSION VERSION_LESS "3.0")
message(FATAL_ERROR "At least CMake version 3.0 required for hunter dependency management."
" Update CMake or set HUNTER_ENABLED to OFF.")
endif()
endif()
include(CMakeParseArguments) # cmake_parse_arguments
option(HUNTER_STATUS_PRINT "Print working status" ON)
option(HUNTER_STATUS_DEBUG "Print a lot info" OFF)
option(HUNTER_TLS_VERIFY "Enable/disable TLS certificate checking on downloads" ON)
set(HUNTER_WIKI "https://github.com/ruslo/hunter/wiki")
function(hunter_gate_status_print)
foreach(print_message ${ARGV})
if(HUNTER_STATUS_PRINT OR HUNTER_STATUS_DEBUG)
message(STATUS "[hunter] ${print_message}")
endif()
endforeach()
endfunction()
function(hunter_gate_status_debug)
foreach(print_message ${ARGV})
if(HUNTER_STATUS_DEBUG)
string(TIMESTAMP timestamp)
message(STATUS "[hunter *** DEBUG *** ${timestamp}] ${print_message}")
endif()
endforeach()
endfunction()
function(hunter_gate_wiki wiki_page)
message("------------------------------ WIKI -------------------------------")
message(" ${HUNTER_WIKI}/${wiki_page}")
message("-------------------------------------------------------------------")
message("")
message(FATAL_ERROR "")
endfunction()
function(hunter_gate_internal_error)
message("")
foreach(print_message ${ARGV})
message("[hunter ** INTERNAL **] ${print_message}")
endforeach()
message("[hunter ** INTERNAL **] [Directory:${CMAKE_CURRENT_LIST_DIR}]")
message("")
hunter_gate_wiki("error.internal")
endfunction()
function(hunter_gate_fatal_error)
cmake_parse_arguments(hunter "" "WIKI" "" "${ARGV}")
string(COMPARE EQUAL "${hunter_WIKI}" "" have_no_wiki)
if(have_no_wiki)
hunter_gate_internal_error("Expected wiki")
endif()
message("")
foreach(x ${hunter_UNPARSED_ARGUMENTS})
message("[hunter ** FATAL ERROR **] ${x}")
endforeach()
message("[hunter ** FATAL ERROR **] [Directory:${CMAKE_CURRENT_LIST_DIR}]")
message("")
hunter_gate_wiki("${hunter_WIKI}")
endfunction()
function(hunter_gate_user_error)
hunter_gate_fatal_error(${ARGV} WIKI "error.incorrect.input.data")
endfunction()
function(hunter_gate_self root version sha1 result)
string(COMPARE EQUAL "${root}" "" is_bad)
if(is_bad)
hunter_gate_internal_error("root is empty")
endif()
string(COMPARE EQUAL "${version}" "" is_bad)
if(is_bad)
hunter_gate_internal_error("version is empty")
endif()
string(COMPARE EQUAL "${sha1}" "" is_bad)
if(is_bad)
hunter_gate_internal_error("sha1 is empty")
endif()
string(SUBSTRING "${sha1}" 0 7 archive_id)
if(EXISTS "${root}/cmake/Hunter")
set(hunter_self "${root}")
else()
set(
hunter_self
"${root}/_Base/Download/Hunter/${version}/${archive_id}/Unpacked"
)
endif()
set("${result}" "${hunter_self}" PARENT_SCOPE)
endfunction()
# Set HUNTER_GATE_ROOT cmake variable to suitable value.
function(hunter_gate_detect_root)
# Check CMake variable
string(COMPARE NOTEQUAL "${HUNTER_ROOT}" "" not_empty)
if(not_empty)
set(HUNTER_GATE_ROOT "${HUNTER_ROOT}" PARENT_SCOPE)
hunter_gate_status_debug("HUNTER_ROOT detected by cmake variable")
return()
endif()
# Check environment variable
string(COMPARE NOTEQUAL "$ENV{HUNTER_ROOT}" "" not_empty)
if(not_empty)
set(HUNTER_GATE_ROOT "$ENV{HUNTER_ROOT}" PARENT_SCOPE)
hunter_gate_status_debug("HUNTER_ROOT detected by environment variable")
return()
endif()
# Check HOME environment variable
string(COMPARE NOTEQUAL "$ENV{HOME}" "" result)
if(result)
set(HUNTER_GATE_ROOT "$ENV{HOME}/.hunter" PARENT_SCOPE)
hunter_gate_status_debug("HUNTER_ROOT set using HOME environment variable")
return()
endif()
# Check SYSTEMDRIVE and USERPROFILE environment variable (windows only)
if(WIN32)
string(COMPARE NOTEQUAL "$ENV{SYSTEMDRIVE}" "" result)
if(result)
set(HUNTER_GATE_ROOT "$ENV{SYSTEMDRIVE}/.hunter" PARENT_SCOPE)
hunter_gate_status_debug(
"HUNTER_ROOT set using SYSTEMDRIVE environment variable"
)
return()
endif()
string(COMPARE NOTEQUAL "$ENV{USERPROFILE}" "" result)
if(result)
set(HUNTER_GATE_ROOT "$ENV{USERPROFILE}/.hunter" PARENT_SCOPE)
hunter_gate_status_debug(
"HUNTER_ROOT set using USERPROFILE environment variable"
)
return()
endif()
endif()
hunter_gate_fatal_error(
"Can't detect HUNTER_ROOT"
WIKI "error.detect.hunter.root"
)
endfunction()
macro(hunter_gate_lock dir)
if(NOT HUNTER_SKIP_LOCK)
if("${CMAKE_VERSION}" VERSION_LESS "3.2")
hunter_gate_fatal_error(
"Can't lock, upgrade to CMake 3.2 or use HUNTER_SKIP_LOCK"
WIKI "error.can.not.lock"
)
endif()
hunter_gate_status_debug("Locking directory: ${dir}")
file(LOCK "${dir}" DIRECTORY GUARD FUNCTION)
hunter_gate_status_debug("Lock done")
endif()
endmacro()
function(hunter_gate_download dir)
string(
COMPARE
NOTEQUAL
"$ENV{HUNTER_DISABLE_AUTOINSTALL}"
""
disable_autoinstall
)
if(disable_autoinstall AND NOT HUNTER_RUN_INSTALL)
hunter_gate_fatal_error(
"Hunter not found in '${dir}'"
"Set HUNTER_RUN_INSTALL=ON to auto-install it from '${HUNTER_GATE_URL}'"
"Settings:"
" HUNTER_ROOT: ${HUNTER_GATE_ROOT}"
" HUNTER_SHA1: ${HUNTER_GATE_SHA1}"
WIKI "error.run.install"
)
endif()
string(COMPARE EQUAL "${dir}" "" is_bad)
if(is_bad)
hunter_gate_internal_error("Empty 'dir' argument")
endif()
string(COMPARE EQUAL "${HUNTER_GATE_SHA1}" "" is_bad)
if(is_bad)
hunter_gate_internal_error("HUNTER_GATE_SHA1 empty")
endif()
string(COMPARE EQUAL "${HUNTER_GATE_URL}" "" is_bad)
if(is_bad)
hunter_gate_internal_error("HUNTER_GATE_URL empty")
endif()
set(done_location "${dir}/DONE")
set(sha1_location "${dir}/SHA1")
set(build_dir "${dir}/Build")
set(cmakelists "${dir}/CMakeLists.txt")
hunter_gate_lock("${dir}")
if(EXISTS "${done_location}")
# while waiting for lock other instance can do all the job
hunter_gate_status_debug("File '${done_location}' found, skip install")
return()
endif()
file(REMOVE_RECURSE "${build_dir}")
file(REMOVE_RECURSE "${cmakelists}")
file(MAKE_DIRECTORY "${build_dir}") # check directory permissions
# Disabling languages speeds up a little bit, reduces noise in the output
# and avoids path too long windows error
file(
WRITE
"${cmakelists}"
"cmake_minimum_required(VERSION 3.0)\n"
"project(HunterDownload LANGUAGES NONE)\n"
"include(ExternalProject)\n"
"ExternalProject_Add(\n"
" Hunter\n"
" URL\n"
" \"${HUNTER_GATE_URL}\"\n"
" URL_HASH\n"
" SHA1=${HUNTER_GATE_SHA1}\n"
" DOWNLOAD_DIR\n"
" \"${dir}\"\n"
" TLS_VERIFY\n"
" ${HUNTER_TLS_VERIFY}\n"
" SOURCE_DIR\n"
" \"${dir}/Unpacked\"\n"
" CONFIGURE_COMMAND\n"
" \"\"\n"
" BUILD_COMMAND\n"
" \"\"\n"
" INSTALL_COMMAND\n"
" \"\"\n"
")\n"
)
if(HUNTER_STATUS_DEBUG)
set(logging_params "")
else()
set(logging_params OUTPUT_QUIET)
endif()
hunter_gate_status_debug("Run generate")
# Need to add toolchain file too.
# Otherwise on Visual Studio + MDD this will fail with error:
# "Could not find an appropriate version of the Windows 10 SDK installed on this machine"
if(EXISTS "${CMAKE_TOOLCHAIN_FILE}")
get_filename_component(absolute_CMAKE_TOOLCHAIN_FILE "${CMAKE_TOOLCHAIN_FILE}" ABSOLUTE)
set(toolchain_arg "-DCMAKE_TOOLCHAIN_FILE=${absolute_CMAKE_TOOLCHAIN_FILE}")
else()
# 'toolchain_arg' can't be empty
set(toolchain_arg "-DCMAKE_TOOLCHAIN_FILE=")
endif()
string(COMPARE EQUAL "${CMAKE_MAKE_PROGRAM}" "" no_make)
if(no_make)
set(make_arg "")
else()
# Test case: remove Ninja from PATH but set it via CMAKE_MAKE_PROGRAM
set(make_arg "-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}")
endif()
execute_process(
COMMAND
"${CMAKE_COMMAND}"
"-H${dir}"
"-B${build_dir}"
"-G${CMAKE_GENERATOR}"
"${toolchain_arg}"
${make_arg}
WORKING_DIRECTORY "${dir}"
RESULT_VARIABLE download_result
${logging_params}
)
if(NOT download_result EQUAL 0)
hunter_gate_internal_error("Configure project failed")
endif()
hunter_gate_status_print(
"Initializing Hunter workspace (${HUNTER_GATE_SHA1})"
" ${HUNTER_GATE_URL}"
" -> ${dir}"
)
execute_process(
COMMAND "${CMAKE_COMMAND}" --build "${build_dir}"
WORKING_DIRECTORY "${dir}"
RESULT_VARIABLE download_result
${logging_params}
)
if(NOT download_result EQUAL 0)
hunter_gate_internal_error("Build project failed")
endif()
file(REMOVE_RECURSE "${build_dir}")
file(REMOVE_RECURSE "${cmakelists}")
file(WRITE "${sha1_location}" "${HUNTER_GATE_SHA1}")
file(WRITE "${done_location}" "DONE")
hunter_gate_status_debug("Finished")
endfunction()
# Must be a macro so master file 'cmake/Hunter' can
# apply all variables easily just by 'include' command
# (otherwise PARENT_SCOPE magic needed)
macro(HunterGate)
if(HUNTER_GATE_DONE)
# variable HUNTER_GATE_DONE set explicitly for external project
# (see `hunter_download`)
set_property(GLOBAL PROPERTY HUNTER_GATE_DONE YES)
endif()
# First HunterGate command will init Hunter, others will be ignored
get_property(_hunter_gate_done GLOBAL PROPERTY HUNTER_GATE_DONE SET)
if(NOT HUNTER_ENABLED)
# Empty function to avoid error "unknown function"
function(hunter_add_package)
endfunction()
set(
_hunter_gate_disabled_mode_dir
"${CMAKE_CURRENT_LIST_DIR}/cmake/Hunter/disabled-mode"
)
if(EXISTS "${_hunter_gate_disabled_mode_dir}")
hunter_gate_status_debug(
"Adding \"disabled-mode\" modules: ${_hunter_gate_disabled_mode_dir}"
)
list(APPEND CMAKE_PREFIX_PATH "${_hunter_gate_disabled_mode_dir}")
endif()
elseif(_hunter_gate_done)
hunter_gate_status_debug("Secondary HunterGate (use old settings)")
hunter_gate_self(
"${HUNTER_CACHED_ROOT}"
"${HUNTER_VERSION}"
"${HUNTER_SHA1}"
_hunter_self
)
include("${_hunter_self}/cmake/Hunter")
else()
set(HUNTER_GATE_LOCATION "${CMAKE_CURRENT_LIST_DIR}")
string(COMPARE NOTEQUAL "${PROJECT_NAME}" "" _have_project_name)
if(_have_project_name)
hunter_gate_fatal_error(
"Please set HunterGate *before* 'project' command. "
"Detected project: ${PROJECT_NAME}"
WIKI "error.huntergate.before.project"
)
endif()
cmake_parse_arguments(
HUNTER_GATE "LOCAL" "URL;SHA1;GLOBAL;FILEPATH" "" ${ARGV}
)
string(COMPARE EQUAL "${HUNTER_GATE_SHA1}" "" _empty_sha1)
string(COMPARE EQUAL "${HUNTER_GATE_URL}" "" _empty_url)
string(
COMPARE
NOTEQUAL
"${HUNTER_GATE_UNPARSED_ARGUMENTS}"
""
_have_unparsed
)
string(COMPARE NOTEQUAL "${HUNTER_GATE_GLOBAL}" "" _have_global)
string(COMPARE NOTEQUAL "${HUNTER_GATE_FILEPATH}" "" _have_filepath)
if(_have_unparsed)
hunter_gate_user_error(
"HunterGate unparsed arguments: ${HUNTER_GATE_UNPARSED_ARGUMENTS}"
)
endif()
if(_empty_sha1)
hunter_gate_user_error("SHA1 suboption of HunterGate is mandatory")
endif()
if(_empty_url)
hunter_gate_user_error("URL suboption of HunterGate is mandatory")
endif()
if(_have_global)
if(HUNTER_GATE_LOCAL)
hunter_gate_user_error("Unexpected LOCAL (already has GLOBAL)")
endif()
if(_have_filepath)
hunter_gate_user_error("Unexpected FILEPATH (already has GLOBAL)")
endif()
endif()
if(HUNTER_GATE_LOCAL)
if(_have_global)
hunter_gate_user_error("Unexpected GLOBAL (already has LOCAL)")
endif()
if(_have_filepath)
hunter_gate_user_error("Unexpected FILEPATH (already has LOCAL)")
endif()
endif()
if(_have_filepath)
if(_have_global)
hunter_gate_user_error("Unexpected GLOBAL (already has FILEPATH)")
endif()
if(HUNTER_GATE_LOCAL)
hunter_gate_user_error("Unexpected LOCAL (already has FILEPATH)")
endif()
endif()
hunter_gate_detect_root() # set HUNTER_GATE_ROOT
# Beautify path, fix probable problems with windows path slashes
get_filename_component(
HUNTER_GATE_ROOT "${HUNTER_GATE_ROOT}" ABSOLUTE
)
hunter_gate_status_debug("HUNTER_ROOT: ${HUNTER_GATE_ROOT}")
if(NOT HUNTER_ALLOW_SPACES_IN_PATH)
string(FIND "${HUNTER_GATE_ROOT}" " " _contain_spaces)
if(NOT _contain_spaces EQUAL -1)
hunter_gate_fatal_error(
"HUNTER_ROOT (${HUNTER_GATE_ROOT}) contains spaces."
"Set HUNTER_ALLOW_SPACES_IN_PATH=ON to skip this error"
"(Use at your own risk!)"
WIKI "error.spaces.in.hunter.root"
)
endif()
endif()
string(
REGEX
MATCH
"[0-9]+\\.[0-9]+\\.[0-9]+[-_a-z0-9]*"
HUNTER_GATE_VERSION
"${HUNTER_GATE_URL}"
)
string(COMPARE EQUAL "${HUNTER_GATE_VERSION}" "" _is_empty)
if(_is_empty)
set(HUNTER_GATE_VERSION "unknown")
endif()
hunter_gate_self(
"${HUNTER_GATE_ROOT}"
"${HUNTER_GATE_VERSION}"
"${HUNTER_GATE_SHA1}"
_hunter_self
)
set(_master_location "${_hunter_self}/cmake/Hunter")
if(EXISTS "${HUNTER_GATE_ROOT}/cmake/Hunter")
# Hunter downloaded manually (e.g. by 'git clone')
set(_unused "xxxxxxxxxx")
set(HUNTER_GATE_SHA1 "${_unused}")
set(HUNTER_GATE_VERSION "${_unused}")
else()
get_filename_component(_archive_id_location "${_hunter_self}/.." ABSOLUTE)
set(_done_location "${_archive_id_location}/DONE")
set(_sha1_location "${_archive_id_location}/SHA1")
# Check Hunter already downloaded by HunterGate
if(NOT EXISTS "${_done_location}")
hunter_gate_download("${_archive_id_location}")
endif()
if(NOT EXISTS "${_done_location}")
hunter_gate_internal_error("hunter_gate_download failed")
endif()
if(NOT EXISTS "${_sha1_location}")
hunter_gate_internal_error("${_sha1_location} not found")
endif()
file(READ "${_sha1_location}" _sha1_value)
string(COMPARE EQUAL "${_sha1_value}" "${HUNTER_GATE_SHA1}" _is_equal)
if(NOT _is_equal)
hunter_gate_internal_error(
"Short SHA1 collision:"
" ${_sha1_value} (from ${_sha1_location})"
" ${HUNTER_GATE_SHA1} (HunterGate)"
)
endif()
if(NOT EXISTS "${_master_location}")
hunter_gate_user_error(
"Master file not found:"
" ${_master_location}"
"try to update Hunter/HunterGate"
)
endif()
endif()
include("${_master_location}")
set_property(GLOBAL PROPERTY HUNTER_GATE_DONE YES)
endif()
endmacro()

202
LICENSE Normal file
View File

@ -0,0 +1,202 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

66
bootstrap.cmake Normal file
View File

@ -0,0 +1,66 @@
# Copyright 2018 Pawel Bylica.
# Licensed under the Apache License, Version 2.0. See the LICENSE file.
# Bootstrap the Cable - CMake Boostrap Library.
# Cable version.
#
# This is internal variable automaticaly updated with external tools.
# Use CABLE_VERSION variable if you need this information.
set(version 0.1.4)
# For conveniance, add the parent dir containg CMake modules to module path.
get_filename_component(module_dir ${CMAKE_CURRENT_LIST_DIR} DIRECTORY)
list(APPEND CMAKE_MODULE_PATH ${module_dir})
unset(module_dir)
if(CABLE_VERSION)
# Some other instance of Cable was initialized in the top project.
# Compare versions of the top project and this instances.
if(CABLE_VERSION VERSION_LESS version)
set(severity WARNING)
set(comment "vesion older than ${version}")
elseif(CABLE_VERSION VERSION_EQUAL version)
set(severity STATUS)
set(comment "same version")
else()
set(severity STATUS)
set(comment "version newer than ${version}")
endif()
# Find the name of the top project.
# Make sure the name is not overwritten by multiple nested projects.
if(NOT DEFINED cable_top_project_name)
set(cable_top_project_name ${PROJECT_NAME})
endif()
# Mark this project as nested.
set(PROJECT_IS_NESTED TRUE)
message(
${severity}
"[cable] Parent Cable ${CABLE_VERSION} (${comment}) initialized in `${cable_top_project_name}` project"
)
unset(version)
unset(severity)
unset(comment)
return()
endif()
# Export Cable version.
set(CABLE_VERSION ${version})
# Mark this project as non-nested.
set(PROJECT_IS_NESTED FALSE)
# Add Cable modules to the CMake module path.
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})
message(STATUS "[cable] Cable ${CABLE_VERSION} initialized")
unset(version)

20
buildinfo/buildinfo.c.in Normal file
View File

@ -0,0 +1,20 @@
// Copyright 2018 Pawel Bylica.
// Licensed under the Apache License, Version 2.0. See the LICENSE file.
// Generated by Cable Build Info on @TIMESTAMP@. Do not modify directly.
#include "@NAME@.h"
const struct buildinfo* @FUNCTION_NAME@()
{
static const struct buildinfo buildinfo = {
.project_version = "@PROJECT_VERSION@",
.system_name = "@SYSTEM_NAME@",
.system_processor = "@SYSTEM_PROCESSOR",
.compiler_id = "@COMPILER_ID@",
.compiler_version = "@COMPILER_VERSION@",
.build_type = "@BUILD_TYPE@",
.git_commit_hash = "@GIT_COMMIT_HASH@",
};
return &buildinfo;
}

25
buildinfo/buildinfo.cmake Normal file
View File

@ -0,0 +1,25 @@
# Copyright 2018 Pawel Bylica.
# Licensed under the Apache License, Version 2.0. See the LICENSE file.
# Read the git commit hash from a file. The gitinfo is suppose to update the
# file only if the hash changes.
file(READ ${BINARY_DIR}/git_commit_hash.txt GIT_COMMIT_HASH)
string(TOLOWER ${SYSTEM_NAME} SYSTEM_NAME)
string(TOLOWER ${SYSTEM_PROCESSOR} SYSTEM_PROCESSOR)
string(TOLOWER ${COMPILER_ID} COMPILER_ID)
string(TOLOWER ${BUILD_TYPE} BUILD_TYPE)
string(TIMESTAMP TIMESTAMP)
message(
" Project Version: ${PROJECT_VERSION}\n"
" System Name: ${SYSTEM_NAME}\n"
" System Processor: ${SYSTEM_PROCESSOR}\n"
" Compiler ID: ${COMPILER_ID}\n"
" Compiler Version: ${COMPILER_VERSION}\n"
" Build Type: ${BUILD_TYPE}\n"
" Git Commit Hash: ${GIT_COMMIT_HASH}\n"
" Timestamp: ${TIMESTAMP}"
)
configure_file(${CMAKE_CURRENT_LIST_DIR}/buildinfo.c.in ${BINARY_DIR}/${NAME}.c)

28
buildinfo/buildinfo.h.in Normal file
View File

@ -0,0 +1,28 @@
// Copyright 2018 Pawel Bylica.
// Licensed under the Apache License, Version 2.0. See the LICENSE file.
// Generated by Cable Build Info on @TIMESTAMP@. Do not modify directly.
#pragma once
#ifdef __cplusplus
extern "C"
{
#endif
struct buildinfo
{
const char* project_version;
const char* system_name;
const char* system_processor;
const char* compiler_id;
const char* compiler_version;
const char* build_type;
const char* git_commit_hash;
};
const struct buildinfo* @FUNCTION_NAME@();
#ifdef __cplusplus
}
#endif

26
buildinfo/gitinfo.cmake Normal file
View File

@ -0,0 +1,26 @@
# Copyright 2018 Pawel Bylica.
# Licensed under the Apache License, Version 2.0. See the LICENSE file.
# Execute git only if the tool is available.
if(GIT)
execute_process(
COMMAND ${GIT} rev-parse HEAD
WORKING_DIRECTORY ${SOURCE_DIR}
OUTPUT_VARIABLE commit_hash
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
endif()
set(commit_hash_file ${BINARY_DIR}/git_commit_hash.txt)
if(EXISTS ${commit_hash_file})
file(READ ${commit_hash_file} prev_commit_hash)
else()
# Create empty file, because other targets expect it to exist.
file(WRITE ${commit_hash_file} "")
endif()
if(NOT "${commit_hash}" STREQUAL "${prev_commit_hash}")
file(WRITE ${commit_hash_file} ${commit_hash})
endif()

View File

@ -0,0 +1,17 @@
# Copyright 2018 Pawel Bylica.
# Licensed under the Apache License, Version 2.0. See the LICENSE file.
# Hunter passwords file used by HunterCacheServers.cmake.
# Do not include directly.
hunter_upload_password(
# REPO_OWNER + REPO = https://github.com/ethereum/hunter-cache
REPO_OWNER ethereum
REPO hunter-cache
# USERNAME = https://github.com/hunter-cache-bot
USERNAME hunter-cache-bot
# PASSWORD = GitHub token saved as a secure environment variable
PASSWORD "$ENV{HUNTER_CACHE_TOKEN}"
)

View File

@ -0,0 +1,26 @@
# Copyright 2018 Pawel Bylica.
# Licensed under the Apache License, Version 2.0. See the LICENSE file.
# This module, when included, sets default values for params related to
# Hunter cache servers, including upload options.
# Default Hunter cache servers.
set(HUNTER_CACHE_SERVERS
"https://github.com/ethereum/hunter-cache;https://github.com/ingenue/hunter-cache"
CACHE STRING "Hunter cache servers")
# Default path to Hunter passwords file containing information how to access
# Ethereum's cache server.
set(HUNTER_PASSWORDS_PATH
${CMAKE_CURRENT_LIST_DIR}/HunterCacheServers-passwords.cmake
CACHE STRING "Hunter passwords file")
# In CI builds upload the binaries if the HUNTER_CACHE_TOKEN was decrypted
# (only for branches and internal PRs).
if("$ENV{CI}" AND NOT "$ENV{HUNTER_CACHE_TOKEN}" STREQUAL "")
set(run_upload YES)
else()
set(run_upload NO)
endif()
option(HUNTER_RUN_UPLOAD "Upload binaries to the Hunter cache server" ${run_upload})
unset(run_upload)

View File

@ -0,0 +1,9 @@
# Copyright 2018 Pawel Bylica.
# Licensed under the Apache License, Version 2.0. See the LICENSE file.
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_C_FLAGS -m32 CACHE STRING "C compiler flags" FORCE)
set(CMAKE_CXX_FLAGS -m32 CACHE STRING "C++ compiler flags" FORCE)

6
toolchains/cxx11.cmake Normal file
View File

@ -0,0 +1,6 @@
# Copyright 2018 Pawel Bylica.
# Licensed under the Apache License, Version 2.0. See the LICENSE file.
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(CMAKE_CXX_EXTENSIONS OFF)

2
toolchains/default.cmake Normal file
View File

@ -0,0 +1,2 @@
# Copyright 2018 Pawel Bylica.
# Licensed under the Apache License, Version 2.0. See the LICENSE file.

23
toolchains/mips64.cmake Normal file
View File

@ -0,0 +1,23 @@
# Copyright 2018 Pawel Bylica.
# Licensed under the Apache License, Version 2.0. See the LICENSE file.
set(CMAKE_SYSTEM_PROCESSOR mips64)
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_C_COMPILER mips64-linux-gnuabi64-gcc)
set(CMAKE_CXX_COMPILER mips64-linux-gnuabi64-g++)
set(CMAKE_FIND_ROOT_PATH /usr/mips64-linux-gnuabi64)
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(CMAKE_CXX_EXTENSIONS Off)
if(${CMAKE_VERSION} VERSION_LESS 3.10.0)
# Until CMake 3.10 the FindThreads uses try_run() check of -pthread flag,
# what causes CMake error in crosscompiling mode. Avoid the try_run() check
# by specifying the result up front.
set(THREADS_PTHREAD_ARG TRUE)
endif()