├── .gitignore ├── CableBuildInfo.cmake ├── CableBuildType.cmake ├── CableCompilerSettings.cmake ├── CablePackage.cmake ├── CableToolchains.cmake ├── HunterGate.cmake ├── LICENSE ├── README.md ├── bootstrap.cmake ├── buildinfo ├── buildinfo.c.in ├── buildinfo.cmake ├── buildinfo.h.in ├── buildinfo.json.in ├── buildinfo.ps1.in ├── buildinfo.sh.in ├── gitinfo.cmake └── version.h.in ├── cable.cmake ├── defaults ├── HunterCacheServers-passwords.cmake └── HunterCacheServers.cmake └── toolchains ├── cxx11-32bit.cmake ├── cxx11-c99.cmake ├── cxx11-fpic.cmake ├── cxx11-pic.cmake ├── cxx11.cmake ├── cxx14-32bit.cmake ├── cxx14-pic.cmake ├── cxx14.cmake ├── cxx17-32bit.cmake ├── cxx17-pic.cmake ├── cxx17.cmake ├── default.cmake ├── mips64.cmake └── powerpc64.cmake /.gitignore: -------------------------------------------------------------------------------- 1 | /.idea 2 | -------------------------------------------------------------------------------- /CableBuildInfo.cmake: -------------------------------------------------------------------------------- 1 | # Cable: CMake Bootstrap Library 2 | # Copyright 2019 Pawel Bylica. 3 | # Licensed under the Apache License, Version 2.0. 4 | 5 | # Cable Build Info, version 1.0.0 6 | # 7 | # This CMake module collects build information and provides it in different 8 | # forms: static librar, JSON file, shell scripts. 9 | # 10 | # CHANGELOG 11 | # 12 | # 1.0.0 - 2022-02-12 13 | 14 | include_guard(GLOBAL) 15 | 16 | include(GNUInstallDirs) 17 | 18 | # TODO: From CMake 3.17 the CMAKE_CURRENT_FUNCTION_LIST_DIR can be used instead. 19 | set(cable_buildinfo_template_dir ${CMAKE_CURRENT_LIST_DIR}/buildinfo) 20 | 21 | function(cable_add_buildinfo_library) 22 | 23 | cmake_parse_arguments("" "" PROJECT_NAME;EXPORT "" ${ARGN}) 24 | 25 | if(NOT _PROJECT_NAME) 26 | message(FATAL_ERROR "The PROJECT_NAME argument missing") 27 | endif() 28 | 29 | # Come up with the target and the C function names. 30 | set(name ${_PROJECT_NAME}-buildinfo) 31 | set(FUNCTION_NAME ${_PROJECT_NAME}_get_buildinfo) 32 | 33 | set(output_dir ${CMAKE_CURRENT_BINARY_DIR}/${_PROJECT_NAME}) 34 | set(header_file ${output_dir}/buildinfo.h) 35 | set(source_file ${output_dir}/buildinfo.c) 36 | 37 | if(CMAKE_CONFIGURATION_TYPES) 38 | set(build_type ${CMAKE_CFG_INTDIR}) 39 | else() 40 | set(build_type ${CMAKE_BUILD_TYPE}) 41 | endif() 42 | 43 | # Find git here to allow the user to provide hints. 44 | find_package(Git) 45 | 46 | # Git info target. 47 | # 48 | # This target is named -git and is always built. 49 | # The executed script gitinfo.cmake check git status and updates files 50 | # containing git information if anything has changed. 51 | add_custom_target( 52 | ${name}-git 53 | COMMAND ${CMAKE_COMMAND} 54 | -DGIT=${GIT_EXECUTABLE} 55 | -DSOURCE_DIR=${PROJECT_SOURCE_DIR} 56 | -DOUTPUT_DIR=${output_dir} 57 | -P ${cable_buildinfo_template_dir}/gitinfo.cmake 58 | BYPRODUCTS ${output_dir}/gitinfo.txt 59 | ) 60 | 61 | add_custom_command( 62 | COMMENT "Updating ${name}:" 63 | OUTPUT ${source_file} ${output_dir}/buildinfo.json 64 | COMMAND ${CMAKE_COMMAND} 65 | -DOUTPUT_DIR=${output_dir} 66 | -DPROJECT_NAME=${_PROJECT_NAME} 67 | -DFUNCTION_NAME=${FUNCTION_NAME} 68 | -DPROJECT_VERSION=${PROJECT_VERSION} 69 | -DSYSTEM_NAME=${CMAKE_SYSTEM_NAME} 70 | -DSYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR} 71 | -DCOMPILER_ID=${CMAKE_CXX_COMPILER_ID} 72 | -DCOMPILER_VERSION=${CMAKE_CXX_COMPILER_VERSION} 73 | -DBUILD_TYPE=${build_type} 74 | -P ${cable_buildinfo_template_dir}/buildinfo.cmake 75 | DEPENDS 76 | ${cable_buildinfo_template_dir}/buildinfo.cmake 77 | ${cable_buildinfo_template_dir}/buildinfo.c.in 78 | ${cable_buildinfo_template_dir}/buildinfo.json.in 79 | ${cable_buildinfo_template_dir}/version.h.in 80 | ${name}-git 81 | ${output_dir}/gitinfo.txt 82 | ) 83 | 84 | string(TIMESTAMP TIMESTAMP) 85 | configure_file(${cable_buildinfo_template_dir}/buildinfo.h.in ${header_file}) 86 | 87 | # Add buildinfo library under given name. 88 | # Make is static and do not build by default until some other target will actually use it. 89 | add_library(${name} STATIC ${source_file} ${header_file}) 90 | 91 | target_include_directories(${name} PUBLIC $) 92 | set_target_properties( 93 | ${name} PROPERTIES 94 | LIBRARY_OUTPUT_DIRECTORY ${output_dir} 95 | ARCHIVE_OUTPUT_DIRECTORY ${output_dir} 96 | ) 97 | 98 | if(_EXPORT) 99 | install(TARGETS ${name} EXPORT ${_EXPORT} 100 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} 101 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} 102 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} 103 | ) 104 | endif() 105 | 106 | endfunction() 107 | -------------------------------------------------------------------------------- /CableBuildType.cmake: -------------------------------------------------------------------------------- 1 | # Cable: CMake Bootstrap Library 2 | # Copyright 2018 Pawel Bylica. 3 | # Licensed under the Apache License, Version 2.0. 4 | 5 | # Cable Build Type, version 1.0.1 6 | # 7 | # This CMake module helps with setting default build type 8 | # and build configurations for multi-configuration generators. 9 | # Use cable_set_build_type(). 10 | # 11 | # CHANGELOG 12 | # 13 | # 1.0.1 - 2021-05-20 14 | # - Fix usage in CMake sub-project. 15 | # 16 | # 1.0.0 - 2020-01-02 17 | 18 | 19 | if(cable_build_type_included) 20 | return() 21 | endif() 22 | set(cable_build_type_included TRUE) 23 | 24 | macro(cable_set_build_type) 25 | if(NOT PROJECT_SOURCE_DIR) # Before the main project(). 26 | cmake_parse_arguments(build_type "" DEFAULT CONFIGURATION_TYPES ${ARGN}) 27 | 28 | if(CMAKE_CONFIGURATION_TYPES) 29 | if(build_type_CONFIGURATION_TYPES) 30 | set( 31 | CMAKE_CONFIGURATION_TYPES 32 | ${build_type_CONFIGURATION_TYPES} 33 | CACHE 34 | STRING 35 | "Available configurations for multi-configuration generators" 36 | FORCE 37 | ) 38 | endif() 39 | message(STATUS "Configurations: ${CMAKE_CONFIGURATION_TYPES}") 40 | else() 41 | if(build_type_DEFAULT AND NOT CMAKE_BUILD_TYPE) 42 | set( 43 | CMAKE_BUILD_TYPE 44 | ${build_type_DEFAULT} 45 | CACHE STRING 46 | "Build type for single-configuration generators" 47 | FORCE 48 | ) 49 | endif() 50 | message(STATUS "Build type: ${CMAKE_BUILD_TYPE}") 51 | endif() 52 | elseif(PROJECT_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) # After the main project(). 53 | message(FATAL_ERROR "cable_set_build_type() must be used before project()") 54 | endif() # Sub-project - silently ignore. 55 | endmacro() 56 | -------------------------------------------------------------------------------- /CableCompilerSettings.cmake: -------------------------------------------------------------------------------- 1 | # Cable: CMake Bootstrap Library 2 | # Copyright 2018 Pawel Bylica. 3 | # Licensed under the Apache License, Version 2.0. 4 | 5 | # Cable Compiler Settings, version 1.2.0 6 | # 7 | # This CMake module provides default configuration (with some options) 8 | # for C/C++ compilers. Use cable_configure_compiler(). 9 | # 10 | # CHANGELOG 11 | # 12 | # 1.2.0 - 2023-02-25 13 | # - Do not set -Werror nor /WX. This has been standardized in CMake 3.24 as CMAKE_COMPILE_WARNING_AS_ERROR. 14 | # - Keep compiler warnings about unknown pragmas. 15 | # - Keep MSVC warning C5030: attribute is not recognized. It should be disabled in source code. 16 | # - Do not try to erase MSVC default warning level /W3. This is not set since CMake 3.15 (CMP0092). 17 | # - Drop explicit -Wimplicit-fallthrough. It is a part of -Wextra. 18 | # - Use PROJECT_IS_TOP_LEVEL if available (or define it). 19 | # - Use include_guard(). 20 | # 21 | # 1.1.0 - 2020-06-20 22 | # - Allow unknown C++ attributes in MSVC compiler. 23 | # - Option -DEXCEPTIONS=OFF to disable C++ exceptions support (GCC, clang). 24 | # - Option -DRTTI=OFF to disable RTTI support (GCC, clang). 25 | # 26 | # 1.0.1 - 2020-01-30 27 | # - Do not explicitly set -mtune=generic, this is default anyway. 28 | # 29 | # 1.0.0 - 2019-12-20 30 | 31 | include_guard() 32 | include(CheckCXXCompilerFlag) 33 | 34 | # Adds CXX compiler flag if the flag is supported by the compiler. 35 | # 36 | # This is effectively a combination of CMake's check_cxx_compiler_flag() 37 | # and add_compile_options(): 38 | # 39 | # if(check_cxx_compiler_flag(flag)) 40 | # add_compile_options(flag) 41 | # 42 | function(cable_add_cxx_compiler_flag_if_supported FLAG) 43 | # Remove leading - or / from the flag name. 44 | string(REGEX REPLACE "^-|/" "" name ${FLAG}) 45 | check_cxx_compiler_flag(${FLAG} ${name}) 46 | if(${name}) 47 | add_compile_options(${FLAG}) 48 | endif() 49 | 50 | # If the optional argument passed, store the result there. 51 | if(ARGV1) 52 | set(${ARGV1} ${name} PARENT_SCOPE) 53 | endif() 54 | endfunction() 55 | 56 | 57 | # Configures the compiler with default flags. 58 | macro(cable_configure_compiler) 59 | if(NOT PROJECT_SOURCE_DIR) 60 | message(FATAL_ERROR "cable_configure_compiler() must be used after project()") 61 | endif() 62 | 63 | if(NOT DEFINED PROJECT_IS_TOP_LEVEL) 64 | # Define PROJECT_IS_TOP_LEVEL (since CMake 3.21) if not available. 65 | string(COMPARE EQUAL ${CMAKE_SOURCE_DIR} ${PROJECT_SOURCE_DIR} PROJECT_IS_TOP_LEVEL) 66 | endif() 67 | 68 | if(PROJECT_IS_TOP_LEVEL) 69 | # Do this configuration only in the top level project. 70 | 71 | cmake_parse_arguments(cable "NO_CONVERSION_WARNINGS;NO_STACK_PROTECTION;NO_PEDANTIC" "" "" ${ARGN}) 72 | 73 | if(cable_UNPARSED_ARGUMENTS) 74 | message(FATAL_ERROR "cable_configure_compiler: Unknown options: ${cable_UNPARSED_ARGUMENTS}") 75 | endif() 76 | 77 | # Set helper variables recognizing C++ compilers. 78 | if(${CMAKE_CXX_COMPILER_ID} STREQUAL GNU) 79 | set(CABLE_COMPILER_GNU TRUE) 80 | elseif(${CMAKE_CXX_COMPILER_ID} MATCHES Clang) 81 | # This matches both clang and AppleClang. 82 | set(CABLE_COMPILER_CLANG TRUE) 83 | endif() 84 | 85 | if(CABLE_COMPILER_GNU OR CABLE_COMPILER_CLANG) 86 | set(CABLE_COMPILER_GNULIKE TRUE) 87 | endif() 88 | 89 | if(CABLE_COMPILER_GNULIKE) 90 | 91 | if(NOT cable_NO_PEDANTIC) 92 | add_compile_options(-Wpedantic) 93 | endif() 94 | 95 | # Enable basic warnings. 96 | add_compile_options(-Wall -Wextra -Wshadow) 97 | 98 | if(NOT cable_NO_CONVERSION_WARNINGS) 99 | # Enable conversion warnings if not explicitly disabled. 100 | add_compile_options(-Wconversion -Wsign-conversion) 101 | endif() 102 | 103 | # Stack protection. 104 | check_cxx_compiler_flag(-fstack-protector fstack-protector) 105 | if(fstack-protector) 106 | # The compiler supports stack protection options. 107 | if(cable_NO_STACK_PROTECTION) 108 | # Stack protection explicitly disabled. 109 | # Add "no" flag, because in some configuration the compiler has it enabled by default. 110 | add_compile_options(-fno-stack-protector) 111 | else() 112 | # Try enabling the "strong" variant. 113 | cable_add_cxx_compiler_flag_if_supported(-fstack-protector-strong have_stack_protector_strong_support) 114 | if(NOT have_stack_protector_strong_support) 115 | # Fallback to standard variant if "strong" not available. 116 | add_compile_options(-fstack-protector) 117 | endif() 118 | endif() 119 | endif() 120 | 121 | elseif(MSVC) 122 | 123 | # Enable basic warnings. 124 | add_compile_options(/W4) 125 | 126 | endif() 127 | 128 | option(EXCEPTIONS "Build with exceptions support" ON) 129 | if(NOT EXCEPTIONS) 130 | add_compile_options(-fno-exceptions) 131 | endif() 132 | 133 | option(RTTI "Build with RTTI support" ON) 134 | if(NOT RTTI) 135 | add_compile_options(-fno-rtti) 136 | endif() 137 | 138 | # Option for arch=native. 139 | option(NATIVE "Build for native CPU" OFF) 140 | if(NATIVE) 141 | if(MSVC) 142 | add_compile_options(-arch:AVX) 143 | else() 144 | add_compile_options(-mtune=native -march=native) 145 | endif() 146 | endif() 147 | 148 | # Sanitizers support. 149 | set(SANITIZE OFF CACHE STRING "Build with the specified sanitizer") 150 | if(SANITIZE) 151 | # Set the linker flags first, they are required to properly test the compiler flag. 152 | set(CMAKE_SHARED_LINKER_FLAGS "-fsanitize=${SANITIZE} ${CMAKE_SHARED_LINKER_FLAGS}") 153 | set(CMAKE_EXE_LINKER_FLAGS "-fsanitize=${SANITIZE} ${CMAKE_EXE_LINKER_FLAGS}") 154 | 155 | set(test_name have_fsanitize_${SANITIZE}) 156 | check_cxx_compiler_flag(-fsanitize=${SANITIZE} ${test_name}) 157 | if(NOT ${test_name}) 158 | message(FATAL_ERROR "Unsupported sanitizer: ${SANITIZE}") 159 | endif() 160 | add_compile_options(-fno-omit-frame-pointer -fsanitize=${SANITIZE}) 161 | 162 | set(blacklist_file ${PROJECT_SOURCE_DIR}/sanitizer-blacklist.txt) 163 | if(EXISTS ${blacklist_file}) 164 | cable_add_cxx_compiler_flag_if_supported(-fsanitize-blacklist=${blacklist_file}) 165 | endif() 166 | unset(blacklist_file) 167 | endif() 168 | 169 | # The "Coverage" build type. 170 | if(CABLE_COMPILER_CLANG) 171 | set(CMAKE_CXX_FLAGS_COVERAGE "-fprofile-instr-generate -fcoverage-mapping") 172 | elseif(CABLE_COMPILER_GNU) 173 | set(CMAKE_CXX_FLAGS_COVERAGE "--coverage") 174 | endif() 175 | endif() 176 | endmacro() 177 | -------------------------------------------------------------------------------- /CablePackage.cmake: -------------------------------------------------------------------------------- 1 | # Cable: CMake Bootstrap Library 2 | # Copyright 2019-2020 Pawel Bylica. 3 | # Licensed under the Apache License, Version 2.0. 4 | 5 | # Cable Package, version 1.0.0 6 | # 7 | # This CMake module provides default configuration for CPack 8 | # 9 | # CHANGELOG 10 | # 11 | # 1.0.0 - 2020-05-06 12 | 13 | if(cable_package_included) 14 | return() 15 | endif() 16 | set(cable_package_included TRUE) 17 | 18 | # Configures CPack to build the archive package. 19 | macro(cable_add_archive_package) 20 | if(WIN32) 21 | set(CPACK_GENERATOR ZIP) 22 | set(CPACK_SOURCE_GENERATOR ZIP) 23 | else() 24 | set(CPACK_GENERATOR TGZ) 25 | set(CPACK_SOURCE_GENERATOR TGZ) 26 | endif() 27 | string(TOLOWER ${CMAKE_SYSTEM_NAME} system_name) 28 | string(TOLOWER ${CMAKE_SYSTEM_PROCESSOR} system_processor) 29 | set(CPACK_PACKAGE_FILE_NAME ${PROJECT_NAME}-${PROJECT_VERSION}-${system_name}-${system_processor}) 30 | set(CPACK_SOURCE_PACKAGE_FILE_NAME ${PROJECT_NAME}-${PROJECT_VERSION}-source) 31 | set(CPACK_PACKAGE_CHECKSUM SHA256) 32 | set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY FALSE) 33 | unset(system_name) 34 | unset(system_processor) 35 | include(CPack) 36 | endmacro() 37 | -------------------------------------------------------------------------------- /CableToolchains.cmake: -------------------------------------------------------------------------------- 1 | # Cable: CMake Bootstrap Library. 2 | # Copyright 2018 Pawel Bylica. 3 | # Licensed under the Apache License, Version 2.0. See the LICENSE file. 4 | 5 | set(cable_toolchain_dir ${CMAKE_CURRENT_LIST_DIR}/toolchains) 6 | 7 | function(cable_configure_toolchain) 8 | if(NOT PROJECT_IS_NESTED) 9 | # Do this configuration only in the top project. 10 | 11 | cmake_parse_arguments("" "" "DEFAULT" "" ${ARGN}) 12 | 13 | set(default_toolchain default) 14 | if(_DEFAULT) 15 | set(default_toolchain ${_DEFAULT}) 16 | endif() 17 | 18 | set(TOOLCHAIN ${default_toolchain} CACHE STRING "CMake toolchain") 19 | 20 | set(toolchain_file toolchains/${TOOLCHAIN}.cmake) 21 | foreach(path ${CMAKE_MODULE_PATH}) 22 | if(EXISTS "${path}/${toolchain_file}") 23 | set(toolchain_file "${path}/${toolchain_file}") 24 | break() 25 | endif() 26 | endforeach() 27 | 28 | cable_debug("Toolchain file: ${toolchain_file}") 29 | set(CMAKE_TOOLCHAIN_FILE ${toolchain_file} CACHE FILEPATH "CMake toolchain file") 30 | endif() 31 | endfunction() 32 | -------------------------------------------------------------------------------- /HunterGate.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2019, Ruslan Baratov 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | # This is a gate file to Hunter package manager. 26 | # Include this file using `include` command and add package you need, example: 27 | # 28 | # cmake_minimum_required(VERSION 3.2) 29 | # 30 | # include("cmake/HunterGate.cmake") 31 | # HunterGate( 32 | # URL "https://github.com/path/to/hunter/archive.tar.gz" 33 | # SHA1 "798501e983f14b28b10cda16afa4de69eee1da1d" 34 | # ) 35 | # 36 | # project(MyProject) 37 | # 38 | # hunter_add_package(Foo) 39 | # hunter_add_package(Boo COMPONENTS Bar Baz) 40 | # 41 | # Projects: 42 | # * https://github.com/hunter-packages/gate/ 43 | # * https://github.com/ruslo/hunter 44 | 45 | option(HUNTER_ENABLED "Enable Hunter package manager support" ON) 46 | 47 | if(HUNTER_ENABLED) 48 | if(CMAKE_VERSION VERSION_LESS "3.2") 49 | message( 50 | FATAL_ERROR 51 | "At least CMake version 3.2 required for Hunter dependency management." 52 | " Update CMake or set HUNTER_ENABLED to OFF." 53 | ) 54 | endif() 55 | endif() 56 | 57 | include(CMakeParseArguments) # cmake_parse_arguments 58 | 59 | option(HUNTER_STATUS_PRINT "Print working status" ON) 60 | option(HUNTER_STATUS_DEBUG "Print a lot info" OFF) 61 | option(HUNTER_TLS_VERIFY "Enable/disable TLS certificate checking on downloads" ON) 62 | 63 | set(HUNTER_ERROR_PAGE "https://docs.hunter.sh/en/latest/reference/errors") 64 | 65 | function(hunter_gate_status_print) 66 | if(HUNTER_STATUS_PRINT OR HUNTER_STATUS_DEBUG) 67 | foreach(print_message ${ARGV}) 68 | message(STATUS "[hunter] ${print_message}") 69 | endforeach() 70 | endif() 71 | endfunction() 72 | 73 | function(hunter_gate_status_debug) 74 | if(HUNTER_STATUS_DEBUG) 75 | foreach(print_message ${ARGV}) 76 | string(TIMESTAMP timestamp) 77 | message(STATUS "[hunter *** DEBUG *** ${timestamp}] ${print_message}") 78 | endforeach() 79 | endif() 80 | endfunction() 81 | 82 | function(hunter_gate_error_page error_page) 83 | message("------------------------------ ERROR ------------------------------") 84 | message(" ${HUNTER_ERROR_PAGE}/${error_page}.html") 85 | message("-------------------------------------------------------------------") 86 | message("") 87 | message(FATAL_ERROR "") 88 | endfunction() 89 | 90 | function(hunter_gate_internal_error) 91 | message("") 92 | foreach(print_message ${ARGV}) 93 | message("[hunter ** INTERNAL **] ${print_message}") 94 | endforeach() 95 | message("[hunter ** INTERNAL **] [Directory:${CMAKE_CURRENT_LIST_DIR}]") 96 | message("") 97 | hunter_gate_error_page("error.internal") 98 | endfunction() 99 | 100 | function(hunter_gate_fatal_error) 101 | cmake_parse_arguments(hunter "" "ERROR_PAGE" "" "${ARGV}") 102 | if("${hunter_ERROR_PAGE}" STREQUAL "") 103 | hunter_gate_internal_error("Expected ERROR_PAGE") 104 | endif() 105 | message("") 106 | foreach(x ${hunter_UNPARSED_ARGUMENTS}) 107 | message("[hunter ** FATAL ERROR **] ${x}") 108 | endforeach() 109 | message("[hunter ** FATAL ERROR **] [Directory:${CMAKE_CURRENT_LIST_DIR}]") 110 | message("") 111 | hunter_gate_error_page("${hunter_ERROR_PAGE}") 112 | endfunction() 113 | 114 | function(hunter_gate_user_error) 115 | hunter_gate_fatal_error(${ARGV} ERROR_PAGE "error.incorrect.input.data") 116 | endfunction() 117 | 118 | function(hunter_gate_self root version sha1 result) 119 | string(COMPARE EQUAL "${root}" "" is_bad) 120 | if(is_bad) 121 | hunter_gate_internal_error("root is empty") 122 | endif() 123 | 124 | string(COMPARE EQUAL "${version}" "" is_bad) 125 | if(is_bad) 126 | hunter_gate_internal_error("version is empty") 127 | endif() 128 | 129 | string(COMPARE EQUAL "${sha1}" "" is_bad) 130 | if(is_bad) 131 | hunter_gate_internal_error("sha1 is empty") 132 | endif() 133 | 134 | string(SUBSTRING "${sha1}" 0 7 archive_id) 135 | 136 | set( 137 | hunter_self 138 | "${root}/_Base/Download/Hunter/${version}/${archive_id}/Unpacked" 139 | ) 140 | 141 | set("${result}" "${hunter_self}" PARENT_SCOPE) 142 | endfunction() 143 | 144 | # Set HUNTER_GATE_ROOT cmake variable to suitable value. 145 | function(hunter_gate_detect_root) 146 | # Check CMake variable 147 | string(COMPARE NOTEQUAL "${HUNTER_ROOT}" "" not_empty) 148 | if(not_empty) 149 | set(HUNTER_GATE_ROOT "${HUNTER_ROOT}" PARENT_SCOPE) 150 | hunter_gate_status_debug("HUNTER_ROOT detected by cmake variable") 151 | return() 152 | endif() 153 | 154 | # Check environment variable 155 | string(COMPARE NOTEQUAL "$ENV{HUNTER_ROOT}" "" not_empty) 156 | if(not_empty) 157 | set(HUNTER_GATE_ROOT "$ENV{HUNTER_ROOT}" PARENT_SCOPE) 158 | hunter_gate_status_debug("HUNTER_ROOT detected by environment variable") 159 | return() 160 | endif() 161 | 162 | # Check HOME environment variable 163 | string(COMPARE NOTEQUAL "$ENV{HOME}" "" result) 164 | if(result) 165 | set(HUNTER_GATE_ROOT "$ENV{HOME}/.hunter" PARENT_SCOPE) 166 | hunter_gate_status_debug("HUNTER_ROOT set using HOME environment variable") 167 | return() 168 | endif() 169 | 170 | # Check SYSTEMDRIVE and USERPROFILE environment variable (windows only) 171 | if(WIN32) 172 | string(COMPARE NOTEQUAL "$ENV{SYSTEMDRIVE}" "" result) 173 | if(result) 174 | set(HUNTER_GATE_ROOT "$ENV{SYSTEMDRIVE}/.hunter" PARENT_SCOPE) 175 | hunter_gate_status_debug( 176 | "HUNTER_ROOT set using SYSTEMDRIVE environment variable" 177 | ) 178 | return() 179 | endif() 180 | 181 | string(COMPARE NOTEQUAL "$ENV{USERPROFILE}" "" result) 182 | if(result) 183 | set(HUNTER_GATE_ROOT "$ENV{USERPROFILE}/.hunter" PARENT_SCOPE) 184 | hunter_gate_status_debug( 185 | "HUNTER_ROOT set using USERPROFILE environment variable" 186 | ) 187 | return() 188 | endif() 189 | endif() 190 | 191 | hunter_gate_fatal_error( 192 | "Can't detect HUNTER_ROOT" 193 | ERROR_PAGE "error.detect.hunter.root" 194 | ) 195 | endfunction() 196 | 197 | function(hunter_gate_download dir) 198 | string( 199 | COMPARE 200 | NOTEQUAL 201 | "$ENV{HUNTER_DISABLE_AUTOINSTALL}" 202 | "" 203 | disable_autoinstall 204 | ) 205 | if(disable_autoinstall AND NOT HUNTER_RUN_INSTALL) 206 | hunter_gate_fatal_error( 207 | "Hunter not found in '${dir}'" 208 | "Set HUNTER_RUN_INSTALL=ON to auto-install it from '${HUNTER_GATE_URL}'" 209 | "Settings:" 210 | " HUNTER_ROOT: ${HUNTER_GATE_ROOT}" 211 | " HUNTER_SHA1: ${HUNTER_GATE_SHA1}" 212 | ERROR_PAGE "error.run.install" 213 | ) 214 | endif() 215 | string(COMPARE EQUAL "${dir}" "" is_bad) 216 | if(is_bad) 217 | hunter_gate_internal_error("Empty 'dir' argument") 218 | endif() 219 | 220 | string(COMPARE EQUAL "${HUNTER_GATE_SHA1}" "" is_bad) 221 | if(is_bad) 222 | hunter_gate_internal_error("HUNTER_GATE_SHA1 empty") 223 | endif() 224 | 225 | string(COMPARE EQUAL "${HUNTER_GATE_URL}" "" is_bad) 226 | if(is_bad) 227 | hunter_gate_internal_error("HUNTER_GATE_URL empty") 228 | endif() 229 | 230 | set(done_location "${dir}/DONE") 231 | set(sha1_location "${dir}/SHA1") 232 | 233 | set(build_dir "${dir}/Build") 234 | set(cmakelists "${dir}/CMakeLists.txt") 235 | 236 | hunter_gate_status_debug("Locking directory: ${dir}") 237 | file(LOCK "${dir}" DIRECTORY GUARD FUNCTION) 238 | hunter_gate_status_debug("Lock done") 239 | 240 | if(EXISTS "${done_location}") 241 | # while waiting for lock other instance can do all the job 242 | hunter_gate_status_debug("File '${done_location}' found, skip install") 243 | return() 244 | endif() 245 | 246 | file(REMOVE_RECURSE "${build_dir}") 247 | file(REMOVE_RECURSE "${cmakelists}") 248 | 249 | file(MAKE_DIRECTORY "${build_dir}") # check directory permissions 250 | 251 | # Disabling languages speeds up a little bit, reduces noise in the output 252 | # and avoids path too long windows error 253 | file( 254 | WRITE 255 | "${cmakelists}" 256 | "cmake_minimum_required(VERSION 3.2)\n" 257 | "project(HunterDownload LANGUAGES NONE)\n" 258 | "include(ExternalProject)\n" 259 | "ExternalProject_Add(\n" 260 | " Hunter\n" 261 | " URL\n" 262 | " \"${HUNTER_GATE_URL}\"\n" 263 | " URL_HASH\n" 264 | " SHA1=${HUNTER_GATE_SHA1}\n" 265 | " DOWNLOAD_DIR\n" 266 | " \"${dir}\"\n" 267 | " TLS_VERIFY\n" 268 | " ${HUNTER_TLS_VERIFY}\n" 269 | " SOURCE_DIR\n" 270 | " \"${dir}/Unpacked\"\n" 271 | " CONFIGURE_COMMAND\n" 272 | " \"\"\n" 273 | " BUILD_COMMAND\n" 274 | " \"\"\n" 275 | " INSTALL_COMMAND\n" 276 | " \"\"\n" 277 | ")\n" 278 | ) 279 | 280 | if(HUNTER_STATUS_DEBUG) 281 | set(logging_params "") 282 | else() 283 | set(logging_params OUTPUT_QUIET) 284 | endif() 285 | 286 | hunter_gate_status_debug("Run generate") 287 | 288 | # Need to add toolchain file too. 289 | # Otherwise on Visual Studio + MDD this will fail with error: 290 | # "Could not find an appropriate version of the Windows 10 SDK installed on this machine" 291 | if(EXISTS "${CMAKE_TOOLCHAIN_FILE}") 292 | get_filename_component(absolute_CMAKE_TOOLCHAIN_FILE "${CMAKE_TOOLCHAIN_FILE}" ABSOLUTE) 293 | set(toolchain_arg "-DCMAKE_TOOLCHAIN_FILE=${absolute_CMAKE_TOOLCHAIN_FILE}") 294 | else() 295 | # 'toolchain_arg' can't be empty 296 | set(toolchain_arg "-DCMAKE_TOOLCHAIN_FILE=") 297 | endif() 298 | 299 | string(COMPARE EQUAL "${CMAKE_MAKE_PROGRAM}" "" no_make) 300 | if(no_make) 301 | set(make_arg "") 302 | else() 303 | # Test case: remove Ninja from PATH but set it via CMAKE_MAKE_PROGRAM 304 | set(make_arg "-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}") 305 | endif() 306 | 307 | execute_process( 308 | COMMAND 309 | "${CMAKE_COMMAND}" 310 | "-H${dir}" 311 | "-B${build_dir}" 312 | "-G${CMAKE_GENERATOR}" 313 | "${toolchain_arg}" 314 | ${make_arg} 315 | WORKING_DIRECTORY "${dir}" 316 | RESULT_VARIABLE download_result 317 | ${logging_params} 318 | ) 319 | 320 | if(NOT download_result EQUAL 0) 321 | hunter_gate_internal_error( 322 | "Configure project failed." 323 | "To reproduce the error run: ${CMAKE_COMMAND} -H${dir} -B${build_dir} -G${CMAKE_GENERATOR} ${toolchain_arg} ${make_arg}" 324 | "In directory ${dir}" 325 | ) 326 | endif() 327 | 328 | hunter_gate_status_print( 329 | "Initializing Hunter workspace (${HUNTER_GATE_SHA1})" 330 | " ${HUNTER_GATE_URL}" 331 | " -> ${dir}" 332 | ) 333 | execute_process( 334 | COMMAND "${CMAKE_COMMAND}" --build "${build_dir}" 335 | WORKING_DIRECTORY "${dir}" 336 | RESULT_VARIABLE download_result 337 | ${logging_params} 338 | ) 339 | 340 | if(NOT download_result EQUAL 0) 341 | hunter_gate_internal_error("Build project failed") 342 | endif() 343 | 344 | file(REMOVE_RECURSE "${build_dir}") 345 | file(REMOVE_RECURSE "${cmakelists}") 346 | 347 | file(WRITE "${sha1_location}" "${HUNTER_GATE_SHA1}") 348 | file(WRITE "${done_location}" "DONE") 349 | 350 | hunter_gate_status_debug("Finished") 351 | endfunction() 352 | 353 | # Must be a macro so master file 'cmake/Hunter' can 354 | # apply all variables easily just by 'include' command 355 | # (otherwise PARENT_SCOPE magic needed) 356 | macro(HunterGate) 357 | if(HUNTER_GATE_DONE) 358 | # variable HUNTER_GATE_DONE set explicitly for external project 359 | # (see `hunter_download`) 360 | set_property(GLOBAL PROPERTY HUNTER_GATE_DONE YES) 361 | endif() 362 | 363 | # First HunterGate command will init Hunter, others will be ignored 364 | get_property(_hunter_gate_done GLOBAL PROPERTY HUNTER_GATE_DONE SET) 365 | 366 | if(NOT HUNTER_ENABLED) 367 | # Empty function to avoid error "unknown function" 368 | function(hunter_add_package) 369 | endfunction() 370 | 371 | set( 372 | _hunter_gate_disabled_mode_dir 373 | "${CMAKE_CURRENT_LIST_DIR}/cmake/Hunter/disabled-mode" 374 | ) 375 | if(EXISTS "${_hunter_gate_disabled_mode_dir}") 376 | hunter_gate_status_debug( 377 | "Adding \"disabled-mode\" modules: ${_hunter_gate_disabled_mode_dir}" 378 | ) 379 | list(APPEND CMAKE_PREFIX_PATH "${_hunter_gate_disabled_mode_dir}") 380 | endif() 381 | elseif(_hunter_gate_done) 382 | hunter_gate_status_debug("Secondary HunterGate (use old settings)") 383 | hunter_gate_self( 384 | "${HUNTER_CACHED_ROOT}" 385 | "${HUNTER_VERSION}" 386 | "${HUNTER_SHA1}" 387 | _hunter_self 388 | ) 389 | include("${_hunter_self}/cmake/Hunter") 390 | else() 391 | set(HUNTER_GATE_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}") 392 | 393 | string(COMPARE NOTEQUAL "${PROJECT_NAME}" "" _have_project_name) 394 | if(_have_project_name) 395 | hunter_gate_fatal_error( 396 | "Please set HunterGate *before* 'project' command. " 397 | "Detected project: ${PROJECT_NAME}" 398 | ERROR_PAGE "error.huntergate.before.project" 399 | ) 400 | endif() 401 | 402 | cmake_parse_arguments( 403 | HUNTER_GATE "LOCAL" "URL;SHA1;GLOBAL;FILEPATH" "" ${ARGV} 404 | ) 405 | 406 | string(COMPARE EQUAL "${HUNTER_GATE_SHA1}" "" _empty_sha1) 407 | string(COMPARE EQUAL "${HUNTER_GATE_URL}" "" _empty_url) 408 | string( 409 | COMPARE 410 | NOTEQUAL 411 | "${HUNTER_GATE_UNPARSED_ARGUMENTS}" 412 | "" 413 | _have_unparsed 414 | ) 415 | string(COMPARE NOTEQUAL "${HUNTER_GATE_GLOBAL}" "" _have_global) 416 | string(COMPARE NOTEQUAL "${HUNTER_GATE_FILEPATH}" "" _have_filepath) 417 | 418 | if(_have_unparsed) 419 | hunter_gate_user_error( 420 | "HunterGate unparsed arguments: ${HUNTER_GATE_UNPARSED_ARGUMENTS}" 421 | ) 422 | endif() 423 | if(_empty_sha1) 424 | hunter_gate_user_error("SHA1 suboption of HunterGate is mandatory") 425 | endif() 426 | if(_empty_url) 427 | hunter_gate_user_error("URL suboption of HunterGate is mandatory") 428 | endif() 429 | if(_have_global) 430 | if(HUNTER_GATE_LOCAL) 431 | hunter_gate_user_error("Unexpected LOCAL (already has GLOBAL)") 432 | endif() 433 | if(_have_filepath) 434 | hunter_gate_user_error("Unexpected FILEPATH (already has GLOBAL)") 435 | endif() 436 | endif() 437 | if(HUNTER_GATE_LOCAL) 438 | if(_have_global) 439 | hunter_gate_user_error("Unexpected GLOBAL (already has LOCAL)") 440 | endif() 441 | if(_have_filepath) 442 | hunter_gate_user_error("Unexpected FILEPATH (already has LOCAL)") 443 | endif() 444 | endif() 445 | if(_have_filepath) 446 | if(_have_global) 447 | hunter_gate_user_error("Unexpected GLOBAL (already has FILEPATH)") 448 | endif() 449 | if(HUNTER_GATE_LOCAL) 450 | hunter_gate_user_error("Unexpected LOCAL (already has FILEPATH)") 451 | endif() 452 | endif() 453 | 454 | hunter_gate_detect_root() # set HUNTER_GATE_ROOT 455 | 456 | # Beautify path, fix probable problems with windows path slashes 457 | get_filename_component( 458 | HUNTER_GATE_ROOT "${HUNTER_GATE_ROOT}" ABSOLUTE 459 | ) 460 | hunter_gate_status_debug("HUNTER_ROOT: ${HUNTER_GATE_ROOT}") 461 | if(NOT HUNTER_ALLOW_SPACES_IN_PATH) 462 | string(FIND "${HUNTER_GATE_ROOT}" " " _contain_spaces) 463 | if(NOT _contain_spaces EQUAL -1) 464 | hunter_gate_fatal_error( 465 | "HUNTER_ROOT (${HUNTER_GATE_ROOT}) contains spaces." 466 | "Set HUNTER_ALLOW_SPACES_IN_PATH=ON to skip this error" 467 | "(Use at your own risk!)" 468 | ERROR_PAGE "error.spaces.in.hunter.root" 469 | ) 470 | endif() 471 | endif() 472 | 473 | string( 474 | REGEX 475 | MATCH 476 | "[0-9]+\\.[0-9]+\\.[0-9]+[-_a-z0-9]*" 477 | HUNTER_GATE_VERSION 478 | "${HUNTER_GATE_URL}" 479 | ) 480 | string(COMPARE EQUAL "${HUNTER_GATE_VERSION}" "" _is_empty) 481 | if(_is_empty) 482 | set(HUNTER_GATE_VERSION "unknown") 483 | endif() 484 | 485 | hunter_gate_self( 486 | "${HUNTER_GATE_ROOT}" 487 | "${HUNTER_GATE_VERSION}" 488 | "${HUNTER_GATE_SHA1}" 489 | _hunter_self 490 | ) 491 | 492 | set(_master_location "${_hunter_self}/cmake/Hunter") 493 | get_filename_component(_archive_id_location "${_hunter_self}/.." ABSOLUTE) 494 | set(_done_location "${_archive_id_location}/DONE") 495 | set(_sha1_location "${_archive_id_location}/SHA1") 496 | 497 | # Check Hunter already downloaded by HunterGate 498 | if(NOT EXISTS "${_done_location}") 499 | hunter_gate_download("${_archive_id_location}") 500 | endif() 501 | 502 | if(NOT EXISTS "${_done_location}") 503 | hunter_gate_internal_error("hunter_gate_download failed") 504 | endif() 505 | 506 | if(NOT EXISTS "${_sha1_location}") 507 | hunter_gate_internal_error("${_sha1_location} not found") 508 | endif() 509 | file(READ "${_sha1_location}" _sha1_value) 510 | string(COMPARE EQUAL "${_sha1_value}" "${HUNTER_GATE_SHA1}" _is_equal) 511 | if(NOT _is_equal) 512 | hunter_gate_internal_error( 513 | "Short SHA1 collision:" 514 | " ${_sha1_value} (from ${_sha1_location})" 515 | " ${HUNTER_GATE_SHA1} (HunterGate)" 516 | ) 517 | endif() 518 | if(NOT EXISTS "${_master_location}") 519 | hunter_gate_user_error( 520 | "Master file not found:" 521 | " ${_master_location}" 522 | "try to update Hunter/HunterGate" 523 | ) 524 | endif() 525 | include("${_master_location}") 526 | set_property(GLOBAL PROPERTY HUNTER_GATE_DONE YES) 527 | endif() 528 | endmacro() 529 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Cable 2 | 3 | [![readme style: standard][readme style standard badge]][standard readme] 4 | 5 | > Cable: CMake Bootstrap Library 6 | 7 | Cable is a set of CMake modules and scripts containing common patterns used 8 | in CMake-based C++ projects. The design goal is to be pragmatic rather than 9 | generic so the number of provided options is minimal. The Cable modules are 10 | independent and it is easy to use them individually. 11 | 12 | 13 | ## Table of Contents 14 | 15 | - [Install](#install) 16 | - [Usage](#usage) 17 | - [Maintainer](#maintainer) 18 | - [License](#license) 19 | 20 | 21 | ## Install 22 | 23 | The suggested Cable location is `cmake/cable` relative to your project root directory. 24 | 25 | 26 | ### With cable.cmake script 27 | 28 | Copy [cable.cmake](cable.cmake) script to your project. 29 | Then use it to download individual Cable CMake modules. 30 | 31 | ```bash 32 | ./cable.cmake install CableBuildType 33 | ``` 34 | 35 | 36 | ### As git subtree 37 | 38 | Adding a dependency project as a [git subtree] is just a copy of the source code 39 | done in a bit more systematic way. 40 | 41 | If you are not familiar with managing dependencies with git subtree read the 42 | [Git subtree: the alternative to Git submodule][git subtree tutorial]. 43 | 44 | #### To install 45 | 46 | ```sh 47 | git remote add cable https://github.com/ethereum/cable 48 | git subtree add --prefix cmake/cable cable master --squash 49 | ``` 50 | 51 | #### To update 52 | 53 | ```sh 54 | git subtree pull --prefix cmake/cable cable master --squash 55 | ``` 56 | 57 | ### As git submodule 58 | 59 | Include the Cable library as [git submodule] in your project. 60 | 61 | ```sh 62 | git submodule add https://github.com/ethereum/cable cmake/cable 63 | ``` 64 | 65 | ## Usage 66 | 67 | Cable contains the `bootstrap.cmake` file that initializes the library. 68 | Start by including this file in your main `CMakeLists.txt` from the Cable 69 | submodule/subtree or any other location. The `bootstrap.cmake` must be included 70 | before the `project()` command. After that, you can include and use other 71 | Cable modules. 72 | 73 | ### Example 74 | 75 | ```cmake 76 | cmake_minimum_required(VERSION 3.5) 77 | 78 | include(cmake/cable/bootstrap.cmake) 79 | include(CableBuildType) 80 | 81 | project(tothemoon) 82 | 83 | cable_set_build_type(DEFAULT RelWithDebInfo CONFIGURATION_TYPES Debug Release RelWithDebInfo) 84 | ``` 85 | 86 | 87 | ## Maintainer 88 | 89 | Paweł Bylica [@chfast] 90 | 91 | ## License 92 | 93 | Licensed under the [Apache License, Version 2.0]. 94 | 95 | 96 | [@chfast]: https://github.com/chfast 97 | [Apache License, Version 2.0]: LICENSE 98 | [git submodule]: https://git-scm.com/book/en/v2/Git-Tools-Submodules 99 | [git subtree]: https://github.com/git/git/blob/master/contrib/subtree/git-subtree.txt 100 | [git subtree tutorial]: https://www.atlassian.com/blog/git/alternatives-to-git-submodule-git-subtree 101 | [standard readme]: https://github.com/RichardLitt/standard-readme 102 | 103 | [readme style standard badge]: https://img.shields.io/badge/readme%20style-standard-brightgreen.svg?style=flat-square 104 | -------------------------------------------------------------------------------- /bootstrap.cmake: -------------------------------------------------------------------------------- 1 | # Cable: CMake Bootstrap Library 2 | # Copyright 2019-2020 Pawel Bylica. 3 | # Licensed under the Apache License, Version 2.0. 4 | 5 | # Bootstrap the Cable - CMake Bootstrap Library by including this file. 6 | # e.g. include(cmake/cable/bootstrap.cmake). 7 | 8 | 9 | # Cable version. 10 | # 11 | # This is internal variable automatically updated with external tools. 12 | # Use CABLE_VERSION variable if you need this information. 13 | set(version 0.5.0) 14 | 15 | # For convenience, add the project CMake module dir to module path. 16 | set(module_dir ${CMAKE_CURRENT_SOURCE_DIR}/cmake) 17 | if(EXISTS ${module_dir}) 18 | list(APPEND CMAKE_MODULE_PATH ${module_dir}) 19 | endif() 20 | 21 | # Always add this Cable instance modules to the CMake module path. 22 | list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}) 23 | 24 | if(CABLE_VERSION) 25 | # Some other instance of Cable has been initialized in the top project. 26 | 27 | # Mark this project as nested. 28 | set(PROJECT_IS_NESTED TRUE) 29 | 30 | # Compare versions of the top project and this instances. 31 | if(CABLE_VERSION VERSION_LESS version) 32 | set(comment " (version older than ${version})") 33 | elseif(CABLE_VERSION VERSION_GREATER version) 34 | set(comment " (version newer than ${version})") 35 | endif() 36 | 37 | # Log information about initialization in the top project. 38 | file(RELATIVE_PATH subproject_dir ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) 39 | cable_debug("${subproject_dir}: Cable ${CABLE_VERSION}${comment} already initialized in the top project") 40 | cable_debug("Project CMake modules directory: ${module_dir}") 41 | 42 | unset(version) 43 | unset(module_dir) 44 | unset(comment) 45 | return() 46 | endif() 47 | 48 | 49 | option(CABLE_DEBUG "Enable Cable debug logs" OFF) 50 | 51 | function(cable_log) 52 | message(STATUS "[cable ] ${ARGN}") 53 | endfunction() 54 | 55 | function(cable_debug) 56 | if(CABLE_DEBUG) 57 | message(STATUS "[cable*] ${ARGN}") 58 | endif() 59 | endfunction() 60 | 61 | # Export Cable version. 62 | set(CABLE_VERSION ${version}) 63 | 64 | # Mark this project as non-nested. 65 | set(PROJECT_IS_NESTED FALSE) 66 | 67 | cable_log("Cable ${CABLE_VERSION} initialized") 68 | cable_debug("Project CMake modules directory: ${module_dir}") 69 | 70 | unset(version) 71 | unset(module_dir) 72 | -------------------------------------------------------------------------------- /buildinfo/buildinfo.c.in: -------------------------------------------------------------------------------- 1 | /* Cable: CMake Bootstrap Library. 2 | * Copyright 2018 Pawel Bylica. 3 | * Licensed under the Apache License, Version 2.0. See the LICENSE file. 4 | */ 5 | 6 | /* Generated by Cable Build Info on @TIMESTAMP@. Do not modify directly. */ 7 | 8 | #include "buildinfo.h" 9 | 10 | const struct buildinfo* @FUNCTION_NAME@() 11 | { 12 | static const struct buildinfo buildinfo = { 13 | .project_name = "@PROJECT_NAME@", 14 | .project_version = "@PROJECT_VERSION@", 15 | .project_name_with_version = "@PROJECT_NAME@-@PROJECT_VERSION@", 16 | .git_commit_hash = "@GIT_COMMIT_HASH@", 17 | .git_branch = "@GIT_BRANCH@", 18 | .system_name = "@SYSTEM_NAME@", 19 | .system_processor = "@SYSTEM_PROCESSOR@", 20 | .compiler_id = "@COMPILER_ID@", 21 | .compiler_version = "@COMPILER_VERSION@", 22 | .build_type = "@BUILD_TYPE@", 23 | }; 24 | return &buildinfo; 25 | } 26 | -------------------------------------------------------------------------------- /buildinfo/buildinfo.cmake: -------------------------------------------------------------------------------- 1 | # Cable: CMake Bootstrap Library. 2 | # Copyright 2018-2019 Pawel Bylica. 3 | # Licensed under the Apache License, Version 2.0. 4 | 5 | string(TOUPPER "${PROJECT_NAME}" PROJECT_NAME_UPPERCASE) 6 | string(TOLOWER "${SYSTEM_NAME}" SYSTEM_NAME) 7 | string(TOLOWER "${SYSTEM_PROCESSOR}" SYSTEM_PROCESSOR) 8 | string(TOLOWER "${COMPILER_ID}" COMPILER_ID) 9 | string(TOLOWER "${BUILD_TYPE}" BUILD_TYPE) 10 | string(TIMESTAMP TIMESTAMP) 11 | 12 | # Read the git info from a file. The gitinfo is suppose to update the file 13 | # only if the information has changed. 14 | file(STRINGS ${OUTPUT_DIR}/gitinfo.txt gitinfo) 15 | list(LENGTH gitinfo gitinfo_len) 16 | if(gitinfo_len LESS 3) 17 | message(WARNING "Git info not available") 18 | else() 19 | list(GET gitinfo 0 describe) 20 | list(GET gitinfo 1 GIT_BRANCH) 21 | list(GET gitinfo 2 GIT_ORIGIN_URL) 22 | endif() 23 | 24 | # The output of `git describe --always --long --tags --match=v*`. 25 | string(REGEX MATCH "(v(.+)-([0-9]+)-g)?([0-9a-f]+)(-dirty)?" match "${describe}") 26 | 27 | if(DEFINED describe AND NOT match) 28 | message(WARNING "Cannot parse git describe: ${describe}") 29 | endif() 30 | 31 | set(GIT_LATEST_PROJECT_VERSION ${CMAKE_MATCH_2}) 32 | set(GIT_LATEST_PROJECT_VERSION_DISTANCE ${CMAKE_MATCH_3}) 33 | set(GIT_COMMIT_HASH ${CMAKE_MATCH_4}) 34 | if(CMAKE_MATCH_5) 35 | set(GIT_DIRTY TRUE) 36 | set(dirty_msg " (dirty)") 37 | else() 38 | set(GIT_DIRTY FALSE) 39 | endif() 40 | 41 | if(GIT_COMMIT_HASH) 42 | string(SUBSTRING ${GIT_COMMIT_HASH} 0 8 abbrev) 43 | set(version_commit "+commit.${abbrev}") 44 | if(GIT_DIRTY) 45 | set(version_commit "${version_commit}.dirty") 46 | endif() 47 | endif() 48 | 49 | if(NOT PROJECT_VERSION) 50 | message(WARNING "PROJECT_VERSION not specified") 51 | endif() 52 | 53 | if(PROJECT_VERSION STREQUAL GIT_LATEST_PROJECT_VERSION) 54 | if(${GIT_LATEST_PROJECT_VERSION_DISTANCE} GREATER 0) 55 | set(PROJECT_VERSION "${PROJECT_VERSION}-${GIT_LATEST_PROJECT_VERSION_DISTANCE}${version_commit}") 56 | endif() 57 | else() 58 | if(GIT_LATEST_PROJECT_VERSION) 59 | message(WARNING "Git project version mismatch: '${GIT_LATEST_PROJECT_VERSION}' vs '${PROJECT_VERSION}'") 60 | endif() 61 | set(PROJECT_VERSION "${PROJECT_VERSION}${version_commit}") 62 | endif() 63 | 64 | if(PROJECT_VERSION MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)$") 65 | set(PROJECT_VERSION_IS_PRERELEASE false) 66 | else() 67 | set(PROJECT_VERSION_IS_PRERELEASE true) 68 | set(prerelease_comment " (prerelease)") 69 | endif() 70 | 71 | message( 72 | " Project Version: ${PROJECT_VERSION}${prerelease_comment}\n" 73 | " System Name: ${SYSTEM_NAME}\n" 74 | " System Processor: ${SYSTEM_PROCESSOR}\n" 75 | " Compiler ID: ${COMPILER_ID}\n" 76 | " Compiler Version: ${COMPILER_VERSION}\n" 77 | " Build Type: ${BUILD_TYPE}\n" 78 | " Git Info: ${GIT_LATEST_PROJECT_VERSION}/${GIT_LATEST_PROJECT_VERSION_DISTANCE}/${GIT_COMMIT_HASH}${dirty_msg}\n" 79 | " Git Branch: ${GIT_BRANCH}\n" 80 | " Git Origin URL: ${GIT_ORIGIN_URL}\n" 81 | " Timestamp: ${TIMESTAMP}" 82 | ) 83 | 84 | configure_file(${CMAKE_CURRENT_LIST_DIR}/buildinfo.c.in ${OUTPUT_DIR}/buildinfo.c) 85 | configure_file(${CMAKE_CURRENT_LIST_DIR}/buildinfo.json.in ${OUTPUT_DIR}/buildinfo.json) 86 | configure_file(${CMAKE_CURRENT_LIST_DIR}/buildinfo.sh.in ${OUTPUT_DIR}/buildinfo.sh) 87 | configure_file(${CMAKE_CURRENT_LIST_DIR}/buildinfo.ps1.in ${OUTPUT_DIR}/buildinfo.ps1) 88 | 89 | configure_file(${CMAKE_CURRENT_LIST_DIR}/version.h.in ${OUTPUT_DIR}/version.h) 90 | -------------------------------------------------------------------------------- /buildinfo/buildinfo.h.in: -------------------------------------------------------------------------------- 1 | /* Cable: CMake Bootstrap Library. 2 | * Copyright 2018 Pawel Bylica. 3 | * Licensed under the Apache License, Version 2.0. See the LICENSE file. 4 | */ 5 | 6 | /* Generated by Cable Build Info on @TIMESTAMP@. Do not modify directly. */ 7 | 8 | #pragma once 9 | 10 | #ifdef __cplusplus 11 | extern "C" 12 | { 13 | #endif 14 | 15 | struct buildinfo 16 | { 17 | const char* project_name; 18 | const char* project_version; 19 | const char* project_name_with_version; 20 | const char* git_commit_hash; 21 | const char* git_branch; 22 | const char* system_name; 23 | const char* system_processor; 24 | const char* compiler_id; 25 | const char* compiler_version; 26 | const char* build_type; 27 | }; 28 | 29 | const struct buildinfo* @FUNCTION_NAME@(); 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | -------------------------------------------------------------------------------- /buildinfo/buildinfo.json.in: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@PROJECT_NAME@", 3 | "version": "@PROJECT_VERSION@", 4 | "is_prerelease": @PROJECT_VERSION_IS_PRERELEASE@, 5 | "commit": "@GIT_COMMIT_HASH@", 6 | "branch": "@GIT_BRANCH@", 7 | "repo": "@GIT_ORIGIN_URL@", 8 | "system_name": "@SYSTEM_NAME@", 9 | "system_processor": "@SYSTEM_PROCESSOR@" 10 | } 11 | -------------------------------------------------------------------------------- /buildinfo/buildinfo.ps1.in: -------------------------------------------------------------------------------- 1 | $env:project_name="@PROJECT_NAME@" 2 | $env:project_version="@PROJECT_VERSION@" 3 | $env:project_version_is_prerelease="@PROJECT_VERSION_IS_PRERELEASE@" 4 | $env:system_name='@SYSTEM_NAME@' 5 | $env:system_processor='@SYSTEM_PROCESSOR@' 6 | -------------------------------------------------------------------------------- /buildinfo/buildinfo.sh.in: -------------------------------------------------------------------------------- 1 | PROJECT_NAME='@PROJECT_NAME@' 2 | PROJECT_VERSION='@PROJECT_VERSION@' 3 | PROJECT_VERSION_IS_PRERELEASE='@PROJECT_VERSION_IS_PRERELEASE@' 4 | SYSTEM_NAME='@SYSTEM_NAME@' 5 | SYSTEM_PROCESSOR='@SYSTEM_PROCESSOR@' 6 | -------------------------------------------------------------------------------- /buildinfo/gitinfo.cmake: -------------------------------------------------------------------------------- 1 | # Cable: CMake Bootstrap Library. 2 | # Copyright 2018 Pawel Bylica. 3 | # Licensed under the Apache License, Version 2.0. See the LICENSE file. 4 | 5 | # Execute git only if the tool is available. 6 | if(GIT) 7 | execute_process( 8 | COMMAND ${GIT} describe --always --long --tags --first-parent --match=v* --abbrev=40 --dirty 9 | WORKING_DIRECTORY ${SOURCE_DIR} 10 | OUTPUT_VARIABLE gitinfo 11 | OUTPUT_STRIP_TRAILING_WHITESPACE 12 | ERROR_VARIABLE error 13 | ERROR_STRIP_TRAILING_WHITESPACE 14 | ) 15 | if(error) 16 | message(WARNING "Git ${error}") 17 | endif() 18 | 19 | execute_process( 20 | COMMAND ${GIT} rev-parse --abbrev-ref HEAD 21 | WORKING_DIRECTORY ${SOURCE_DIR} 22 | OUTPUT_VARIABLE gitbranch 23 | OUTPUT_STRIP_TRAILING_WHITESPACE 24 | ERROR_VARIABLE error 25 | ERROR_STRIP_TRAILING_WHITESPACE 26 | ) 27 | if(error) 28 | message(WARNING "Git ${error}") 29 | else() 30 | set(gitinfo "${gitinfo}\n${gitbranch}") 31 | endif() 32 | 33 | execute_process( 34 | COMMAND ${GIT} config --get remote.origin.url 35 | WORKING_DIRECTORY ${SOURCE_DIR} 36 | OUTPUT_VARIABLE gitorigin 37 | OUTPUT_STRIP_TRAILING_WHITESPACE 38 | ERROR_VARIABLE error 39 | ERROR_STRIP_TRAILING_WHITESPACE 40 | ) 41 | if(error) 42 | message(WARNING "Git ${error}") 43 | else() 44 | set(gitinfo "${gitinfo}\n${gitorigin}\n") 45 | endif() 46 | endif() 47 | 48 | set(gitinfo_file ${OUTPUT_DIR}/gitinfo.txt) 49 | 50 | if(EXISTS ${gitinfo_file}) 51 | file(READ ${gitinfo_file} prev_gitinfo) 52 | else() 53 | # Create empty file, because other targets expect it to exist. 54 | file(WRITE ${gitinfo_file} "") 55 | endif() 56 | 57 | if(NOT "${gitinfo}" STREQUAL "${prev_gitinfo}") 58 | file(WRITE ${gitinfo_file} ${gitinfo}) 59 | endif() 60 | -------------------------------------------------------------------------------- /buildinfo/version.h.in: -------------------------------------------------------------------------------- 1 | /* Cable: CMake Bootstrap Library. 2 | * Copyright 2019 Pawel Bylica. 3 | * Licensed under the Apache License, Version 2.0. 4 | */ 5 | 6 | /* Generated by Cable Build Info on @TIMESTAMP@. Do not modify directly. */ 7 | 8 | #pragma once 9 | 10 | #define @PROJECT_NAME_UPPERCASE@_VERSION "@PROJECT_VERSION@" 11 | 12 | #ifdef __cplusplus 13 | constexpr auto @PROJECT_NAME@_version = "@PROJECT_VERSION@"; 14 | #endif 15 | -------------------------------------------------------------------------------- /cable.cmake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env -S cmake -P 2 | 3 | # Cable: CMake Bootstrap Library 4 | # Copyright 2019-2020 Pawel Bylica. 5 | # Licensed under the Apache License, Version 2.0. 6 | 7 | # The cable command-line tool, version 1.0.0 8 | # 9 | # This CMake script allows installing or updating Cable modules. 10 | # Commands: 11 | # - list 12 | # - install 13 | # - update 14 | # 15 | # You can also include it from CMakeLists.txt to add Cable modules to 16 | # CMAKE_MODULE_PATH. 17 | 18 | if(NOT CMAKE_SCRIPT_MODE_FILE) 19 | # Setup Cable modules when included as include(cable.cmake). 20 | list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}) 21 | return() 22 | endif() 23 | 24 | set(repo_url https://github.com/ethereum/cable) 25 | set(download_url ${repo_url}/raw/master) 26 | set(cable_dir ${CMAKE_CURRENT_LIST_DIR}) 27 | 28 | function(get_modules_list OUTPUT_LIST) 29 | file(GLOB modules_files RELATIVE ${cable_dir} "${cable_dir}/Cable*.cmake") 30 | string(REPLACE ".cmake" "" modules "${modules_files}") 31 | set(${OUTPUT_LIST} "${modules}" PARENT_SCOPE) 32 | endfunction() 33 | 34 | function(download MODULE_NAME) 35 | set(module_file ${MODULE_NAME}.cmake) 36 | set(src "${download_url}/${module_file}") 37 | set(dst "${cable_dir}/${module_file}") 38 | file(DOWNLOAD "${src}" "${dst}" STATUS status) 39 | list(GET status 0 status_code) 40 | list(GET status 1 error_msg) 41 | if(status EQUAL 0) 42 | set(msg DONE) 43 | else() 44 | file(REMOVE "${dst}") 45 | set(msg "${status_code} ${error_msg}\n ${src}") 46 | endif() 47 | message("Downloading ${MODULE_NAME}: ${msg}") 48 | endfunction() 49 | 50 | set(cmd ${CMAKE_ARGV3}) # cmake -P cable.cmake ARGV3 ARGV4 ... 51 | if(NOT cmd) 52 | set(cmd list) 53 | endif() 54 | 55 | if(cmd STREQUAL list) 56 | get_modules_list(modules) 57 | string(REPLACE ";" "\n " modules "${modules}") 58 | message("Installed modules:\n ${modules}") 59 | elseif(cmd STREQUAL update) 60 | get_modules_list(modules) 61 | foreach(module ${modules}) 62 | download(${module}) 63 | endforeach() 64 | elseif(cmd STREQUAL install) 65 | download(${CMAKE_ARGV4}) 66 | else() 67 | message(FATAL_ERROR "Unknown command '${cmd}'") 68 | endif() 69 | -------------------------------------------------------------------------------- /defaults/HunterCacheServers-passwords.cmake: -------------------------------------------------------------------------------- 1 | # Cable: CMake Bootstrap Library. 2 | # Copyright 2018 Pawel Bylica. 3 | # Licensed under the Apache License, Version 2.0. See the LICENSE file. 4 | 5 | # Hunter passwords file used by HunterCacheServers.cmake. 6 | # Do not include directly. 7 | 8 | hunter_upload_password( 9 | # REPO_OWNER + REPO = https://github.com/ethereum/hunter-cache 10 | REPO_OWNER ethereum 11 | REPO hunter-cache 12 | 13 | # USERNAME = https://github.com/hunter-cache-bot 14 | USERNAME hunter-cache-bot 15 | 16 | # PASSWORD = GitHub token saved as a secure environment variable 17 | PASSWORD "$ENV{HUNTER_CACHE_TOKEN}" 18 | ) 19 | -------------------------------------------------------------------------------- /defaults/HunterCacheServers.cmake: -------------------------------------------------------------------------------- 1 | # Cable: CMake Bootstrap Library. 2 | # Copyright 2018 Pawel Bylica. 3 | # Licensed under the Apache License, Version 2.0. See the LICENSE file. 4 | 5 | # This module, when included, sets default values for params related to 6 | # Hunter cache servers, including upload options. 7 | 8 | # Default Hunter cache servers. 9 | set(HUNTER_CACHE_SERVERS 10 | "https://github.com/ethereum/hunter-cache;https://github.com/ingenue/hunter-cache" 11 | CACHE STRING "Hunter cache servers") 12 | 13 | # Default path to Hunter passwords file containing information how to access 14 | # Ethereum's cache server. 15 | set(HUNTER_PASSWORDS_PATH 16 | ${CMAKE_CURRENT_LIST_DIR}/HunterCacheServers-passwords.cmake 17 | CACHE STRING "Hunter passwords file") 18 | 19 | # In CI builds upload the binaries if the HUNTER_CACHE_TOKEN was decrypted 20 | # (only for branches and internal PRs). 21 | if("$ENV{CI}" AND NOT "$ENV{HUNTER_CACHE_TOKEN}" STREQUAL "") 22 | set(run_upload YES) 23 | else() 24 | set(run_upload NO) 25 | endif() 26 | option(HUNTER_RUN_UPLOAD "Upload binaries to the Hunter cache server" ${run_upload}) 27 | unset(run_upload) 28 | -------------------------------------------------------------------------------- /toolchains/cxx11-32bit.cmake: -------------------------------------------------------------------------------- 1 | # Cable: CMake Bootstrap Library. 2 | # Copyright 2018-2019 Pawel Bylica. 3 | # Licensed under the Apache License, Version 2.0. 4 | 5 | set(CMAKE_CXX_STANDARD 11) 6 | set(CMAKE_CXX_STANDARD_REQUIRED TRUE) 7 | set(CMAKE_CXX_EXTENSIONS OFF) 8 | 9 | set(CMAKE_C_FLAGS_INIT -m32) 10 | set(CMAKE_CXX_FLAGS_INIT -m32) 11 | -------------------------------------------------------------------------------- /toolchains/cxx11-c99.cmake: -------------------------------------------------------------------------------- 1 | # Cable: CMake Bootstrap Library. 2 | # Copyright 2018 Pawel Bylica. 3 | # Licensed under the Apache License, Version 2.0. See the LICENSE file. 4 | 5 | set(CMAKE_CXX_STANDARD 11) 6 | set(CMAKE_CXX_STANDARD_REQUIRED TRUE) 7 | set(CMAKE_CXX_EXTENSIONS OFF) 8 | 9 | set(CMAKE_C_STANDARD 99) 10 | set(CMAKE_C_EXTENSIONS OFF) 11 | -------------------------------------------------------------------------------- /toolchains/cxx11-fpic.cmake: -------------------------------------------------------------------------------- 1 | # Cable: CMake Bootstrap Library. 2 | # Copyright 2018 Pawel Bylica. 3 | # Licensed under the Apache License, Version 2.0. See the LICENSE file. 4 | 5 | set(CMAKE_CXX_STANDARD 11) 6 | set(CMAKE_CXX_STANDARD_REQUIRED TRUE) 7 | set(CMAKE_CXX_EXTENSIONS OFF) 8 | 9 | set(CMAKE_POSITION_INDEPENDENT_CODE ON) 10 | 11 | set(CMAKE_CXX_FLAGS_INIT "-fPIC" CACHE STRING "" FORCE) 12 | set(CMAKE_C_FLAGS_INIT "-fPIC" CACHE STRING "" FORCE) 13 | -------------------------------------------------------------------------------- /toolchains/cxx11-pic.cmake: -------------------------------------------------------------------------------- 1 | # Cable: CMake Bootstrap Library. 2 | # Copyright 2018 Pawel Bylica. 3 | # Licensed under the Apache License, Version 2.0. See the LICENSE file. 4 | 5 | set(CMAKE_CXX_STANDARD 11) 6 | set(CMAKE_CXX_STANDARD_REQUIRED TRUE) 7 | set(CMAKE_CXX_EXTENSIONS OFF) 8 | 9 | set(CMAKE_POSITION_INDEPENDENT_CODE ON) 10 | -------------------------------------------------------------------------------- /toolchains/cxx11.cmake: -------------------------------------------------------------------------------- 1 | # Cable: CMake Bootstrap Library. 2 | # Copyright 2018 Pawel Bylica. 3 | # Licensed under the Apache License, Version 2.0. See the LICENSE file. 4 | 5 | set(CMAKE_CXX_STANDARD 11) 6 | set(CMAKE_CXX_STANDARD_REQUIRED TRUE) 7 | set(CMAKE_CXX_EXTENSIONS OFF) 8 | -------------------------------------------------------------------------------- /toolchains/cxx14-32bit.cmake: -------------------------------------------------------------------------------- 1 | # Cable: CMake Bootstrap Library. 2 | # Copyright 2019 Pawel Bylica. 3 | # Licensed under the Apache License, Version 2.0. 4 | 5 | set(CMAKE_CXX_STANDARD 14) 6 | set(CMAKE_CXX_STANDARD_REQUIRED TRUE) 7 | set(CMAKE_CXX_EXTENSIONS OFF) 8 | 9 | set(CMAKE_C_FLAGS_INIT -m32) 10 | set(CMAKE_CXX_FLAGS_INIT -m32) 11 | -------------------------------------------------------------------------------- /toolchains/cxx14-pic.cmake: -------------------------------------------------------------------------------- 1 | # Cable: CMake Bootstrap Library. 2 | # Copyright 2019 Pawel Bylica. 3 | # Licensed under the Apache License, Version 2.0. 4 | 5 | set(CMAKE_CXX_STANDARD 14) 6 | set(CMAKE_CXX_STANDARD_REQUIRED TRUE) 7 | set(CMAKE_CXX_EXTENSIONS OFF) 8 | 9 | set(CMAKE_POSITION_INDEPENDENT_CODE ON) 10 | -------------------------------------------------------------------------------- /toolchains/cxx14.cmake: -------------------------------------------------------------------------------- 1 | # Cable: CMake Bootstrap Library. 2 | # Copyright 2019 Pawel Bylica. 3 | # Licensed under the Apache License, Version 2.0. 4 | 5 | set(CMAKE_CXX_STANDARD 14) 6 | set(CMAKE_CXX_STANDARD_REQUIRED TRUE) 7 | set(CMAKE_CXX_EXTENSIONS OFF) 8 | -------------------------------------------------------------------------------- /toolchains/cxx17-32bit.cmake: -------------------------------------------------------------------------------- 1 | # Cable: CMake Bootstrap Library. 2 | # Copyright 2019 Pawel Bylica. 3 | # Licensed under the Apache License, Version 2.0. 4 | 5 | set(CMAKE_CXX_STANDARD 17) 6 | set(CMAKE_CXX_STANDARD_REQUIRED TRUE) 7 | set(CMAKE_CXX_EXTENSIONS OFF) 8 | 9 | set(CMAKE_C_FLAGS_INIT -m32) 10 | set(CMAKE_CXX_FLAGS_INIT -m32) 11 | -------------------------------------------------------------------------------- /toolchains/cxx17-pic.cmake: -------------------------------------------------------------------------------- 1 | # Cable: CMake Bootstrap Library. 2 | # Copyright 2019 Pawel Bylica. 3 | # Licensed under the Apache License, Version 2.0. 4 | 5 | set(CMAKE_CXX_STANDARD 17) 6 | set(CMAKE_CXX_STANDARD_REQUIRED TRUE) 7 | set(CMAKE_CXX_EXTENSIONS OFF) 8 | 9 | set(CMAKE_POSITION_INDEPENDENT_CODE ON) 10 | -------------------------------------------------------------------------------- /toolchains/cxx17.cmake: -------------------------------------------------------------------------------- 1 | # Cable: CMake Bootstrap Library. 2 | # Copyright 2019 Pawel Bylica. 3 | # Licensed under the Apache License, Version 2.0. 4 | 5 | set(CMAKE_CXX_STANDARD 17) 6 | set(CMAKE_CXX_STANDARD_REQUIRED TRUE) 7 | set(CMAKE_CXX_EXTENSIONS OFF) 8 | -------------------------------------------------------------------------------- /toolchains/default.cmake: -------------------------------------------------------------------------------- 1 | # Cable: CMake Bootstrap Library. 2 | # Copyright 2018 Pawel Bylica. 3 | # Licensed under the Apache License, Version 2.0. See the LICENSE file. 4 | -------------------------------------------------------------------------------- /toolchains/mips64.cmake: -------------------------------------------------------------------------------- 1 | # Cable: CMake Bootstrap Library. 2 | # Copyright 2018 Pawel Bylica. 3 | # Licensed under the Apache License, Version 2.0. See the LICENSE file. 4 | 5 | set(CMAKE_SYSTEM_PROCESSOR mips64) 6 | set(CMAKE_SYSTEM_NAME Linux) 7 | set(CMAKE_C_COMPILER mips64-linux-gnuabi64-gcc) 8 | set(CMAKE_CXX_COMPILER mips64-linux-gnuabi64-g++) 9 | 10 | set(CMAKE_FIND_ROOT_PATH /usr/mips64-linux-gnuabi64) 11 | SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 12 | SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 13 | SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 14 | 15 | set(CMAKE_CXX_STANDARD 11) 16 | set(CMAKE_CXX_STANDARD_REQUIRED TRUE) 17 | set(CMAKE_CXX_EXTENSIONS Off) 18 | 19 | if(${CMAKE_VERSION} VERSION_LESS 3.10.0) 20 | # Until CMake 3.10 the FindThreads uses try_run() check of -pthread flag, 21 | # what causes CMake error in crosscompiling mode. Avoid the try_run() check 22 | # by specifying the result up front. 23 | set(THREADS_PTHREAD_ARG TRUE) 24 | endif() 25 | -------------------------------------------------------------------------------- /toolchains/powerpc64.cmake: -------------------------------------------------------------------------------- 1 | # Cable: CMake Bootstrap Library. 2 | # Copyright 2018 Pawel Bylica. 3 | # Licensed under the Apache License, Version 2.0. See the LICENSE file. 4 | 5 | set(CMAKE_SYSTEM_PROCESSOR powerpc64) 6 | set(CMAKE_SYSTEM_NAME Linux) 7 | set(CMAKE_C_COMPILER powerpc64-linux-gnu-gcc) 8 | set(CMAKE_CXX_COMPILER powerpc64-linux-gnu-g++) 9 | 10 | set(CMAKE_FIND_ROOT_PATH /usr/powerpc64-linux-gnu) 11 | SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 12 | SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 13 | SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 14 | 15 | set(CMAKE_CXX_STANDARD 11) 16 | set(CMAKE_CXX_STANDARD_REQUIRED TRUE) 17 | set(CMAKE_CXX_EXTENSIONS OFF) 18 | 19 | if(${CMAKE_VERSION} VERSION_LESS 3.10.0) 20 | # Until CMake 3.10 the FindThreads uses try_run() check of -pthread flag, 21 | # what causes CMake error in crosscompiling mode. Avoid the try_run() check 22 | # by specifying the result up front. 23 | set(THREADS_PTHREAD_ARG TRUE) 24 | endif() 25 | --------------------------------------------------------------------------------